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.add_option("--tray", dest="tray", help="start Deluge hidden in system tray",
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()
@ -106,7 +104,20 @@ Continuing...""" % pstate_file_path
print >> sys.stderr, "The error was: %s." % oopsie
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():
print "Starting new Deluge session..."
@ -115,7 +126,7 @@ def start_deluge():
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:
bus = dbus.SessionBus()
@ -137,10 +148,6 @@ if dbus_imported:
for filename in get_cmd_line_torrents():
deluge_iface.interactive_add_torrent(filename)
if options.url:
deluge_iface.interactive_add_torrent_url(options.url)
else:
print "no existing Deluge session"
start_deluge()

View File

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

View File

@ -32,7 +32,6 @@
import os.path
from itertools import izip
import re
import gettext
import gobject
@ -766,8 +765,7 @@ class DelugeGTK:
return rlist
## Start the timer that updates the interface
def start(self, start_in_tray=False, cmd_line_torrents=None,
cmd_line_torrent_url=None):
def start(self, start_in_tray=False, cmd_line_torrents=None):
if cmd_line_torrents is None:
cmd_line_torrents = []
@ -782,7 +780,6 @@ class DelugeGTK:
for torrent_file in cmd_line_torrents:
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)
self.load_plugins()
@ -1065,15 +1062,11 @@ class DelugeGTK:
def interactive_add_torrent_url(self, url):
if url:
filename, headers = common.fetch_url(url)
filename = common.fetch_url(url)
if filename:
self.interactive_add_torrent(filename)
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'):
path = self.config.get('default_download_path')
else:

View File

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