[Core] Fix adding magnet with trailing newline

* A bug in libtorrent means that a magnet with a trailing newline will be added
   but with an invalid info_hash. Strip any whitespace before add is a workaround.
This commit is contained in:
Calum Lind 2017-02-15 23:30:53 +00:00
parent 8a3f15e5c0
commit b52de1549e
3 changed files with 8 additions and 5 deletions

View File

@ -471,7 +471,8 @@ class TorrentManager(component.Component):
handle = None handle = None
try: try:
if magnet: if magnet:
handle = lt.add_magnet_uri(self.session, utf8_encoded(magnet), add_torrent_params) magnet_uri = utf8_encoded(magnet.strip())
handle = lt.add_magnet_uri(self.session, magnet_uri, add_torrent_params)
else: else:
handle = self.session.add_torrent(add_torrent_params) handle = self.session.add_torrent(add_torrent_params)
except RuntimeError, e: except RuntimeError, e:

View File

@ -163,7 +163,7 @@ class Core(CorePluginBase):
_file = open(filename, "rb") _file = open(filename, "rb")
elif magnet == True: elif magnet == True:
_file = open(filename, "r") _file = open(filename, "r")
filedump = _file.read() filedump = _file.read().strip()
if not filedump: if not filedump:
raise RuntimeError, "Torrent is 0 bytes!" raise RuntimeError, "Torrent is 0 bytes!"
_file.close() _file.close()
@ -197,8 +197,10 @@ class Core(CorePluginBase):
for part in magnet.split('&'): for part in magnet.split('&'):
if part.startswith("dn="): if part.startswith("dn="):
mname = os.sep.join([path, part[3:] + ".magnet"]) name = part[3:].strip()
break if name:
mname = os.sep.join([path, name + ".magnet"])
break
else: else:
short_hash = magnet.split("btih:")[1][:8] short_hash = magnet.split("btih:")[1][:8]
mname = '.'.join([filename, short_hash, "magnet"]) mname = '.'.join([filename, short_hash, "magnet"])

View File

@ -42,7 +42,7 @@ from setuptools import setup
__plugin_name__ = "AutoAdd" __plugin_name__ = "AutoAdd"
__author__ = "Chase Sterling" __author__ = "Chase Sterling"
__author_email__ = "chase.sterling@gmail.com" __author_email__ = "chase.sterling@gmail.com"
__version__ = "1.04" __version__ = "1.05"
__url__ = "http://dev.deluge-torrent.org/wiki/Plugins/AutoAdd" __url__ = "http://dev.deluge-torrent.org/wiki/Plugins/AutoAdd"
__license__ = "GPLv3" __license__ = "GPLv3"
__description__ = "Monitors folders for .torrent files." __description__ = "Monitors folders for .torrent files."