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

How to download only one of the torrents? #801

Closed
amilajack opened this issue May 14, 2016 · 9 comments
Closed

How to download only one of the torrents? #801

amilajack opened this issue May 14, 2016 · 9 comments

Comments

@amilajack
Copy link
Contributor

@amilajack amilajack commented May 14, 2016

I'm having trouble understanding the documentation. How can I download only one of the torrents?

This is what I have so far:

// ....
client.add(magnetURI, function(torrent) {
     for (const file of torrent.files) {
       if (file.path.includes('mp4', 'srt')) {
         // How can I select only one of these?
         file.appendTo('body');
         break;
      }
    }
});
  • WebTorrent version:
  • Node.js version: 5.11.1
  • Browser name/version (if using WebTorrent in the browser): Electron
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 14, 2016

I assume you're asking about how to download one of the files in a torrent.

client.add(magnetURI, function(torrent) {
  for (const file of torrent.files) {
    if (file.path === some_condition) {
      file.appendTo('body')

      // or...

      file.getBuffer(function (buf) {
        console.log(buf.toString('hex')) // got raw data
      })
    }
  }
})
@feross feross closed this May 14, 2016
@amilajack

This comment has been minimized.

Copy link
Contributor Author

@amilajack amilajack commented May 14, 2016

Oh I see. So if I want to download only certain files, I have to call appendTo on them?

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented May 14, 2016

You should deselect the rest of files.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 14, 2016

Right. What @DiegoRBaquero said:

file.deselect()
@amilajack

This comment has been minimized.

Copy link
Contributor Author

@amilajack amilajack commented May 14, 2016

@feross @DiegoRBaquero Thanks a ton! Is there a way to list all the selected files (for debugging purposes)?

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented May 14, 2016

@amilajack You mean files? You could just create an attribute for the file.

@amilajack

This comment has been minimized.

Copy link
Contributor Author

@amilajack amilajack commented May 15, 2016

Yea sorry for the confusion. I edited my comment. I mean to ask how I could list all the files that are being downloaded from a given torrent? Ideally, I'd like to start a torrent, deselect certain files, and then list all the ones that are still selected.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 17, 2016

The way that selected files are tracked internally (based on byte ranges) would make this information kind of hard to expose, at the moment. I recommend tracking this information manually in your application.

@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
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
3 participants
You can’t perform that action at this time.