Handle magnet links in torrent parsing and downloader modules (#4815)

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: jxxghp <jxxghp@live.cn>
This commit is contained in:
jxxghp
2025-08-23 10:51:32 +08:00
committed by GitHub
parent cd8f7e72e0
commit 4699f511bf
3 changed files with 31 additions and 2 deletions

View File

@@ -125,6 +125,14 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
else:
torrent_content = content
# 检查是否为磁力链接
if isinstance(torrent_content, str) and torrent_content.startswith("magnet:"):
# 磁力链接不需要解析种子文件
return None, torrent_content
elif isinstance(torrent_content, bytes) and torrent_content.startswith(b"magnet:"):
# 磁力链接不需要解析种子文件
return None, torrent_content
if torrent_content:
torrent_info = Torrent.from_string(torrent_content)
@@ -138,7 +146,9 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
# 读取种子的名称
torrent, content = __get_torrent_info()
if not torrent:
# 检查是否为磁力链接
is_magnet = isinstance(content, str) and content.startswith("magnet:") or isinstance(content, bytes) and content.startswith(b"magnet:")
if not torrent and not is_magnet:
return None, None, None, f"添加种子任务失败:无法读取种子文件"
# 获取下载器

View File

@@ -126,6 +126,14 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
else:
torrent_content = content
# 检查是否为磁力链接
if isinstance(torrent_content, str) and torrent_content.startswith("magnet:"):
# 磁力链接不需要解析种子文件
return None, torrent_content
elif isinstance(torrent_content, bytes) and torrent_content.startswith(b"magnet:"):
# 磁力链接不需要解析种子文件
return None, torrent_content
if torrent_content:
torrent_info = Torrent.from_string(torrent_content)
@@ -139,7 +147,9 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
# 读取种子的名称
torrent, content = __get_torrent_info()
if not torrent:
# 检查是否为磁力链接
is_magnet = isinstance(content, str) and content.startswith("magnet:") or isinstance(content, bytes) and content.startswith(b"magnet:")
if not torrent and not is_magnet:
return None, None, None, f"添加种子任务失败:无法读取种子文件"
# 获取下载器