mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-28 02:50:30 +00:00
Fix #2110 : Accept magnet uris with xt param anywhere within them
This commit is contained in:
parent
c426f998e2
commit
6fe350fa52
@ -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
|
||||||
|
|
||||||
|
@ -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,
|
||||||
|
@ -722,24 +722,29 @@ 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):
|
||||||
if not name:
|
xt_hash = param[len(xt_param):]
|
||||||
name = info_hash
|
if len(xt_hash) == 32:
|
||||||
return {"name":name, "info_hash":info_hash, "files_tree":''}
|
info_hash = base64.b32decode(xt_hash).encode("hex")
|
||||||
except Exception, e:
|
elif len(xt_hash) == 40:
|
||||||
log.exception(e)
|
info_hash = xt_hash
|
||||||
return False
|
else:
|
||||||
|
break
|
||||||
|
elif param.startswith(dn_param):
|
||||||
|
name = unquote_plus(param[len(dn_param):])
|
||||||
|
|
||||||
|
if info_hash:
|
||||||
|
if not name:
|
||||||
|
name = info_hash
|
||||||
|
return {"name":name, "info_hash":info_hash, "files_tree":''}
|
||||||
|
return False
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def add_torrents(self, torrents):
|
def add_torrents(self, torrents):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user