Created
March 16, 2017 18:28
-
-
Save patrickdronk/916f5a67567dbc8d53cfdbf5cf95ff26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* 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