Last active
January 6, 2016 18:07
-
-
Save rafapolo/a6aa52529f5dd0ef2ee2 to your computer and use it in GitHub Desktop.
Gera JSON com infos de Seeds e Leechs no tracker OpenBittorrent para todo .torrent em uma pasta
This file contains hidden or 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
#author: Rafael Polo | |
#language: CoffeeScript | |
#todo: | |
# remover repetidos | |
# considerar possíveis Peers vindos da DHT | distributed hash table | |
# parametrizar listar apenas com mais de 1 seed | |
# consultar outros Trackers usando API do torrentz.eu | |
Torrent = require('nt') | |
Tracker = require('node-tracker') | |
Promise = require('bluebird'); | |
FS = require('fs'); | |
# get openbittorrent Tracker response | |
scrapeOBT = (hash) -> | |
new Promise((resolve, reject) -> | |
response = {} | |
test = new Tracker("udp://tracker.openbittorrent.com:80/announce") | |
test.scrape [hash], (err, msg) -> | |
return 0 if err | |
response = {} | |
response["seeds"] = msg[hash]['seeders'] | |
response["leechs"] = msg[hash]['leechers'] | |
response["downloads"] = msg[hash]['completed'] | |
resolve response | |
) | |
# scrape all files from folder | |
folder = "./torrents" | |
files = FS.readdirSync(folder) | |
async = [] | |
for file in files | |
async.push new Promise((resolve, reject) -> | |
tr = Torrent.read "#{folder}/#{file}", (err, torrent) -> | |
return 0 if err | |
result = {} | |
hash = torrent.infoHash() | |
name = torrent.metadata['info']['name'] | |
scrapeOBT(hash).then( | |
(response) -> | |
result[name] = {} | |
result[name]["seeds"] = response["seeds"] | |
result[name]["leechs"] = response["leechs"] | |
result[name]["downloads"] = response["downloads"] | |
console.log result | |
resolve result | |
) | |
) | |
Promise.all(async).then( | |
(results) -> | |
FS.writeFile 'results.json', JSON.stringify(results), (err) -> | |
process.exit(0) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment