Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files are always null #569

Closed
KeizerDev opened this issue Jan 11, 2016 · 10 comments
Closed

Files are always null #569

KeizerDev opened this issue Jan 11, 2016 · 10 comments

Comments

@KeizerDev
Copy link

@KeizerDev KeizerDev commented Jan 11, 2016

Understanding example gives files: null, how can I fix that?

var client = new WebTorrent()

var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d'

client.add(torrentId, function (torrent) {
  var file = torrent.files[0]
  file.appendTo('body') // append the file to the DOM
})
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 12, 2016

Please provide more details. Are you running this in node.js or the browser? Which version of node or browser are you using?

What do you mean it "gives files: null"?

@KeizerDev

This comment has been minimized.

Copy link
Author

@KeizerDev KeizerDev commented Jan 12, 2016

I'm using Google Chrome 46.0.2490.80.
When I just grabbing a random magnet link with a mp4 video, client.torrents[0]['files'], returns null

@andreapaiola

This comment has been minimized.

Copy link
Contributor

@andreapaiola andreapaiola commented Jan 12, 2016

WebTorrent or BitTorrent?

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Jan 12, 2016

The code you first posted doesn't have client.torrents[0]['files'] ...

It seems you are trying to access the files property before it has even downloaded the metadata.

Can you post the full code please?

@KeizerDev

This comment has been minimized.

Copy link
Author

@KeizerDev KeizerDev commented Jan 12, 2016

@DiegoRBaquero No, just run it in your console

@KeizerDev

This comment has been minimized.

Copy link
Author

@KeizerDev KeizerDev commented Jan 12, 2016

Yeah that's my point, the metadata never gets downloaded.. 👎

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Jan 12, 2016

I just tested in BTorrent with the magnet of the example, it works. Do you have your code hosted somewhere? Maybe jsfiddle or plunker?

https://www.dropbox.com/s/7iw6ec2fk2otw0x/Screenshot%202016-01-12%2014.20.13.png?dl=0

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 12, 2016

@KeizerDev If you won't post your full code then we can't help you beyond what we've already tried.

@DiegoRBaquero is right. It sounds like you're trying to use the torrent object before the callback has fired. The sample code you provided works fine for me.

You shouldn't do client.torrents[0]['files']. You should wait for the callback to fire.

@feross feross closed this Jan 12, 2016
@KeizerDev

This comment has been minimized.

Copy link
Author

@KeizerDev KeizerDev commented Jan 12, 2016

@DiegoRBaquero and @feross my full code is actually:

var client = new WebTorrent()

var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d'

client.add(torrentId, function (torrent) {
  var file = torrent.files[0]
  file.appendTo('body') // append the file to the DOM
})

This will work as you guys said, I just had to wait, BUT when I change the magnet link to something like magnet:?xt=urn:btih:21AC20E0976C373B8372D1637F075AD0BEEFCAD6&dn=the+last+witch+hunter+2015+720p+webrip+x264+aac+etrg&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80%2Fannounce&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce and refire the script after a page reload, the callback will never been fired, or it just takes way to long but I didn't had time to wait that long (Fyi, this is a mp4 movie, found just some where on the internet 😃). How can I fix this, what can cause this?

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Jan 12, 2016

Because, for the 1000th time, that torrent is not in the webrtc network. Also, please do NOT use WebTorrent for copyright infringement.

Please read this part of the FAQ:

Why does browser downloading not work? I see no peers!

It does work! But you can't just use any random magnet uri or .torrent file. The torrent must be seeded by a WebRTC-capable client, i.e. webtorrent-hybrid, instant.io, or Playback.

In the browser, WebTorrent can only download torrents that are explicitly seeded to web peers via a WebRTC-capable client. Desktop torrent clients need to support WebRTC to connect to web browsers.

@webtorrent webtorrent locked and limited conversation to collaborators Jan 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.