diff --git a/src/module/core/download_client.py b/src/module/core/download_client.py index 94297bfd..236f2cc9 100644 --- a/src/module/core/download_client.py +++ b/src/module/core/download_client.py @@ -13,6 +13,10 @@ class DownloadClient: def __init__(self): self.client = getClient() + def auth(self): + host, username, password = settings.downloader.host, settings.downloader.username, settings.downloader.password + self.client.auth(host, username, password) + def init_downloader(self): prefs = { "rss_auto_downloading_enabled": True, diff --git a/src/module/downloader/__init__.py b/src/module/downloader/__init__.py index 2dd7a157..527d6a40 100644 --- a/src/module/downloader/__init__.py +++ b/src/module/downloader/__init__.py @@ -1,11 +1,5 @@ -from module.conf import settings - - def getClient(): - host = settings.downloader.host - username = settings.downloader.username - password = settings.downloader.password # TODO 多下载器支持 # 从 settings 里读取下载器名称,然后返回对应 Client from .qb_downloader import QbDownloader - return QbDownloader(host, username, password) + return QbDownloader() diff --git a/src/module/downloader/qb_downloader.py b/src/module/downloader/qb_downloader.py index 4170dfb5..64e8b643 100644 --- a/src/module/downloader/qb_downloader.py +++ b/src/module/downloader/qb_downloader.py @@ -7,27 +7,30 @@ from qbittorrentapi.exceptions import Conflict409Error from module.conf import settings from module.ab_decorator import qb_connect_failed_wait -from .exceptions import ConflictError +from module.downloader.exceptions import ConflictError logger = logging.getLogger(__name__) class QbDownloader: @qb_connect_failed_wait - def __init__(self, host, username, password): + def __init__(self): + self._client: Client | None = None + + @qb_connect_failed_wait + def auth(self, host, username, password): self._client = Client( host=host, username=username, password=password, - VERIFY_WEBUI_CERTIFICATE=settings.downloader.ssl, - RAISE_ERROR_FOR_UNSUPPORTED_QBITTORRENT_VERSIONS=True, + VERIFY_WEBUI_CERTIFICATE=settings.downloader.ssl ) while True: try: self._client.auth_log_in() break except LoginFailed: - logger.debug( + logger.warning( f"Can't login qBittorrent Server {host} by {username}, retry in {5} seconds." ) time.sleep(5)