Skip to content

Instantly share code, notes, and snippets.

@totu
Created March 20, 2017 19:47
Show Gist options
  • Save totu/2679c6b7bb5a6bcc94b9747a2f5e5bb5 to your computer and use it in GitHub Desktop.
Save totu/2679c6b7bb5a6bcc94b9747a2f5e5bb5 to your computer and use it in GitHub Desktop.
JavaScript torrent loader a.k.a. "The Harvester"
#!/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