Add 'save_path' to add_torrent().
Save the 'save_path' in the torrent state.
This commit is contained in:
parent
8a0692fa4f
commit
17f62130fe
@ -182,12 +182,16 @@ class Core(dbus.service.Object):
|
|||||||
gobject.idle_add(self._shutdown)
|
gobject.idle_add(self._shutdown)
|
||||||
|
|
||||||
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
|
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
|
||||||
in_signature="say", out_signature="b")
|
in_signature="ssay", out_signature="b")
|
||||||
def add_torrent_file(self, filename, filedump):
|
def add_torrent_file(self, filename, save_path, filedump):
|
||||||
"""Adds a torrent file to the libtorrent session
|
"""Adds a torrent file to the libtorrent session
|
||||||
This requires the torrents filename and a dump of it's content
|
This requires the torrents filename and a dump of it's content
|
||||||
"""
|
"""
|
||||||
torrent_id = self.torrents.add(filename, filedump)
|
if save_path == "":
|
||||||
|
save_path = None
|
||||||
|
|
||||||
|
torrent_id = self.torrents.add(filename, filedump=filedump,
|
||||||
|
save_path=save_path)
|
||||||
|
|
||||||
# Run the plugin hooks for 'post_torrent_add'
|
# Run the plugin hooks for 'post_torrent_add'
|
||||||
self.plugins.run_post_torrent_add(torrent_id)
|
self.plugins.run_post_torrent_add(torrent_id)
|
||||||
@ -201,8 +205,8 @@ class Core(dbus.service.Object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
|
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
|
||||||
in_signature="s", out_signature="b")
|
in_signature="ss", out_signature="b")
|
||||||
def add_torrent_url(self, url):
|
def add_torrent_url(self, url, save_path):
|
||||||
log.info("Attempting to add url %s", url)
|
log.info("Attempting to add url %s", url)
|
||||||
|
|
||||||
# Get the actual filename of the torrent from the url provided.
|
# Get the actual filename of the torrent from the url provided.
|
||||||
@ -221,7 +225,7 @@ class Core(dbus.service.Object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# Add the torrent to session
|
# Add the torrent to session
|
||||||
return self.add_torrent_file(filename, filedump)
|
return self.add_torrent_file(filename, save_path, filedump)
|
||||||
|
|
||||||
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
|
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
|
||||||
in_signature="s", out_signature="")
|
in_signature="s", out_signature="")
|
||||||
|
|||||||
@ -38,7 +38,7 @@ import deluge.common
|
|||||||
class Torrent:
|
class Torrent:
|
||||||
"""Torrent holds information about torrents added to the libtorrent session.
|
"""Torrent holds information about torrents added to the libtorrent session.
|
||||||
"""
|
"""
|
||||||
def __init__(self, filename, handle, compact):
|
def __init__(self, filename, handle, compact, save_path):
|
||||||
# Set the filename
|
# Set the filename
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
# Set the libtorrent handle
|
# Set the libtorrent handle
|
||||||
@ -49,6 +49,8 @@ class Torrent:
|
|||||||
self.total_uploaded = 0
|
self.total_uploaded = 0
|
||||||
# Set the allocation mode
|
# Set the allocation mode
|
||||||
self.compact = compact
|
self.compact = compact
|
||||||
|
# Where the torrent is being saved to
|
||||||
|
self.save_path = save_path
|
||||||
# The tracker status
|
# The tracker status
|
||||||
self.tracker_status = ""
|
self.tracker_status = ""
|
||||||
|
|
||||||
@ -59,7 +61,8 @@ class Torrent:
|
|||||||
def get_state(self):
|
def get_state(self):
|
||||||
"""Returns the state of this torrent for saving to the session state"""
|
"""Returns the state of this torrent for saving to the session state"""
|
||||||
status = self.handle.status()
|
status = self.handle.status()
|
||||||
return (self.torrent_id, self.filename, self.compact, status.paused)
|
return (self.torrent_id, self.filename, self.compact, status.paused,
|
||||||
|
self.save_path)
|
||||||
|
|
||||||
def get_eta(self):
|
def get_eta(self):
|
||||||
"""Returns the ETA in seconds for this torrent"""
|
"""Returns the ETA in seconds for this torrent"""
|
||||||
|
|||||||
@ -47,11 +47,12 @@ from deluge.core.torrent import Torrent
|
|||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
class TorrentState:
|
class TorrentState:
|
||||||
def __init__(self, torrent_id, filename, compact, paused):
|
def __init__(self, torrent_id, filename, compact, paused, save_path):
|
||||||
self.torrent_id = torrent_id
|
self.torrent_id = torrent_id
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.compact = compact
|
self.compact = compact
|
||||||
self.paused = paused
|
self.paused = paused
|
||||||
|
self.save_path = save_path
|
||||||
|
|
||||||
class TorrentManagerState:
|
class TorrentManagerState:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -117,7 +118,8 @@ class TorrentManager:
|
|||||||
"""Returns a list of torrent_ids"""
|
"""Returns a list of torrent_ids"""
|
||||||
return self.torrents.keys()
|
return self.torrents.keys()
|
||||||
|
|
||||||
def add(self, filename, filedump=None, compact=None, paused=False):
|
def add(self, filename, filedump=None, compact=None, paused=False,
|
||||||
|
save_path=None):
|
||||||
"""Add a torrent to the manager and returns it's torrent_id"""
|
"""Add a torrent to the manager and returns it's torrent_id"""
|
||||||
log.info("Adding torrent: %s", filename)
|
log.info("Adding torrent: %s", filename)
|
||||||
|
|
||||||
@ -160,6 +162,10 @@ class TorrentManager:
|
|||||||
torrent_filedump = lt.bdecode(filedump)
|
torrent_filedump = lt.bdecode(filedump)
|
||||||
handle = None
|
handle = None
|
||||||
|
|
||||||
|
# Make sure we have a valid download_location
|
||||||
|
if save_path is None:
|
||||||
|
save_path = self.config["download_location"]
|
||||||
|
|
||||||
# Make sure we are adding it with the correct allocation method.
|
# Make sure we are adding it with the correct allocation method.
|
||||||
if compact is None:
|
if compact is None:
|
||||||
compact = self.config["compact_allocation"]
|
compact = self.config["compact_allocation"]
|
||||||
@ -167,7 +173,7 @@ class TorrentManager:
|
|||||||
try:
|
try:
|
||||||
handle = self.session.add_torrent(
|
handle = self.session.add_torrent(
|
||||||
lt.torrent_info(torrent_filedump),
|
lt.torrent_info(torrent_filedump),
|
||||||
self.config["download_location"],
|
save_path,
|
||||||
resume_data=fastresume,
|
resume_data=fastresume,
|
||||||
compact_mode=compact,
|
compact_mode=compact,
|
||||||
paused=paused)
|
paused=paused)
|
||||||
@ -179,7 +185,8 @@ class TorrentManager:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# Create a Torrent object
|
# Create a Torrent object
|
||||||
torrent = Torrent(filename, handle, compact)
|
torrent = Torrent(filename, handle, compact,
|
||||||
|
save_path)
|
||||||
# Add the torrent object to the dictionary
|
# Add the torrent object to the dictionary
|
||||||
self.torrents[torrent.torrent_id] = torrent
|
self.torrents[torrent.torrent_id] = torrent
|
||||||
|
|
||||||
@ -187,7 +194,7 @@ class TorrentManager:
|
|||||||
handle.set_max_connections(self.max_connections)
|
handle.set_max_connections(self.max_connections)
|
||||||
handle.set_max_uploads(self.max_uploads)
|
handle.set_max_uploads(self.max_uploads)
|
||||||
|
|
||||||
log.debug("Attemping to save torrent file: %s", filename)
|
log.debug("Attempting to save torrent file: %s", filename)
|
||||||
# Test if the torrentfiles_location is accessible
|
# Test if the torrentfiles_location is accessible
|
||||||
if os.access(
|
if os.access(
|
||||||
os.path.join(self.config["torrentfiles_location"]), os.F_OK) \
|
os.path.join(self.config["torrentfiles_location"]), os.F_OK) \
|
||||||
@ -303,7 +310,7 @@ class TorrentManager:
|
|||||||
# Try to add the torrents in the state to the session
|
# Try to add the torrents in the state to the session
|
||||||
for torrent_state in state.torrents:
|
for torrent_state in state.torrents:
|
||||||
self.add(torrent_state.filename, compact=torrent_state.compact,
|
self.add(torrent_state.filename, compact=torrent_state.compact,
|
||||||
paused=torrent_state.paused)
|
paused=torrent_state.paused, save_path=torrent_state.save_path)
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
"""Save the state of the TorrentManager to the torrents.state file"""
|
"""Save the state of the TorrentManager to the torrents.state file"""
|
||||||
|
|||||||
@ -85,7 +85,7 @@ def add_torrent_file(torrent_files):
|
|||||||
f = open(torrent_file, "rb")
|
f = open(torrent_file, "rb")
|
||||||
# Get the filename because the core doesn't want a path.
|
# Get the filename because the core doesn't want a path.
|
||||||
(path, filename) = os.path.split(torrent_file)
|
(path, filename) = os.path.split(torrent_file)
|
||||||
result = core.add_torrent_file(filename, f.read())
|
result = core.add_torrent_file(filename, str(), f.read())
|
||||||
f.close()
|
f.close()
|
||||||
if result is False:
|
if result is False:
|
||||||
# The torrent was not added successfully.
|
# The torrent was not added successfully.
|
||||||
@ -96,7 +96,7 @@ def add_torrent_url(torrent_url):
|
|||||||
core = get_core()
|
core = get_core()
|
||||||
from deluge.common import is_url
|
from deluge.common import is_url
|
||||||
if is_url(torrent_url):
|
if is_url(torrent_url):
|
||||||
result = core.add_torrent_url(torrent_url)
|
result = core.add_torrent_url(torrent_url, str())
|
||||||
if result is False:
|
if result is False:
|
||||||
# The torrent url was not added successfully.
|
# The torrent url was not added successfully.
|
||||||
log.warning("Torrent %s was not added successfully.", torrent_url)
|
log.warning("Torrent %s was not added successfully.", torrent_url)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user