fix: retry qbittorrent files after add

This commit is contained in:
jxxghp
2026-07-05 17:15:07 +08:00
parent b231ad415f
commit 132f27c1c6
3 changed files with 94 additions and 8 deletions
+20 -2
View File
@@ -37,9 +37,14 @@ _QBITTORRENT_PAUSED_STATES = {
"stoppeddl",
"stoppedup",
}
_TORRENT_FILES_RETRY_TIMES = 5
_TORRENT_FILES_RETRY_INTERVAL = 1
class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
"""
qBittorrent 下载器模块,负责下载任务添加、文件选择和任务管理。
"""
def init_module(self) -> None:
"""
@@ -50,6 +55,9 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
@staticmethod
def get_name() -> str:
"""
获取模块名称
"""
return "Qbittorrent"
@staticmethod
@@ -73,7 +81,10 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
"""
return 1
def stop(self):
def stop(self) -> None:
"""
停止模块
"""
pass
def test(self) -> Optional[Tuple[bool, str]]:
@@ -90,6 +101,9 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
return True, ""
def init_setting(self) -> Tuple[str, Union[str, bool]]:
"""
返回控制模块启用状态的配置项
"""
pass
def scheduler_job(self) -> None:
@@ -221,7 +235,11 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
else:
if is_paused:
# 种子文件
torrent_files = server.get_files(torrent_hash)
torrent_files = server.get_files(
torrent_hash,
retry=_TORRENT_FILES_RETRY_TIMES,
interval=_TORRENT_FILES_RETRY_INTERVAL,
)
if not torrent_files:
return downloader or self.get_default_config_name(), torrent_hash, torrent_layout, "获取种子文件失败,下载任务可能在暂停状态"
+19 -6
View File
@@ -488,17 +488,30 @@ class Qbittorrent:
logger.error(f"删除种子出错:{str(err)}")
return False
def get_files(self, tid: str) -> Optional[TorrentFilesList]:
def get_files(self, tid: str, retry: int = 1, interval: float = 0) -> Optional[TorrentFilesList]:
"""
获取种子文件清单
:param tid: 种子Hash
:param retry: 最多尝试次数
:param interval: 重试间隔,单位秒
:return: 种子文件清单
"""
if not self.qbc:
return None
try:
return self.qbc.torrents_files(torrent_hash=tid)
except Exception as err:
logger.error(f"获取种子文件列表出错:{str(err)}")
return None
last_error = None
retry_times = max(retry, 1)
for index in range(retry_times):
try:
torrent_files = self.qbc.torrents_files(torrent_hash=tid)
if torrent_files:
return torrent_files
except Exception as err:
last_error = err
if index < retry_times - 1 and interval:
time.sleep(interval)
if last_error:
logger.error(f"获取种子文件列表出错:{str(last_error)}")
return None
def set_files(self, **kwargs) -> bool:
"""