diff --git a/deluge/ui/console/commands/add.py b/deluge/ui/console/commands/add.py index 71ef1e7d1..37a3eb2aa 100644 --- a/deluge/ui/console/commands/add.py +++ b/deluge/ui/console/commands/add.py @@ -56,7 +56,8 @@ class Command(BaseCommand): help='Interpret all given torrent-file arguments as files'), ) - usage = "Usage: add [-p ] [-u | --urls] [-f | --files] [ ...]" + usage = "Usage: add [-p ] [-u | --urls] [-f | --files] [ ...]\n"\ + " 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) diff --git a/deluge/ui/console/modes/add_util.py b/deluge/ui/console/modes/add_util.py index 168a6b1eb..bdd235e87 100644 --- a/deluge/ui/console/modes/add_util.py +++ b/deluge/ui/console/modes/add_util.py @@ -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)