Fixed #268 - Tweaks for torrents loading from command line, from url.

This commit is contained in:
Alex Dedul 2007-07-16 16:07:06 +00:00
parent 30b69cd85a
commit df898e22b8
4 changed files with 29 additions and 29 deletions

View File

@ -63,8 +63,6 @@ import deluge.interface
parser = OptionParser(usage="%prog [options] [actions]", version=deluge.common.PROGRAM_VERSION) parser = OptionParser(usage="%prog [options] [actions]", version=deluge.common.PROGRAM_VERSION)
parser.add_option("--tray", dest="tray", help="start Deluge hidden in system tray", parser.add_option("--tray", dest="tray", help="start Deluge hidden in system tray",
metavar="TRAY", action="store_true") metavar="TRAY", action="store_true")
parser.add_option("--url", dest="url", help="Load a torrent from a URL",
metavar="URL", action="store")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -106,7 +104,20 @@ Continuing...""" % pstate_file_path
print >> sys.stderr, "The error was: %s." % oopsie print >> sys.stderr, "The error was: %s." % oopsie
def get_cmd_line_torrents(): def get_cmd_line_torrents():
return [os.path.abspath(x) for x in args] cmd_line_torrents = []
for torrent in args:
if deluge.common.is_url(torrent):
filename = deluge.common.fetch_url(torrent)
if filename:
cmd_line_torrents.append(filename)
else:
if not torrent.endswith(".torrent"):
print "Error,", torrent, " does not seem to be a .torrent file"
else:
cmd_line_torrents.append(os.path.abspath(torrent))
return cmd_line_torrents
def start_deluge(): def start_deluge():
print "Starting new Deluge session..." print "Starting new Deluge session..."
@ -115,7 +126,7 @@ def start_deluge():
interface = deluge.interface.DelugeGTK() interface = deluge.interface.DelugeGTK()
interface.start(options.tray, get_cmd_line_torrents(), options.url) interface.start(options.tray, get_cmd_line_torrents())
if dbus_imported: if dbus_imported:
bus = dbus.SessionBus() bus = dbus.SessionBus()
@ -137,10 +148,6 @@ if dbus_imported:
for filename in get_cmd_line_torrents(): for filename in get_cmd_line_torrents():
deluge_iface.interactive_add_torrent(filename) deluge_iface.interactive_add_torrent(filename)
if options.url:
deluge_iface.interactive_add_torrent_url(options.url)
else: else:
print "no existing Deluge session" print "no existing Deluge session"
start_deluge() start_deluge()

View File

@ -129,14 +129,19 @@ def is_url(url):
def fetch_url(url): def fetch_url(url):
import urllib import urllib
filename, headers = urllib.urlretrieve(url) try:
if filename.endswith(".torrent") or \ filename, headers = urllib.urlretrieve(url)
headers["content-type"]=="application/x-bittorrent": except IOError:
return filename, headers print 'Network error while trying to fetch torrent from %s' % url
else: else:
print "URL doesn't appear to be a valid torrent file:", url if filename.endswith(".torrent") or \
return None, None headers["content-type"]=="application/x-bittorrent":
return filename
else:
print "URL doesn't appear to be a valid torrent file:", url
return None
# Encryption States # Encryption States
class EncState: class EncState:

View File

@ -32,7 +32,6 @@
import os.path import os.path
from itertools import izip from itertools import izip
import re
import gettext import gettext
import gobject import gobject
@ -766,8 +765,7 @@ class DelugeGTK:
return rlist return rlist
## Start the timer that updates the interface ## Start the timer that updates the interface
def start(self, start_in_tray=False, cmd_line_torrents=None, def start(self, start_in_tray=False, cmd_line_torrents=None):
cmd_line_torrent_url=None):
if cmd_line_torrents is None: if cmd_line_torrents is None:
cmd_line_torrents = [] cmd_line_torrents = []
@ -782,7 +780,6 @@ class DelugeGTK:
for torrent_file in cmd_line_torrents: for torrent_file in cmd_line_torrents:
self.interactive_add_torrent(torrent_file) self.interactive_add_torrent(torrent_file)
self.interactive_add_torrent_url(cmd_line_torrent_url)
# Load plugins after we showed main window (if not started in tray) # Load plugins after we showed main window (if not started in tray)
self.load_plugins() self.load_plugins()
@ -1065,15 +1062,11 @@ class DelugeGTK:
def interactive_add_torrent_url(self, url): def interactive_add_torrent_url(self, url):
if url: if url:
filename, headers = common.fetch_url(url) filename = common.fetch_url(url)
if filename: if filename:
self.interactive_add_torrent(filename) self.interactive_add_torrent(filename)
def interactive_add_torrent(self, torrent): def interactive_add_torrent(self, torrent):
if not torrent.endswith(".torrent"):
print "Error,", torrent, " does not seem to be a .torrent file"
return
if self.config.get('use_default_dir'): if self.config.get('use_default_dir'):
path = self.config.get('default_download_path') path = self.config.get('default_download_path')
else: else:

View File

@ -61,9 +61,6 @@ if dbus_imported:
@dbus.service.method('org.deluge_torrent.Deluge') @dbus.service.method('org.deluge_torrent.Deluge')
def interactive_add_torrent(self, torrent_file): def interactive_add_torrent(self, torrent_file):
self.interface.interactive_add_torrent(torrent_file) self.interface.interactive_add_torrent(torrent_file)
@dbus.service.method('org.deluge_torrent.Deluge')
def interactive_add_torrent_url(self, url):
self.interface.interactive_add_torrent_url(url)
else: else:
# This is a fallback class in case dbus is not available # This is a fallback class in case dbus is not available
class Manager: class Manager:
@ -72,5 +69,3 @@ else:
def interactive_add_torrent(self, torrent_file): def interactive_add_torrent(self, torrent_file):
print "I can't do anything with this." print "I can't do anything with this."
def interactive_add_torrent_url(self, url):
print "I can't do anything with this."