diff --git a/deluge/core/autoadd.py b/deluge/core/autoadd.py index e053e4131..78d6d1575 100644 --- a/deluge/core/autoadd.py +++ b/deluge/core/autoadd.py @@ -91,9 +91,7 @@ class AutoAdd(component.Component): continue # The torrent looks good, so lets add it to the session - component.get("TorrentManager").add( - os.path.split(filepath)[1], - filedump) + component.get("TorrentManager").add(filedump=filedump) os.remove(filepath) diff --git a/deluge/core/core.py b/deluge/core/core.py index eeb732abd..1feb8838c 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -325,21 +325,8 @@ class Core( log.warn("Unable to decode torrent file: %s", e) return None - torrent_id = self.torrents.add(torrent_info=torrent_info, options=options) - - # Here we need to save a copy of the filedump for state purposes - # and also if the user wishes to save a copy of the torrent elsewhere. - if torrent_id: - # Write the .torrent file to the state directory - try: - save_file = open(os.path.join(self.config["state_location"], - torrent_id + ".torrent"), - "wb") - save_file.write(filedump) - save_file.close() - except IOError, e: - log.warning("Unable to save torrent file: %s", e) - + torrent_id = self.torrents.add(filedump=filedump, options=options) + # Run the plugin hooks for 'post_torrent_add' self.plugins.run_post_torrent_add(torrent_id) diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 86dcaa003..d135c0324 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -203,15 +203,23 @@ class TorrentManager(component.Component): return fastresume - def add(self, torrent_info=None, state=None, options=None, save_state=True): + def add(self, torrent_info=None, state=None, options=None, save_state=True, + filedump=None): """Add a torrent to the manager and returns it's torrent_id""" - if torrent_info is None and state is None: + + if torrent_info is None and state is None and filedump is None: log.debug("You must specify a valid torrent_info or a torrent state object!") return log.debug("torrentmanager.add") add_torrent_params = {} + if filedump is not None: + try: + torrent_info = lt.torrent_info(lt.bdecode(filedump)) + except Exception, e: + log.error("Unable to decode torrent file!: %s", e) + if torrent_info is None: # We have no torrent_info so we need to add the torrent with information # from the state object. @@ -312,6 +320,17 @@ class TorrentManager(component.Component): handle.resume() handle.auto_managed(options["auto_managed"]) + # Write the .torrent file to the state directory + if filedump: + try: + save_file = open(os.path.join(self.config["state_location"], + torrent.torrent_id + ".torrent"), + "wb") + save_file.write(filedump) + save_file.close() + except IOError, e: + log.warning("Unable to save torrent file: %s", e) + if save_state: # Save the session state self.save_state()