From 1e4f3e97cd995f241da86659cf578305ea57828b Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 19 Oct 2024 18:17:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor=EF=BC=9Amedia=5Fexists=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8C=87=E5=AE=9A=E6=9C=8D=E5=8A=A1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/__init__.py | 6 ++++-- app/modules/emby/__init__.py | 12 ++++++++++-- app/modules/jellyfin/__init__.py | 12 ++++++++++-- app/modules/plex/__init__.py | 12 ++++++++++-- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 7c38a3c6f..e41c6e49d 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -450,14 +450,16 @@ def torrent_files(self, tid: str, """ return self.run_module("torrent_files", tid=tid, downloader=downloader) - def media_exists(self, mediainfo: MediaInfo, itemid: str = None) -> Optional[ExistMediaInfo]: + def media_exists(self, mediainfo: MediaInfo, itemid: str = None, + server: str = None) -> Optional[ExistMediaInfo]: """ 判断媒体文件是否存在 :param mediainfo: 识别的媒体信息 :param itemid: 媒体服务器ItemID + :param server: 媒体服务器 :return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}} """ - return self.run_module("media_exists", mediainfo=mediainfo, itemid=itemid) + return self.run_module("media_exists", mediainfo=mediainfo, itemid=itemid, server=server) def media_files(self, mediainfo: MediaInfo) -> Optional[List[FileItem]]: """ diff --git a/app/modules/emby/__init__.py b/app/modules/emby/__init__.py index 5953e8e87..da0e9d857 100644 --- a/app/modules/emby/__init__.py +++ b/app/modules/emby/__init__.py @@ -101,14 +101,22 @@ def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[schemas.We return result return None - def media_exists(self, mediainfo: MediaInfo, itemid: str = None) -> Optional[schemas.ExistMediaInfo]: + def media_exists(self, mediainfo: MediaInfo, itemid: str = None, + server: str = None) -> Optional[schemas.ExistMediaInfo]: """ 判断媒体文件是否存在 :param mediainfo: 识别的媒体信息 :param itemid: 媒体服务器ItemID + :param server: 媒体服务器名称 :return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}} """ - for name, server in self.get_instances().items(): + if server: + servers = [(server, self.get_instance(server))] + else: + servers = self.get_instances().items() + for name, server in servers: + if not server: + continue if mediainfo.type == MediaType.MOVIE: if itemid: movie = server.get_iteminfo(itemid) diff --git a/app/modules/jellyfin/__init__.py b/app/modules/jellyfin/__init__.py index cdcb45a04..0ceb33672 100644 --- a/app/modules/jellyfin/__init__.py +++ b/app/modules/jellyfin/__init__.py @@ -101,14 +101,22 @@ def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[schemas.We return result return None - def media_exists(self, mediainfo: MediaInfo, itemid: str = None) -> Optional[schemas.ExistMediaInfo]: + def media_exists(self, mediainfo: MediaInfo, itemid: str = None, + server: str = None) -> Optional[schemas.ExistMediaInfo]: """ 判断媒体文件是否存在 :param mediainfo: 识别的媒体信息 :param itemid: 媒体服务器ItemID + :param server: 媒体服务器名称 :return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}} """ - for name, server in self.get_instances().items(): + if server: + servers = [(server, self.get_instance(server))] + else: + servers = self.get_instances().items() + for name, server in servers: + if not server: + continue if mediainfo.type == MediaType.MOVIE: if itemid: movie = server.get_iteminfo(itemid) diff --git a/app/modules/plex/__init__.py b/app/modules/plex/__init__.py index 381de1a25..61d9d4751 100644 --- a/app/modules/plex/__init__.py +++ b/app/modules/plex/__init__.py @@ -82,14 +82,22 @@ def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[schemas.We return result return None - def media_exists(self, mediainfo: MediaInfo, itemid: str = None) -> Optional[schemas.ExistMediaInfo]: + def media_exists(self, mediainfo: MediaInfo, itemid: str = None, + server: str = None) -> Optional[schemas.ExistMediaInfo]: """ 判断媒体文件是否存在 :param mediainfo: 识别的媒体信息 :param itemid: 媒体服务器ItemID + :param server: 媒体服务器名称 :return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}} """ - for name, server in self.get_instances().items(): + if server: + servers = [(server, self.get_instance(server))] + else: + servers = self.get_instances().items() + for name, server in servers: + if not server: + continue if mediainfo.type == MediaType.MOVIE: if itemid: movie = server.get_iteminfo(itemid)