Module: deluge Branch: 1.3-stable Commit: fbc664fa144eb9e0efae1a0bd677fb1aa7d2af09
Author: Calum Lind <[email protected]> Date: Thu Jun 30 17:22:24 2011 +0100 Fix #1258: Add Magnet and Url support to add command in console --- ChangeLog | 3 ++ deluge/ui/console/commands/add.py | 41 ++++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3469fa6..bf73728 100644 --- a/ChangeLog +++ b/ChangeLog @@ -27,6 +27,9 @@ === Execute === * #1477: Fix ignore Added events from state file on startup +==== ConsoleUI ==== + * #1258: Add support for urls and magnet uris in add command + === Deluge 1.3.2 (24 May 2011) === ==== Core ==== * #1527: Fix Converting unicode to unicode error in move_storage diff --git a/deluge/ui/console/commands/add.py b/deluge/ui/console/commands/add.py index 7878438..ff4878b 100644 --- a/deluge/ui/console/commands/add.py +++ b/deluge/ui/console/commands/add.py @@ -39,6 +39,7 @@ from deluge.ui.console.main import BaseCommand import deluge.ui.console.colors as colors from deluge.ui.client import client import deluge.component as component +import deluge.common from optparse import make_option import os @@ -51,7 +52,7 @@ class Command(BaseCommand): help='save path for torrent'), ) - usage = "Usage: add [-p <save-location>] <torrent-file> [<torrent-file> ...]" + usage = "Usage: add [-p <save-location>] <torrent-file/infohash/url> [<torrent-file/infohash/url> ...]" def handle(self, *args, **options): self.console = component.get("ConsoleUI") @@ -60,25 +61,33 @@ class Command(BaseCommand): if options["path"]: t_options["download_location"] = os.path.expanduser(options["path"]) + def on_success(result): + self.console.write("{!success!}Torrent added!") + def on_fail(result): + self.console.write("{!error!}Torrent was not added! %s" % result) + # Keep a list of deferreds to make a DeferredList deferreds = [] for arg in args: - if not os.path.exists(arg): - self.console.write("{!error!}%s doesn't exist!" % arg) - continue - if not os.path.isfile(arg): - self.console.write("{!error!}This is a directory!") + if not arg.strip(): continue - self.console.write("{!info!}Attempting to add torrent: %s" % arg) - filename = os.path.split(arg)[-1] - filedump = base64.encodestring(open(arg, "rb").read()) - - def on_success(result): - self.console.write("{!success!}Torrent added!") - def on_fail(result): - self.console.write("{!error!}Torrent was not added! %s" % result) - - deferreds.append(client.core.add_torrent_file(filename, filedump, t_options).addCallback(on_success).addErrback(on_fail)) + if deluge.common.is_url(arg): + deferreds.append(client.core.add_torrent_url(arg, t_options).addCallback(on_success).addErrback(on_fail)) + elif deluge.common.is_magnet(arg): + deferreds.append(client.core.add_torrent_magnet(arg, t_options).addCallback(on_success).addErrback(on_fail)) + else: + # Just a file + path = os.path.abspath(arg.replace('file://', '', 1)) + if not os.path.exists(path): + self.console.write("{!error!}%s doesn't exist!" % arg) + continue + if not os.path.isfile(path): + self.console.write("{!error!}This is a directory!") + continue + self.console.write("{!info!}Attempting to add torrent: %s" % arg) + filename = os.path.split(arg)[-1] + filedump = base64.encodestring(open(arg, "rb").read()) + deferreds.append(client.core.add_torrent_file(filename, filedump, t_options).addCallback(on_success).addErrback(on_fail)) return defer.DeferredList(deferreds) -- 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.
