[Core] Assign magnet arg if magnet URI in filename
A magnet that prefetched the metadata is added as a normal torrent but with the filename set to the magnet URI. So we need to assign the URI to magnet arg and set filename to None before creating Torrent object. Updated the is_magnet function to prevent AttributeError with None type.
This commit is contained in:
parent
57ea5ef5da
commit
23f1cfc926
|
@ -672,11 +672,11 @@ def is_magnet(uri):
|
|||
True
|
||||
|
||||
"""
|
||||
|
||||
if uri.startswith(MAGNET_SCHEME) and XT_BTIH_PARAM in uri:
|
||||
return True
|
||||
if not uri:
|
||||
return False
|
||||
|
||||
return uri.startswith(MAGNET_SCHEME) and XT_BTIH_PARAM in uri
|
||||
|
||||
|
||||
def get_magnet_info(uri):
|
||||
"""Parse torrent information from magnet link.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'))
|
||||
|
|
Loading…
Reference in New Issue