mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
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:
co-authored by
Cursor Agent
jxxghp
parent
cd8f7e72e0
commit
4699f511bf
@@ -201,6 +201,15 @@ class TorrentHelper(metaclass=WeakSingleton):
|
|||||||
"""
|
"""
|
||||||
if not torrent_content:
|
if not torrent_content:
|
||||||
return "", []
|
return "", []
|
||||||
|
|
||||||
|
# 检查是否为磁力链接
|
||||||
|
if isinstance(torrent_content, str) and torrent_content.startswith("magnet:"):
|
||||||
|
# 磁力链接无法预先获取文件信息,返回空
|
||||||
|
return "", []
|
||||||
|
elif isinstance(torrent_content, bytes) and torrent_content.startswith(b"magnet:"):
|
||||||
|
# 磁力链接无法预先获取文件信息,返回空
|
||||||
|
return "", []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 解析种子内容
|
# 解析种子内容
|
||||||
torrentinfo = Torrent.from_string(torrent_content)
|
torrentinfo = Torrent.from_string(torrent_content)
|
||||||
|
|||||||
@@ -125,6 +125,14 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
|
|||||||
else:
|
else:
|
||||||
torrent_content = content
|
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:
|
if torrent_content:
|
||||||
torrent_info = Torrent.from_string(torrent_content)
|
torrent_info = Torrent.from_string(torrent_content)
|
||||||
|
|
||||||
@@ -138,7 +146,9 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
|
|||||||
|
|
||||||
# 读取种子的名称
|
# 读取种子的名称
|
||||||
torrent, content = __get_torrent_info()
|
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"添加种子任务失败:无法读取种子文件"
|
return None, None, None, f"添加种子任务失败:无法读取种子文件"
|
||||||
|
|
||||||
# 获取下载器
|
# 获取下载器
|
||||||
|
|||||||
@@ -126,6 +126,14 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
|
|||||||
else:
|
else:
|
||||||
torrent_content = content
|
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:
|
if torrent_content:
|
||||||
torrent_info = Torrent.from_string(torrent_content)
|
torrent_info = Torrent.from_string(torrent_content)
|
||||||
|
|
||||||
@@ -139,7 +147,9 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
|
|||||||
|
|
||||||
# 读取种子的名称
|
# 读取种子的名称
|
||||||
torrent, content = __get_torrent_info()
|
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"添加种子任务失败:无法读取种子文件"
|
return None, None, None, f"添加种子任务失败:无法读取种子文件"
|
||||||
|
|
||||||
# 获取下载器
|
# 获取下载器
|
||||||
|
|||||||
Reference in New Issue
Block a user