From 6e334ef3332be2534f867f0c34f89f5f7d914c8a Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 16 Aug 2024 17:03:51 +0800 Subject: [PATCH] fix apis --- app/modules/emby/__init__.py | 2 +- app/modules/qbittorrent/__init__.py | 4 ++-- app/modules/qbittorrent/qbittorrent.py | 24 ++++++++++++++---------- app/modules/transmission/transmission.py | 16 ++++++---------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/modules/emby/__init__.py b/app/modules/emby/__init__.py index f73189b4..26fe89a4 100644 --- a/app/modules/emby/__init__.py +++ b/app/modules/emby/__init__.py @@ -154,7 +154,7 @@ class EmbyModule(_ModuleBase, _MediaServerBase): media_statistics = [] for server in servers: media_statistic = server.get_medias_count() - if not media_statistics: + if not media_statistic: continue media_statistic.user_count = server.get_user_count() media_statistics.append(media_statistic) diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index 111e28c4..20046e0b 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -176,14 +176,14 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase): # 选择文件 server.set_files(torrent_hash=torrent_hash, file_ids=file_ids, priority=0) # 开始任务 - if settings.QB_FORCE_RESUME: + if server.is_force_resume(): # 强制继续 server.torrents_set_force_start(torrent_hash) else: server.start_torrents(torrent_hash) return downloader or self._default_server, torrent_hash, f"添加下载成功,已选择集数:{sucess_epidised}" else: - if settings.QB_FORCE_RESUME: + if server.is_force_resume(): server.torrents_set_force_start(torrent_hash) return downloader or self._default_server, torrent_hash, "添加下载成功" diff --git a/app/modules/qbittorrent/qbittorrent.py b/app/modules/qbittorrent/qbittorrent.py index b46d4837..18581a49 100644 --- a/app/modules/qbittorrent/qbittorrent.py +++ b/app/modules/qbittorrent/qbittorrent.py @@ -7,6 +7,7 @@ from qbittorrentapi.client import Client from qbittorrentapi.transfer import TransferInfoDictionary from app.log import logger +from app.utils.string import StringUtils class Qbittorrent: @@ -27,18 +28,13 @@ class Qbittorrent: """ 若不设置参数,则创建配置文件设置的下载器 """ - if not host: + if host and port: + self._host, self._port = host, port + elif host: + self._host, self._port = StringUtils.get_domain_address(address=host, prefix=True) + else: logger.error("Qbittorrent配置不完整!") return - self._host = host - if not port: - # 从host中获取端口 - if ":" in host: - host, port = host.split(":") - self._host = host - self._port = int(port) - else: - self._port = port self._username = username self._password = password self._category = category @@ -176,12 +172,20 @@ class Qbittorrent: except Exception as err: logger.error(f"设置种子Tag出错:{str(err)}") + def is_force_resume(self) -> bool: + """ + 是否支持强制作种 + """ + return self._force_resume + def torrents_set_force_start(self, ids: Union[str, list]): """ 设置强制作种 """ if not self.qbc: return + if not self._force_resume: + return try: self.qbc.torrents_set_force_start(enable=True, torrent_hashes=ids) except Exception as err: diff --git a/app/modules/transmission/transmission.py b/app/modules/transmission/transmission.py index ee1f12bc..68bb91e7 100644 --- a/app/modules/transmission/transmission.py +++ b/app/modules/transmission/transmission.py @@ -5,6 +5,7 @@ from transmission_rpc import Client, Torrent, File from transmission_rpc.session import SessionStats, Session from app.log import logger +from app.utils.string import StringUtils class Transmission: @@ -26,18 +27,13 @@ class Transmission: """ 若不设置参数,则创建配置文件设置的下载器 """ - if not host: + if host and port: + self._host, self._port = host, port + elif host: + self._host, self._port = StringUtils.get_domain_address(address=host, prefix=False) + else: logger.error("Transmission配置不完整!") return - self._host = host - if not port: - # 从host中获取端口 - if ":" in host: - host, port = host.split(":") - self._host = host - self._port = int(port) - else: - self._port = port self._username = username self._password = password if self._host and self._port: