Created
June 14, 2014 16:36
-
-
Save rhyzx/7a30f9963cccea962237 to your computer and use it in GitHub Desktop.
Magnet parsing API in node
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
// parse magnet | |
var magnetUri = require('magnet-uri') | |
var readTorrent = require('read-torrent') | |
var humanForamt = require('human-format') | |
app.get('/magnet', function (req, res) { | |
var uri = req.param('u') | |
var info = magnetUri(uri) | |
readTorrent('http://torrage.com/torrent/' + info.infoHash.toUpperCase() + '.torrent', function(err, torrent) { | |
if (err) return res.jsonp(500, { error: err }) | |
// clean info | |
res.jsonp({ | |
infoHash: torrent.infoHash, | |
name: torrent.name, | |
files: torrent.files.map(function (item, i) { | |
return { | |
index: i, | |
name: item.name, | |
length: item.length, | |
length_f: humanForamt(item.length) | |
} | |
}).filter(function (item, i) { | |
// remove padding file | |
// BUG? SPEC? | |
return !/^_____padding_file_/.test(item.name) | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment