-
-
Save totu/2679c6b7bb5a6bcc94b9747a2f5e5bb5 to your computer and use it in GitHub Desktop.
JavaScript torrent loader a.k.a. "The Harvester"
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
#!/usr/local/bin/node | |
const torrent = require('torrent-stream') | |
const mag = process.argv.slice(2)[0]; | |
const download = function(input, id) { | |
const dl = torrent(input, {path: '/path/to/plex/folder'}) | |
dl.on('ready', function () { | |
dl.files.forEach(function (file) { | |
file.select(); | |
}); | |
var checkStatus = function () { | |
var downSpeed = dl.swarm.downloadSpeed(); | |
var percentage = ((dl.swarm.downloaded / dl.torrent.length) * 100).toPrecision(4); | |
console.log('speed: ' + downSpeed + ' percentage: ' + percentage) | |
if (downSpeed < 10000 && percentage >= 100) { | |
console.log("DONE!"); | |
dl.destroy(); | |
clearInterval(checker); | |
process.exit(0); | |
} | |
} | |
checker = setInterval(checkStatus, 500) | |
checkStatus(); | |
}); | |
} | |
if (mag != 'undefined') { | |
console.log(mag); | |
download(mag); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment