Fix #2110 : Accept magnet uris with xt param anywhere within them

This commit is contained in:
Calum Lind 2012-11-27 17:42:18 +00:00
parent c426f998e2
commit 6fe350fa52
3 changed files with 26 additions and 19 deletions

View File

@ -448,7 +448,9 @@ def is_magnet(uri):
True True
""" """
if uri[:20] == "magnet:?xt=urn:btih:": magnet_scheme = 'magnet:?'
xt_param = 'xt=urn:btih:'
if uri.startswith(magnet_scheme) and xt_param in uri:
return True return True
return False return False

View File

@ -81,7 +81,7 @@ Deluge.add.UrlWindow = Ext.extend(Deluge.add.Window, {
var cookies = this.cookieField.getValue(); var cookies = this.cookieField.getValue();
var torrentId = this.createTorrentId(); var torrentId = this.createTorrentId();
if (url.substring(0,20) == 'magnet:?xt=urn:btih:') { if (url.indexOf('magnet:?') == 0 && url.indexOf('xt=urn:btih') > -1) {
deluge.client.web.get_magnet_info(url, { deluge.client.web.get_magnet_info(url, {
success: this.onGotInfo, success: this.onGotInfo,
scope: this, scope: this,

View File

@ -722,23 +722,28 @@ class WebApi(JSONComponent):
:rtype: dictionary :rtype: dictionary
""" """
try: magnet_scheme = 'magnet:?'
s = uri.split("&")[0][20:] xt_param = 'xt=urn:btih:'
if len(s) == 32: dn_param = 'dn='
info_hash = base64.b32decode(s).encode("hex") if uri.startswith(magnet_scheme):
elif len(s) == 40:
info_hash = s
else:
return False
name = None name = None
for i in uri.split("&")[1:]: info_hash = None
if i[:3] == "dn=": for param in uri[len(magnet_scheme):].split('&'):
name = unquote_plus(i.split("=")[1]) if param.startswith(xt_param):
xt_hash = param[len(xt_param):]
if len(xt_hash) == 32:
info_hash = base64.b32decode(xt_hash).encode("hex")
elif len(xt_hash) == 40:
info_hash = xt_hash
else:
break
elif param.startswith(dn_param):
name = unquote_plus(param[len(dn_param):])
if info_hash:
if not name: if not name:
name = info_hash name = info_hash
return {"name":name, "info_hash":info_hash, "files_tree":''} return {"name":name, "info_hash":info_hash, "files_tree":''}
except Exception, e:
log.exception(e)
return False return False
@export @export