Module: deluge
Branch: master
Commit: 87473f2cde16db14023e1fbfa816702d7e5add12

Author: Nick Lanham <[email protected]>
Date:   Thu Feb 24 12:08:22 2011 +0100

support magnet uris in add command/dialog

---

 deluge/ui/console/commands/add.py   |    6 +++++-
 deluge/ui/console/modes/add_util.py |    5 ++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/deluge/ui/console/commands/add.py 
b/deluge/ui/console/commands/add.py
index 71ef1e7..37a3eb2 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 <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)
diff --git a/deluge/ui/console/modes/add_util.py 
b/deluge/ui/console/modes/add_util.py
index 168a6b1..bdd235e 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)

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to