Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save patrickdronk/916f5a67567dbc8d53cfdbf5cf95ff26 to your computer and use it in GitHub Desktop.
Save patrickdronk/916f5a67567dbc8d53cfdbf5cf95ff26 to your computer and use it in GitHub Desktop.
* startDownload(torrent, movie) {
var client = new WebTorrent();
var fileLocation = '';
client.add(torrent, {path: Helpers.publicPath() + '/movies'}, function (torrent) {
var folder = torrent.name;
var biggestSize = 0;
var location = '';
for (const key in torrent.files) {
if (biggestSize < torrent.files[key].length) {
biggestSize = torrent.files[key].length;
location = torrent.files[key].name;
}
}
// update the movie about the file :)
fileLocation = '/' + folder + '/' + location;
movie.download_location = fileLocation;
yield movie.save();
torrent.on('done', function () {
console.log('torrent download finished')
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment