This commit is contained in:
jxxghp
2023-06-10 19:22:40 +08:00
parent 548317980f
commit 99bd8aade3
17 changed files with 92 additions and 55 deletions

View File

@ -42,21 +42,23 @@ class TheMovieDb(_ModuleBase):
pass
def recognize_media(self, meta: MetaBase,
tmdbid: str = None) -> Optional[MediaInfo]:
mtype: MediaType = None,
tmdbid: int = None) -> Optional[MediaInfo]:
"""
识别媒体信息
:param meta: 识别的元数据
:param mtype: 识别的媒体类型与tmdbid配套
:param tmdbid: tmdbid
:return: 识别的媒体信息,包括剧集信息
"""
if not meta:
return None
cache_info = self.cache.get(meta)
if not cache_info:
if not cache_info or cache_info.get('id') == 0:
# 缓存没有或者强制不使用缓存
if tmdbid:
# 直接查询详情
info = self.tmdb.get_info(mtype=meta.type, tmdbid=tmdbid)
info = self.tmdb.get_info(mtype=mtype, tmdbid=tmdbid)
else:
if meta.type != MediaType.TV and not meta.year:
info = self.tmdb.search_multi(meta.get_name())

View File

@ -1,3 +1,4 @@
import traceback
from functools import lru_cache
from typing import Optional, Tuple, List
@ -114,7 +115,7 @@ class TmdbHelper:
return True
return False
def __get_names(self, mtype: MediaType, tmdb_id: str) -> Tuple[Optional[dict], List[str]]:
def __get_names(self, mtype: MediaType, tmdb_id: int) -> Tuple[Optional[dict], List[str]]:
"""
搜索tmdb中所有的标题和译名用于名称匹配
:param mtype: 类型:电影、电视剧、动漫
@ -230,7 +231,8 @@ class TmdbHelper:
logger.error(f"连接TMDB出错{err}")
return None
except Exception as e:
logger.error(f"连接TMDB出错{str(e)}")
logger.error(f"连接TMDB出错{e}")
print(traceback.print_exc())
return None
logger.debug(f"API返回{str(self.search.total_results)}")
if len(movies) == 0:
@ -289,7 +291,8 @@ class TmdbHelper:
logger.error(f"连接TMDB出错{err}")
return None
except Exception as e:
logger.error(f"连接TMDB出错{str(e)}")
logger.error(f"连接TMDB出错{e}")
print(traceback.print_exc())
return None
logger.debug(f"API返回{str(self.search.total_results)}")
if len(tvs) == 0:
@ -346,13 +349,14 @@ class TmdbHelper:
return False
try:
seasons = self.__get_tv_seasons(tv_info)
for season, season_info in seasons.values():
for season, season_info in seasons.items():
if season_info.get("air_date"):
if season.get("air_date")[0:4] == str(_season_year) \
and season == int(season_number):
return True
except Exception as e1:
logger.error(f"连接TMDB出错{e1}")
print(traceback.print_exc())
return False
return False
@ -363,6 +367,7 @@ class TmdbHelper:
return None
except Exception as e:
logger.error(f"连接TMDB出错{e}")
print(traceback.print_exc())
return None
if len(tvs) == 0:
@ -433,7 +438,8 @@ class TmdbHelper:
logger.error(f"连接TMDB出错{err}")
return None
except Exception as e:
logger.error(f"连接TMDB出错{str(e)}")
logger.error(f"连接TMDB出错{e}")
print(traceback.print_exc())
return None
logger.debug(f"API返回{str(self.search.total_results)}")
if len(multis) == 0:
@ -529,7 +535,7 @@ class TmdbHelper:
def get_info(self,
mtype: MediaType,
tmdbid: str) -> dict:
tmdbid: int) -> dict:
"""
给定TMDB号查询一条媒体信息
:param mtype: 类型:电影、电视剧、动漫,为空时都查(此时用不上年份)
@ -602,7 +608,7 @@ class TmdbHelper:
tmdb_info['name'] = cn_title
def __get_movie_detail(self,
tmdbid: str,
tmdbid: int,
append_to_response: str = "images,"
"credits,"
"alternative_titles,"
@ -714,7 +720,7 @@ class TmdbHelper:
return None
def __get_tv_detail(self,
tmdbid: str,
tmdbid: int,
append_to_response: str = "images,"
"credits,"
"alternative_titles,"
@ -896,7 +902,7 @@ class TmdbHelper:
print(str(e))
return None
def get_tv_season_detail(self, tmdbid, season: int):
def get_tv_season_detail(self, tmdbid: int, season: int):
"""
获取电视剧季的详情
:param tmdbid: TMDB ID
@ -970,7 +976,7 @@ class TmdbHelper:
print(str(e))
return {}
def get_tv_episode_detail(self, tmdbid: str, season: int, episode: int):
def get_tv_episode_detail(self, tmdbid: int, season: int, episode: int):
"""
获取电视剧集的详情
:param tmdbid: TMDB ID

View File

@ -75,12 +75,12 @@ class TmdbCache(metaclass=Singleton):
with lock:
return self._meta_data.pop(key, None)
def delete_by_tmdbid(self, tmdbid: str) -> None:
def delete_by_tmdbid(self, tmdbid: int) -> None:
"""
清空对应TMDBID的所有缓存记录以强制更新TMDB中最新的数据
"""
for key in list(self._meta_data):
if str(self._meta_data.get(key, {}).get("id")) == str(tmdbid):
if self._meta_data.get(key, {}).get("id") == tmdbid:
with lock:
self._meta_data.pop(key)
@ -89,7 +89,7 @@ class TmdbCache(metaclass=Singleton):
清除未识别的缓存记录以便重新搜索TMDB
"""
for key in list(self._meta_data):
if str(self._meta_data.get(key, {}).get("id")) == '0':
if self._meta_data.get(key, {}).get("id") == 0:
with lock:
self._meta_data.pop(key)