From 02111a3b9f241155735f28a8dbbf2ca694b60493 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 28 Sep 2023 16:23:10 +0800 Subject: [PATCH] fix #684 --- app/modules/emby/__init__.py | 2 +- app/modules/emby/emby.py | 7 +++++++ app/modules/jellyfin/__init__.py | 3 +-- app/modules/jellyfin/jellyfin.py | 7 +++++++ app/modules/plex/__init__.py | 2 +- app/modules/plex/plex.py | 11 +++++++++++ app/modules/qbittorrent/__init__.py | 2 +- app/modules/qbittorrent/qbittorrent.py | 6 ++++++ app/modules/transmission/__init__.py | 2 +- app/modules/transmission/transmission.py | 6 ++++++ 10 files changed, 42 insertions(+), 6 deletions(-) diff --git a/app/modules/emby/__init__.py b/app/modules/emby/__init__.py index 7ae34ab0..1d160ef1 100644 --- a/app/modules/emby/__init__.py +++ b/app/modules/emby/__init__.py @@ -28,7 +28,7 @@ class EmbyModule(_ModuleBase): """ # 定时重连 if not self.emby.is_inactive(): - self.emby = Emby() + self.emby.reconnect() def user_authenticate(self, name: str, password: str) -> Optional[str]: """ diff --git a/app/modules/emby/emby.py b/app/modules/emby/emby.py index 5873097d..ad5a472e 100644 --- a/app/modules/emby/emby.py +++ b/app/modules/emby/emby.py @@ -35,6 +35,13 @@ class Emby(metaclass=Singleton): return False return True if not self.user else False + def reconnect(self): + """ + 重连 + """ + self.user = self.get_user() + self.folders = self.get_emby_folders() + def get_emby_folders(self) -> List[dict]: """ 获取Emby媒体库路径列表 diff --git a/app/modules/jellyfin/__init__.py b/app/modules/jellyfin/__init__.py index d11c04c7..ff5716b5 100644 --- a/app/modules/jellyfin/__init__.py +++ b/app/modules/jellyfin/__init__.py @@ -1,4 +1,3 @@ -import json from pathlib import Path from typing import Optional, Tuple, Union, Any, List, Generator @@ -26,7 +25,7 @@ class JellyfinModule(_ModuleBase): """ # 定时重连 if not self.jellyfin.is_inactive(): - self.jellyfin = Jellyfin() + self.jellyfin.reconnect() def stop(self): pass diff --git a/app/modules/jellyfin/jellyfin.py b/app/modules/jellyfin/jellyfin.py index 2c684fa6..21898817 100644 --- a/app/modules/jellyfin/jellyfin.py +++ b/app/modules/jellyfin/jellyfin.py @@ -33,6 +33,13 @@ class Jellyfin(metaclass=Singleton): return False return True if not self.user else False + def reconnect(self): + """ + 重连 + """ + self.user = self.get_user() + self.serverid = self.get_server_id() + def __get_jellyfin_librarys(self) -> List[dict]: """ 获取Jellyfin媒体库的信息 diff --git a/app/modules/plex/__init__.py b/app/modules/plex/__init__.py index 0cb1aa45..76fe555f 100644 --- a/app/modules/plex/__init__.py +++ b/app/modules/plex/__init__.py @@ -29,7 +29,7 @@ class PlexModule(_ModuleBase): """ # 定时重连 if not self.plex.is_inactive(): - self.plex = Plex() + self.plex.reconnect() def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[WebhookEventInfo]: """ diff --git a/app/modules/plex/plex.py b/app/modules/plex/plex.py index c9815102..4b1217fd 100644 --- a/app/modules/plex/plex.py +++ b/app/modules/plex/plex.py @@ -38,6 +38,17 @@ class Plex(metaclass=Singleton): return False return True if not self._plex else False + def reconnect(self): + """ + 重连 + """ + try: + self._plex = PlexServer(self._host, self._token) + self._libraries = self._plex.library.sections() + except Exception as e: + self._plex = None + logger.error(f"Plex服务器连接失败:{str(e)}") + def get_librarys(self): """ 获取媒体服务器所有媒体库列表 diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index 698b85e5..e81fc32a 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -34,7 +34,7 @@ class QbittorrentModule(_ModuleBase): """ # 定时重连 if self.qbittorrent.is_inactive(): - self.qbittorrent = Qbittorrent() + self.qbittorrent.reconnect() def download(self, content: Union[Path, str], download_dir: Path, cookie: str, episodes: Set[int] = None, category: str = None) -> Optional[Tuple[Optional[str], str]]: diff --git a/app/modules/qbittorrent/qbittorrent.py b/app/modules/qbittorrent/qbittorrent.py index 072c0a87..b03abef8 100644 --- a/app/modules/qbittorrent/qbittorrent.py +++ b/app/modules/qbittorrent/qbittorrent.py @@ -35,6 +35,12 @@ class Qbittorrent(metaclass=Singleton): return False return True if not self.qbc else False + def reconnect(self): + """ + 重连 + """ + self.qbc = self.__login_qbittorrent() + def __login_qbittorrent(self) -> Optional[Client]: """ 连接qbittorrent diff --git a/app/modules/transmission/__init__.py b/app/modules/transmission/__init__.py index 78eb6456..cfde6a01 100644 --- a/app/modules/transmission/__init__.py +++ b/app/modules/transmission/__init__.py @@ -34,7 +34,7 @@ class TransmissionModule(_ModuleBase): """ # 定时重连 if not self.transmission.is_inactive(): - self.transmission = Transmission() + self.transmission.reconnect() def download(self, content: Union[Path, str], download_dir: Path, cookie: str, episodes: Set[int] = None, category: str = None) -> Optional[Tuple[Optional[str], str]]: diff --git a/app/modules/transmission/transmission.py b/app/modules/transmission/transmission.py index 81370509..c0ae409e 100644 --- a/app/modules/transmission/transmission.py +++ b/app/modules/transmission/transmission.py @@ -56,6 +56,12 @@ class Transmission(metaclass=Singleton): return False return True if not self.trc else False + def reconnect(self): + """ + 重连 + """ + self.trc = self.__login_transmission() + def get_torrents(self, ids: Union[str, list] = None, status: Union[str, list] = None, tags: Union[str, list] = None) -> Tuple[List[Torrent], bool]: """