Merge remote-tracking branch 'origin/main'

This commit is contained in:
jxxghp 2023-11-30 08:16:30 +08:00
commit 6835c38c24
3 changed files with 24 additions and 11 deletions

View File

@ -20,10 +20,16 @@ class Qbittorrent(metaclass=Singleton):
qbc: Client = None
def __init__(self):
self._host, self._port = StringUtils.get_domain_address(address=settings.QB_HOST, prefix=True)
self._username = settings.QB_USER
self._password = settings.QB_PASSWORD
def __init__(self, host: str = None, port: int = None, username: str = None, password: str = None):
"""
若不设置参数则创建配置文件设置的下载器
"""
if host and port:
self._host, self._port = host, port
else:
self._host, self._port = StringUtils.get_domain_address(address=settings.QB_HOST, prefix=True)
self._username = username if username else settings.QB_USER
self._password = password if password else settings.QB_PASSWORD
if self._host and self._port:
self.qbc = self.__login_qbittorrent()

View File

@ -24,10 +24,16 @@ class Transmission(metaclass=Singleton):
"peersGettingFromUs", "peersSendingToUs", "uploadRatio", "uploadedEver", "downloadedEver", "downloadDir",
"error", "errorString", "doneDate", "queuePosition", "activityDate", "trackers"]
def __init__(self):
self._host, self._port = StringUtils.get_domain_address(address=settings.TR_HOST, prefix=False)
self._username = settings.TR_USER
self._password = settings.TR_PASSWORD
def __init__(self, host: str = None, port: int = None, username: str = None, password: str = None):
"""
若不设置参数则创建配置文件设置的下载器
"""
if host and port:
self._host, self._port = host, port
else:
self._host, self._port = StringUtils.get_domain_address(address=settings.TR_HOST, prefix=False)
self._username = username if username else settings.TR_USER
self._password = password if password else settings.TR_PASSWORD
if self._host and self._port:
self.trc = self.__login_transmission()

View File

@ -9,9 +9,10 @@ class Singleton(abc.ABCMeta, type):
_instances: dict = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
key = (cls, args, frozenset(kwargs.items()))
if key not in cls._instances:
cls._instances[key] = super().__call__(*args, **kwargs)
return cls._instances[key]
class AbstractSingleton(abc.ABC, metaclass=Singleton):