[#2463] [AutoAdd] Fix not loading torrents

The owner attribute for tm.add() method was moved to options dict
This commit is contained in:
Calum Lind 2014-07-02 19:32:32 +01:00
commit 48fb321699

View file

@ -41,6 +41,8 @@
from deluge._libtorrent import lt from deluge._libtorrent import lt
import os import os
import logging import logging
import base64
from deluge.plugins.pluginbase import CorePluginBase from deluge.plugins.pluginbase import CorePluginBase
import deluge.component as component import deluge.component as component
import deluge.configmanager import deluge.configmanager
@ -164,10 +166,11 @@ class Core(CorePluginBase):
def load_torrent(self, filename, magnet): def load_torrent(self, filename, magnet):
try: try:
log.debug("Attempting to open %s for add.", filename) log.debug("Attempting to open %s for add.", filename)
if magnet == False: if magnet:
_file = open(filename, "rb")
elif magnet == True:
_file = open(filename, "r") _file = open(filename, "r")
else:
_file = open(filename, "rb")
filedump = _file.read() filedump = _file.read()
if not filedump: if not filedump:
raise RuntimeError, "Torrent is 0 bytes!" raise RuntimeError, "Torrent is 0 bytes!"
@ -180,7 +183,7 @@ class Core(CorePluginBase):
if magnet == False: if magnet == False:
lt.torrent_info(lt.bdecode(filedump)) lt.torrent_info(lt.bdecode(filedump))
return filedump return base64.encodestring(filedump)
def split_magnets(self, filename): def split_magnets(self, filename):
log.debug("Attempting to open %s for splitting magnets.", filename) log.debug("Attempting to open %s for splitting magnets.", filename)
@ -238,7 +241,7 @@ class Core(CorePluginBase):
# without them is valid, and applies all its settings. # without them is valid, and applies all its settings.
for option, value in watchdir.iteritems(): for option, value in watchdir.iteritems():
if OPTIONS_AVAILABLE.get(option): if OPTIONS_AVAILABLE.get(option):
if watchdir.get(option+'_toggle', True): if watchdir.get(option+'_toggle', True) or option == "owner":
opts[option] = value opts[option] = value
# Check for .magnet files containing multiple magnet links and # Check for .magnet files containing multiple magnet links and
@ -296,16 +299,11 @@ class Core(CorePluginBase):
continue continue
# The torrent looks good, so lets add it to the session. # The torrent looks good, so lets add it to the session.
if magnet == False: if magnet:
torrent_id = component.get("TorrentManager").add( torrent_id = component.get("Core").add_torrent_magnet(filedump, opts)
filedump=filedump, filename=filename, options=opts, else:
owner=watchdir.get("owner", "localclient") torrent_id = component.get("Core").add_torrent_file(filename, filedump, opts)
)
elif magnet == True:
torrent_id = component.get("TorrentManager").add(
magnet=filedump, options=opts,
owner=watchdir.get("owner", "localclient")
)
# If the torrent added successfully, set the extra options. # If the torrent added successfully, set the extra options.
if torrent_id: if torrent_id:
if 'Label' in component.get("CorePluginManager").get_enabled_plugins(): if 'Label' in component.get("CorePluginManager").get_enabled_plugins():
@ -321,7 +319,7 @@ class Core(CorePluginBase):
component.get("TorrentManager").queue_bottom(torrent_id) component.get("TorrentManager").queue_bottom(torrent_id)
else: else:
# torrent handle is invalid and so is the magnet link # torrent handle is invalid and so is the magnet link
if magnet == True: if magnet:
log.debug("invalid magnet link") log.debug("invalid magnet link")
os.rename(filepath, filepath + ".invalid") os.rename(filepath, filepath + ".invalid")
continue continue