Fix #270 autoadd folder
This commit is contained in:
parent
d7957f82e7
commit
5936aeebb6
|
@ -91,9 +91,7 @@ class AutoAdd(component.Component):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# The torrent looks good, so lets add it to the session
|
# The torrent looks good, so lets add it to the session
|
||||||
component.get("TorrentManager").add(
|
component.get("TorrentManager").add(filedump=filedump)
|
||||||
os.path.split(filepath)[1],
|
|
||||||
filedump)
|
|
||||||
|
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
|
|
||||||
|
|
|
@ -325,21 +325,8 @@ class Core(
|
||||||
log.warn("Unable to decode torrent file: %s", e)
|
log.warn("Unable to decode torrent file: %s", e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
torrent_id = self.torrents.add(torrent_info=torrent_info, options=options)
|
torrent_id = self.torrents.add(filedump=filedump, 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)
|
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
||||||
|
|
|
@ -203,15 +203,23 @@ class TorrentManager(component.Component):
|
||||||
|
|
||||||
return fastresume
|
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"""
|
"""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!")
|
log.debug("You must specify a valid torrent_info or a torrent state object!")
|
||||||
return
|
return
|
||||||
|
|
||||||
log.debug("torrentmanager.add")
|
log.debug("torrentmanager.add")
|
||||||
add_torrent_params = {}
|
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:
|
if torrent_info is None:
|
||||||
# We have no torrent_info so we need to add the torrent with information
|
# We have no torrent_info so we need to add the torrent with information
|
||||||
# from the state object.
|
# from the state object.
|
||||||
|
@ -312,6 +320,17 @@ class TorrentManager(component.Component):
|
||||||
handle.resume()
|
handle.resume()
|
||||||
handle.auto_managed(options["auto_managed"])
|
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:
|
if save_state:
|
||||||
# Save the session state
|
# Save the session state
|
||||||
self.save_state()
|
self.save_state()
|
||||||
|
|
Loading…
Reference in New Issue