Fix #1258: Add Magnet and Url support to add command in console
This commit is contained in:
parent
cc130c0085
commit
fbc664fa14
|
@ -27,6 +27,9 @@
|
||||||
=== Execute ===
|
=== Execute ===
|
||||||
* #1477: Fix ignore Added events from state file on startup
|
* #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) ===
|
=== Deluge 1.3.2 (24 May 2011) ===
|
||||||
==== Core ====
|
==== Core ====
|
||||||
* #1527: Fix Converting unicode to unicode error in move_storage
|
* #1527: Fix Converting unicode to unicode error in move_storage
|
||||||
|
|
|
@ -39,6 +39,7 @@ from deluge.ui.console.main import BaseCommand
|
||||||
import deluge.ui.console.colors as colors
|
import deluge.ui.console.colors as colors
|
||||||
from deluge.ui.client import client
|
from deluge.ui.client import client
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
|
import deluge.common
|
||||||
|
|
||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
import os
|
import os
|
||||||
|
@ -51,7 +52,7 @@ class Command(BaseCommand):
|
||||||
help='save path for torrent'),
|
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):
|
def handle(self, *args, **options):
|
||||||
self.console = component.get("ConsoleUI")
|
self.console = component.get("ConsoleUI")
|
||||||
|
@ -60,25 +61,33 @@ class Command(BaseCommand):
|
||||||
if options["path"]:
|
if options["path"]:
|
||||||
t_options["download_location"] = os.path.expanduser(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
|
# Keep a list of deferreds to make a DeferredList
|
||||||
deferreds = []
|
deferreds = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if not os.path.exists(arg):
|
if not arg.strip():
|
||||||
self.console.write("{!error!}%s doesn't exist!" % arg)
|
|
||||||
continue
|
continue
|
||||||
if not os.path.isfile(arg):
|
if deluge.common.is_url(arg):
|
||||||
self.console.write("{!error!}This is a directory!")
|
deferreds.append(client.core.add_torrent_url(arg, t_options).addCallback(on_success).addErrback(on_fail))
|
||||||
continue
|
elif deluge.common.is_magnet(arg):
|
||||||
self.console.write("{!info!}Attempting to add torrent: %s" % arg)
|
deferreds.append(client.core.add_torrent_magnet(arg, t_options).addCallback(on_success).addErrback(on_fail))
|
||||||
filename = os.path.split(arg)[-1]
|
else:
|
||||||
filedump = base64.encodestring(open(arg, "rb").read())
|
# Just a file
|
||||||
|
path = os.path.abspath(arg.replace('file://', '', 1))
|
||||||
def on_success(result):
|
if not os.path.exists(path):
|
||||||
self.console.write("{!success!}Torrent added!")
|
self.console.write("{!error!}%s doesn't exist!" % arg)
|
||||||
def on_fail(result):
|
continue
|
||||||
self.console.write("{!error!}Torrent was not added! %s" % result)
|
if not os.path.isfile(path):
|
||||||
|
self.console.write("{!error!}This is a directory!")
|
||||||
deferreds.append(client.core.add_torrent_file(filename, filedump, t_options).addCallback(on_success).addErrback(on_fail))
|
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)
|
return defer.DeferredList(deferreds)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue