Skip to content

Commit

Permalink
Merge pull request #7888 from xoriole/fix/7887-fix-download
Browse files Browse the repository at this point in the history
Fix download using magnetlink without metainfo
  • Loading branch information
xoriole authored Feb 7, 2024
2 parents 359c03a + 9efbbd1 commit 49d94dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ async def start_download_from_uri(self, uri, config=None):
tdef = TorrentDef.load_from_dict(self.metainfo_cache[infohash]['meta_info'])
else:
self._logger.info('Metainfo not found in cache')
tdef = TorrentDefNoMetainfo(infohash, b"Unknown name" if not name else name, url=uri)
name_encoded = name.encode('utf8') if name else b"Unknown name"
tdef = TorrentDefNoMetainfo(infohash, name_encoded, url=uri)
return await self.start_download(tdef=tdef, config=config)
if scheme == FILE_SCHEME:
self._logger.info('File scheme detected')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,13 @@ async def test_start_download_from_magnet_no_name(fake_dlmgr: DownloadManager):
assert download.tdef.get_name() == b'Unknown name'


async def test_start_download_from_magnet_with_name(fake_dlmgr: DownloadManager):
# Test whether a download is started with `Unknown name` name when the magnet has no name
magnet = f'magnet:?xt=urn:btih:{"A" * 40}&dn=AwesomeTorrent'
download = await fake_dlmgr.start_download_from_uri(magnet)
assert download.tdef.get_name() == b'AwesomeTorrent'


def test_update_trackers(fake_dlmgr) -> None:
fake_download, _ = create_fake_download_and_state()
fake_dlmgr.downloads[fake_download.infohash] = fake_download
Expand Down

0 comments on commit 49d94dc

Please sign in to comment.