magnet-uri
Advanced tools
Comparing version 3.0.0 to 3.1.0
35
index.js
@@ -13,4 +13,3 @@ var base32 = require('thirty-two') | ||
if (!data || data.length === 0) | ||
return result | ||
if (!data || data.length === 0) return result | ||
@@ -23,4 +22,3 @@ var params = data.split('&') | ||
// This keyval is invalid, skip it | ||
if (keyval.length !== 2) | ||
return | ||
if (keyval.length !== 2) return | ||
@@ -31,12 +29,9 @@ var key = keyval[0] | ||
// Clean up torrent name | ||
if (key === 'dn') | ||
val = decodeURIComponent(val).replace(/\+/g, ' ') | ||
if (key === 'dn') val = decodeURIComponent(val).replace(/\+/g, ' ') | ||
// Address tracker (tr) is an encoded URI, so decode it | ||
if (key === 'tr') | ||
val = decodeURIComponent(val) | ||
if (key === 'tr') val = decodeURIComponent(val) | ||
// Return keywords as an array | ||
if (key === 'kt') | ||
val = decodeURIComponent(val).split('+') | ||
if (key === 'kt') val = decodeURIComponent(val).split('+') | ||
@@ -56,3 +51,3 @@ // If there are repeated parameters, return an array of values | ||
// Convenience properties for parity with `parse-torrent-file` | ||
// Convenience properties for parity with `parse-torrent-file` module | ||
var m | ||
@@ -65,13 +60,13 @@ if (result.xt && (m = result.xt.match(/^urn:btih:(.{40})/))) { | ||
} | ||
if (result.dn) | ||
result.name = result.dn | ||
if (result.kt) | ||
result.keywords = result.kt | ||
// always make `announce` property an array, for parity with `parse-torrent-file` | ||
if (typeof result.tr === 'string') | ||
result.announce = [ result.tr ] | ||
else if (Array.isArray(result.tr)) | ||
result.announce = result.tr | ||
if (result.dn) result.name = result.dn | ||
if (result.kt) result.keywords = result.kt | ||
if (typeof result.tr === 'string') result.announce = [ result.tr ] | ||
else if (Array.isArray(result.tr)) result.announce = result.tr | ||
if (result.announce) result.announceList = result.announce.map(function (url) { | ||
return [ url ] | ||
}) | ||
return result | ||
} |
{ | ||
"name": "magnet-uri", | ||
"description": "Parse a magnet URI and return an object of keys/values", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"author": "Feross Aboukhadijeh <feross@feross.org> (http://feross.org/)", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -10,13 +10,24 @@ var magnet = require('../') | ||
}) | ||
result = magnet(leavesOfGrass) | ||
t.equal(result.xt, "urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36") | ||
t.equal(result.dn, "Leaves of Grass by Walt Whitman.epub") | ||
t.equal(result.infoHash, "d2474e86c95b19b8bcfdb92bc12c9d44667cfa36") | ||
t.deepEquals(result.tr, [ | ||
"udp://tracker.openbittorrent.com:80", | ||
"udp://tracker.publicbt.com:80", | ||
"udp://tracker.istole.it:6969", | ||
"udp://tracker.ccc.de:80", | ||
"udp://open.demonii.com:1337" | ||
]) | ||
var result = magnet(leavesOfGrass) | ||
t.equal(result.xt, 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36') | ||
t.equal(result.dn, 'Leaves of Grass by Walt Whitman.epub') | ||
t.equal(result.infoHash, 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36') | ||
var announce = [ | ||
'udp://tracker.openbittorrent.com:80', | ||
'udp://tracker.publicbt.com:80', | ||
'udp://tracker.istole.it:6969', | ||
'udp://tracker.ccc.de:80', | ||
'udp://open.demonii.com:1337' | ||
] | ||
var announceList = [ | ||
[ 'udp://tracker.openbittorrent.com:80' ], | ||
[ 'udp://tracker.publicbt.com:80' ], | ||
[ 'udp://tracker.istole.it:6969' ], | ||
[ 'udp://tracker.ccc.de:80' ], | ||
[ 'udp://open.demonii.com:1337' ] | ||
] | ||
t.deepEquals(result.tr, announce) | ||
t.deepEquals(result.announce, announce) | ||
t.deepEquals(result.announceList, announceList) | ||
t.end() | ||
@@ -76,3 +87,3 @@ }) | ||
test('extracts 40-char hex BitTorrent info_hash', function (t) { | ||
result = magnet('magnet:?xt=urn:btih:aad050ee1bb22e196939547b134535824dabf0ce') | ||
var result = magnet('magnet:?xt=urn:btih:aad050ee1bb22e196939547b134535824dabf0ce') | ||
t.equal(result.infoHash, 'aad050ee1bb22e196939547b134535824dabf0ce') | ||
@@ -83,3 +94,3 @@ t.end() | ||
test('extracts 32-char base32 BitTorrent info_hash', function (t) { | ||
result = magnet('magnet:?xt=urn:btih:64DZYZWMUAVLIWJUXGDIK4QGAAIN7SL6') | ||
var result = magnet('magnet:?xt=urn:btih:64DZYZWMUAVLIWJUXGDIK4QGAAIN7SL6') | ||
t.equal(result.infoHash, 'f7079c66cca02ab45934b9868572060010dfc97e') | ||
@@ -90,5 +101,5 @@ t.end() | ||
test('extracts keywords', function (t) { | ||
result = magnet('magnet:?xt=urn:btih:64DZYZWMUAVLIWJUXGDIK4QGAAIN7SL6&kt=joe+blow+mp3') | ||
var result = magnet('magnet:?xt=urn:btih:64DZYZWMUAVLIWJUXGDIK4QGAAIN7SL6&kt=joe+blow+mp3') | ||
t.deepEqual(result.keywords, ['joe','blow','mp3']) | ||
t.end() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9643
141