From b52de1549eb8dd8297d9c603a7faa1b58d647daf Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Wed, 15 Feb 2017 23:30:53 +0000 Subject: [PATCH] [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. --- deluge/core/torrentmanager.py | 3 ++- deluge/plugins/autoadd/autoadd/core.py | 8 +++++--- deluge/plugins/autoadd/setup.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index abd35e328..a5c3620cc 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -471,7 +471,8 @@ class TorrentManager(component.Component): handle = None try: 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: handle = self.session.add_torrent(add_torrent_params) except RuntimeError, e: diff --git a/deluge/plugins/autoadd/autoadd/core.py b/deluge/plugins/autoadd/autoadd/core.py index 53c557598..adbc66ec5 100644 --- a/deluge/plugins/autoadd/autoadd/core.py +++ b/deluge/plugins/autoadd/autoadd/core.py @@ -163,7 +163,7 @@ class Core(CorePluginBase): _file = open(filename, "rb") elif magnet == True: _file = open(filename, "r") - filedump = _file.read() + filedump = _file.read().strip() if not filedump: raise RuntimeError, "Torrent is 0 bytes!" _file.close() @@ -197,8 +197,10 @@ class Core(CorePluginBase): for part in magnet.split('&'): if part.startswith("dn="): - mname = os.sep.join([path, part[3:] + ".magnet"]) - break + name = part[3:].strip() + if name: + mname = os.sep.join([path, name + ".magnet"]) + break else: short_hash = magnet.split("btih:")[1][:8] mname = '.'.join([filename, short_hash, "magnet"]) diff --git a/deluge/plugins/autoadd/setup.py b/deluge/plugins/autoadd/setup.py index de759fab7..96e811834 100644 --- a/deluge/plugins/autoadd/setup.py +++ b/deluge/plugins/autoadd/setup.py @@ -42,7 +42,7 @@ from setuptools import setup __plugin_name__ = "AutoAdd" __author__ = "Chase Sterling" __author_email__ = "chase.sterling@gmail.com" -__version__ = "1.04" +__version__ = "1.05" __url__ = "http://dev.deluge-torrent.org/wiki/Plugins/AutoAdd" __license__ = "GPLv3" __description__ = "Monitors folders for .torrent files."