diff --git a/deluge/common.py b/deluge/common.py index c5a9572cb..6de58a9c5 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -672,10 +672,10 @@ def is_magnet(uri): True """ + if not uri: + return False - if uri.startswith(MAGNET_SCHEME) and XT_BTIH_PARAM in uri: - return True - return False + return uri.startswith(MAGNET_SCHEME) and XT_BTIH_PARAM in uri def get_magnet_info(uri): diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 31e28b6a0..2ab5c66e9 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -23,7 +23,7 @@ from twisted.internet.task import LoopingCall import deluge.component as component from deluge._libtorrent import lt -from deluge.common import archive_files, decode_bytes, get_magnet_info +from deluge.common import archive_files, decode_bytes, get_magnet_info, is_magnet from deluge.configmanager import ConfigManager, get_config_dir from deluge.core.authmanager import AUTH_LEVEL_ADMIN from deluge.core.torrent import Torrent, TorrentOptions, sanitize_filepath @@ -555,6 +555,11 @@ class TorrentManager(component.Component): return d def _add_torrent_obj(self, handle, options, state, filename, magnet, resume_data, filedump, save_state): + # For magnets added with metadata, filename is used so set as magnet. + if not magnet and is_magnet(filename): + magnet = filename + filename = None + # Create a Torrent object and add to the dictionary. torrent = Torrent(handle, options, state, filename, magnet) self.torrents[torrent.torrent_id] = torrent diff --git a/deluge/tests/test_common.py b/deluge/tests/test_common.py index 43f82f010..0a35ce6af 100644 --- a/deluge/tests/test_common.py +++ b/deluge/tests/test_common.py @@ -74,6 +74,7 @@ class CommonTestCase(unittest.TestCase): def test_is_magnet(self): self.assertTrue(is_magnet('magnet:?xt=urn:btih:SU5225URMTUEQLDXQWRB2EQWN6KLTYKN')) + self.assertFalse(is_magnet(None)) def test_is_infohash(self): self.assertTrue(is_infohash('2dc5d0e71a66fe69649a640d39cb00a259704973'))