From ba27d02854951f36c8f796cdb8fb8c92d2474603 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 30 Sep 2023 20:40:48 +0800 Subject: [PATCH] fix --- app/modules/emby/__init__.py | 2 +- app/modules/emby/emby.py | 12 +++++++-- app/modules/jellyfin/__init__.py | 2 +- app/modules/jellyfin/jellyfin.py | 6 +++-- app/modules/plex/__init__.py | 2 +- app/modules/plex/plex.py | 43 ++++++++++++++++++++++---------- 6 files changed, 47 insertions(+), 20 deletions(-) diff --git a/app/modules/emby/__init__.py b/app/modules/emby/__init__.py index 3a3d0c9c..40188421 100644 --- a/app/modules/emby/__init__.py +++ b/app/modules/emby/__init__.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Optional, Tuple, Union, Any, List, Generator +from typing import Optional, Tuple, Union, Any, List from app import schemas from app.core.context import MediaInfo diff --git a/app/modules/emby/emby.py b/app/modules/emby/emby.py index 68ce28a7..8e6b3370 100644 --- a/app/modules/emby/emby.py +++ b/app/modules/emby/emby.py @@ -235,7 +235,15 @@ class Emby(metaclass=Singleton): """ if not self._host or not self._apikey: return None - req_url = "%semby/Items?IncludeItemTypes=Series&Fields=ProductionYear&StartIndex=0&Recursive=true&SearchTerm=%s&Limit=10&IncludeSearchTypes=false&api_key=%s" % ( + req_url = ("%semby/Items?" + "IncludeItemTypes=Series" + "&Fields=ProductionYear" + "&StartIndex=0" + "&Recursive=true" + "&SearchTerm=%s" + "&Limit=10" + "&IncludeSearchTypes=false" + "&api_key=%s") % ( self._host, name, self._apikey) try: res = RequestUtils().get_res(req_url) @@ -334,7 +342,7 @@ class Emby(metaclass=Singleton): if tmdb_id and item_info.tmdbid: if str(tmdb_id) != str(item_info.tmdbid): return None, {} - # /Shows/Id/Episodes 查集的信息 + # 查集的信息 if not season: season = "" try: diff --git a/app/modules/jellyfin/__init__.py b/app/modules/jellyfin/__init__.py index db5c53c3..ecd0f530 100644 --- a/app/modules/jellyfin/__init__.py +++ b/app/modules/jellyfin/__init__.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Optional, Tuple, Union, Any, List, Generator +from typing import Optional, Tuple, Union, Any, List from app import schemas from app.core.context import MediaInfo diff --git a/app/modules/jellyfin/jellyfin.py b/app/modules/jellyfin/jellyfin.py index 2bd326ee..d6a7745c 100644 --- a/app/modules/jellyfin/jellyfin.py +++ b/app/modules/jellyfin/jellyfin.py @@ -210,7 +210,8 @@ class Jellyfin(metaclass=Singleton): """ if not self._host or not self._apikey or not self.user: return None - req_url = "%sUsers/%s/Items?api_key=%s&searchTerm=%s&IncludeItemTypes=Series&Limit=10&Recursive=true" % ( + req_url = ("%sUsers/%s/Items?" + "api_key=%s&searchTerm=%s&IncludeItemTypes=Series&Limit=10&Recursive=true") % ( self._host, self.user, self._apikey, name) try: res = RequestUtils().get_res(req_url) @@ -239,7 +240,8 @@ class Jellyfin(metaclass=Singleton): """ if not self._host or not self._apikey or not self.user: return None - req_url = "%sUsers/%s/Items?api_key=%s&searchTerm=%s&IncludeItemTypes=Movie&Limit=10&Recursive=true" % ( + req_url = ("%sUsers/%s/Items?" + "api_key=%s&searchTerm=%s&IncludeItemTypes=Movie&Limit=10&Recursive=true") % ( self._host, self.user, self._apikey, title) try: res = RequestUtils().get_res(req_url) diff --git a/app/modules/plex/__init__.py b/app/modules/plex/__init__.py index af0ad7f9..115862db 100644 --- a/app/modules/plex/__init__.py +++ b/app/modules/plex/__init__.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Optional, Tuple, Union, Any, List, Generator +from typing import Optional, Tuple, Union, Any, List from app import schemas from app.core.context import MediaInfo diff --git a/app/modules/plex/plex.py b/app/modules/plex/plex.py index 6aedb3ac..227f6231 100644 --- a/app/modules/plex/plex.py +++ b/app/modules/plex/plex.py @@ -118,14 +118,20 @@ class Plex(metaclass=Singleton): return None ret_movies = [] if year: - movies = self._plex.library.search(title=title, year=year, libtype="movie") + movies = self._plex.library.search(title=title, + year=year, + libtype="movie") # 根据原标题再查一遍 if original_title and str(original_title) != str(title): - movies.extend(self._plex.library.search(title=original_title, year=year, libtype="movie")) + movies.extend(self._plex.library.search(title=original_title, + year=year, + libtype="movie")) else: - movies = self._plex.library.search(title=title, libtype="movie") + movies = self._plex.library.search(title=title, + libtype="movie") if original_title and str(original_title) != str(title): - movies.extend(self._plex.library.search(title=original_title, libtype="movie")) + movies.extend(self._plex.library.search(title=original_title, + libtype="movie")) for item in set(movies): ids = self.__get_ids(item.guids) if tmdb_id and ids['tmdb_id']: @@ -174,9 +180,15 @@ class Plex(metaclass=Singleton): videos = self._plex.fetchItem(item_id) else: # 根据标题和年份模糊搜索,该结果不够准确 - videos = self._plex.library.search(title=title, year=year, libtype="show") - if not videos and original_title and str(original_title) != str(title): - videos = self._plex.library.search(title=original_title, year=year, libtype="show") + videos = self._plex.library.search(title=title, + year=year, + libtype="show") + if (not videos + and original_title + and str(original_title) != str(title)): + videos = self._plex.library.search(title=original_title, + year=year, + libtype="show") if not videos: return None, {} if isinstance(videos, list): @@ -206,9 +218,11 @@ class Plex(metaclass=Singleton): return None try: if image_type == "Poster": - images = self._plex.fetchItems('/library/metadata/%s/posters' % item_id, cls=media.Poster) + images = self._plex.fetchItems('/library/metadata/%s/posters' % item_id, + cls=media.Poster) else: - images = self._plex.fetchItems('/library/metadata/%s/arts' % item_id, cls=media.Art) + images = self._plex.fetchItems('/library/metadata/%s/arts' % item_id, + cls=media.Art) for image in images: if hasattr(image, 'key') and image.key.startswith('http'): return image.key @@ -410,7 +424,7 @@ class Plex(metaclass=Singleton): "parentTitle": "Combat Shadow Fighting Saga / Great Prison Battle Saga", "originalTitle": "Baki Hanma", "contentRating": "TV-MA", - "summary": "The world is shaken by news of a man taking down a monstrous elephant with his bare hands. Back in Japan, Baki is confronted by a knife-wielding child.", + "summary": "The world is shaken by news", "index": 1, "parentIndex": 1, "audienceRating": 8.5, @@ -492,14 +506,17 @@ class Plex(metaclass=Singleton): eventItem.season_id = message.get('Metadata', {}).get('parentIndex') eventItem.episode_id = message.get('Metadata', {}).get('index') - if message.get('Metadata', {}).get('summary') and len(message.get('Metadata', {}).get('summary')) > 100: + if (message.get('Metadata', {}).get('summary') + and len(message.get('Metadata', {}).get('summary')) > 100): eventItem.overview = str(message.get('Metadata', {}).get('summary'))[:100] + "..." else: eventItem.overview = message.get('Metadata', {}).get('summary') else: - eventItem.item_type = "MOV" if message.get('Metadata', {}).get('type') == 'movie' else "SHOW" + eventItem.item_type = "MOV" if message.get('Metadata', + {}).get('type') == 'movie' else "SHOW" eventItem.item_name = "%s %s" % ( - message.get('Metadata', {}).get('title'), "(" + str(message.get('Metadata', {}).get('year')) + ")") + message.get('Metadata', {}).get('title'), + "(" + str(message.get('Metadata', {}).get('year')) + ")") eventItem.item_id = message.get('Metadata', {}).get('ratingKey') if len(message.get('Metadata', {}).get('summary')) > 100: eventItem.overview = str(message.get('Metadata', {}).get('summary'))[:100] + "..."