support magnet uris in add command/dialog

This commit is contained in:
Nick Lanham 2011-02-24 12:08:22 +01:00
parent db46a97263
commit 87473f2cde
2 changed files with 9 additions and 2 deletions

View File

@ -56,7 +56,8 @@ class Command(BaseCommand):
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):
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"]):
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))
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:
if not os.path.exists(arg):
self.console.write("{!error!}%s doesn't exist!" % arg)

View File

@ -52,8 +52,9 @@ def add_torrent(t_file, options, success_cb, fail_cb, ress):
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_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]
else:
files = glob.glob(t_file)
@ -66,6 +67,8 @@ def add_torrent(t_file, options, success_cb, fail_cb, ress):
for f in files:
if is_url:
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:
if not os.path.exists(f):
fail_cb("Doesn't exist",f,ress)