support magnet uris in add command/dialog
This commit is contained in:
parent
db46a97263
commit
87473f2cde
|
@ -56,7 +56,8 @@ class Command(BaseCommand):
|
||||||
help='Interpret all given torrent-file arguments as files'),
|
help='Interpret all given torrent-file arguments as files'),
|
||||||
)
|
)
|
||||||
|
|
||||||
usage = "Usage: add [-p <save-location>] [-u | --urls] [-f | --files] <torrent-file> [<torrent-file> ...]"
|
usage = "Usage: add [-p <save-location>] [-u | --urls] [-f | --files] <torrent-file> [<torrent-file> ...]\n"\
|
||||||
|
" <torrent-file> arguments can be file paths, URLs or magnet uris"
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
self.console = component.get("ConsoleUI")
|
self.console = component.get("ConsoleUI")
|
||||||
|
@ -80,6 +81,9 @@ class Command(BaseCommand):
|
||||||
if not options["force_file"] and (deluge.common.is_url(arg) or options["force_url"]):
|
if not options["force_file"] and (deluge.common.is_url(arg) or options["force_url"]):
|
||||||
self.console.write("{!info!}Attempting to add torrent from url: %s" % arg)
|
self.console.write("{!info!}Attempting to add torrent from url: %s" % arg)
|
||||||
deferreds.append(client.core.add_torrent_url(arg, t_options).addCallback(on_success).addErrback(on_fail))
|
deferreds.append(client.core.add_torrent_url(arg, t_options).addCallback(on_success).addErrback(on_fail))
|
||||||
|
elif not options["force_file"] and (deluge.common.is_magnet(arg)):
|
||||||
|
self.console.write("{!info!}Attempting to add torrent from magnet uri: %s" % arg)
|
||||||
|
deferreds.append(client.core.add_torrent_magnet(arg, t_options).addCallback(on_success).addErrback(on_fail))
|
||||||
else:
|
else:
|
||||||
if not os.path.exists(arg):
|
if not os.path.exists(arg):
|
||||||
self.console.write("{!error!}%s doesn't exist!" % arg)
|
self.console.write("{!error!}%s doesn't exist!" % arg)
|
||||||
|
|
|
@ -52,8 +52,9 @@ def add_torrent(t_file, options, success_cb, fail_cb, ress):
|
||||||
t_options["add_paused"] = options["add_paused"]
|
t_options["add_paused"] = options["add_paused"]
|
||||||
|
|
||||||
is_url = (not (options["path_type"]==1)) and (deluge.common.is_url(t_file) or options["path_type"]==2)
|
is_url = (not (options["path_type"]==1)) and (deluge.common.is_url(t_file) or options["path_type"]==2)
|
||||||
|
is_mag = not(is_url) and (not (options["path_type"]==1)) and deluge.common.is_magnet(t_file)
|
||||||
|
|
||||||
if is_url:
|
if is_url or is_mag:
|
||||||
files = [t_file]
|
files = [t_file]
|
||||||
else:
|
else:
|
||||||
files = glob.glob(t_file)
|
files = glob.glob(t_file)
|
||||||
|
@ -66,6 +67,8 @@ def add_torrent(t_file, options, success_cb, fail_cb, ress):
|
||||||
for f in files:
|
for f in files:
|
||||||
if is_url:
|
if is_url:
|
||||||
client.core.add_torrent_url(f, t_options).addCallback(success_cb,f,ress).addErrback(fail_cb,f,ress)
|
client.core.add_torrent_url(f, t_options).addCallback(success_cb,f,ress).addErrback(fail_cb,f,ress)
|
||||||
|
elif is_mag:
|
||||||
|
client.core.add_torrent_magnet(f, t_options).addCallback(success_cb,f,ress).addErrback(fail_cb,f,ress)
|
||||||
else:
|
else:
|
||||||
if not os.path.exists(f):
|
if not os.path.exists(f):
|
||||||
fail_cb("Doesn't exist",f,ress)
|
fail_cb("Doesn't exist",f,ress)
|
||||||
|
|
Loading…
Reference in New Issue