An event-based magnet-link parser for node
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
index.js
package.json

README.md

node-miracles

Miracles is an event-based magnet link parser for node

license: MIT

Installation

npm install miracles

Usage

var miracles = require('miracles');

var tpbDocumentary = miracles('magnet:?xt=urn:btih:79816060ea56d56f2a2148cd45705511079f9bca&dn=TPB.AFK.2013.720p.h264-SimonKlose&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80');

tpbDocumentary.on('root', function(){
    console.log('begining parsing...');
});

tpbDocumentary.on('completed', function(parsed){
    console.log(parsed);
});

// address /tr/acker paremeter
tpbDocumentary.on('tr', function(address){
    console.log('encountered tracker:', address);
});

Docs

Magnet(url)

returns a newly instantiated object of type [object Magnet]

magnet#on(tag, callback)

callback(tagData)
attaches the callback to the tag, calling it when the tag is encountered

magnet#on('root', callback)

callback()
calls the attached callback when begining to parse the URI

magnet#on('completed', callback)

callback(data)
calls the attached callback with the fully parsed structure of the magnet URI, also signifies that the link is finished being parsed

magnet#get(tag, opts)

returns the data associated with the tag

opts
opts.buffer = true // if asking for the 'xt' tag, will convert the hexidecimal string to it's corresponding 20 byte representation for announce requests

magnet#find(/regex/)

returns an array of the fully matched values, tags included

var link = Magnet('magnet:?xt=urn:btih:79816060ea56d56f2a2148cd45705511079f9bca&dn=TPB.AFK.2013.720p.h264-SimonKlose&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80');

link.on('completed', function(data){
    console.log(link.find(/o/gi));
    /* results will look like –
    [ 'TPB.AFK.2013.720p.h264-SimonKlose', 'udp://tracker.openbittorrent.com:80', 'udp://tracker.publicbt.com:80' ]
    */
});

Notes

Refer to the official website for the magnet-uri project, the Wikipedia article, and more directly, the specification for more information on parameters and whatnot.