mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
Merge pull request #5350 from cddjr/fix_tmdb_cache
This commit is contained in:
@@ -1635,7 +1635,7 @@ class SubscribeChain(ChainBase):
|
|||||||
info = schemas.SubscribeEpisodeInfo()
|
info = schemas.SubscribeEpisodeInfo()
|
||||||
info.title = episode.name
|
info.title = episode.name
|
||||||
info.description = episode.overview
|
info.description = episode.overview
|
||||||
info.backdrop = f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/w500${episode.still_path}"
|
info.backdrop = settings.TMDB_IMAGE_URL(episode.still_path, "w500")
|
||||||
episodes[episode.episode_number] = info
|
episodes[episode.episode_number] = info
|
||||||
elif subscribe.type == MediaType.TV.value:
|
elif subscribe.type == MediaType.TV.value:
|
||||||
# 根据开始结束集计算集信息
|
# 根据开始结束集计算集信息
|
||||||
|
|||||||
@@ -843,6 +843,18 @@ class Settings(BaseSettings, ConfigModel, LogConfigModel):
|
|||||||
rename_format = re.sub(r'/+', '/', rename_format)
|
rename_format = re.sub(r'/+', '/', rename_format)
|
||||||
return rename_format.strip("/")
|
return rename_format.strip("/")
|
||||||
|
|
||||||
|
def TMDB_IMAGE_URL(self, file_path: str, file_size: str = "original") -> str:
|
||||||
|
"""
|
||||||
|
获取TMDB图片网址
|
||||||
|
|
||||||
|
:param file_path: TMDB API返回的xxx_path
|
||||||
|
:param file_size: 图片大小,例如:'original', 'w500' 等
|
||||||
|
:return: 图片的完整URL
|
||||||
|
"""
|
||||||
|
return (
|
||||||
|
f"https://{self.TMDB_IMAGE_DOMAIN}/t/p/{file_size}/{file_path.removeprefix('/')}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# 实例化配置
|
# 实例化配置
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|||||||
+4
-4
@@ -479,11 +479,11 @@ class MediaInfo:
|
|||||||
self.episode_groups = info.pop("episode_groups").get("results") or []
|
self.episode_groups = info.pop("episode_groups").get("results") or []
|
||||||
|
|
||||||
# 海报
|
# 海报
|
||||||
if info.get('poster_path'):
|
if path := info.get('poster_path'):
|
||||||
self.poster_path = f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{info.get('poster_path')}"
|
self.poster_path = settings.TMDB_IMAGE_URL(path)
|
||||||
# 背景
|
# 背景
|
||||||
if info.get('backdrop_path'):
|
if path := info.get('backdrop_path'):
|
||||||
self.backdrop_path = f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{info.get('backdrop_path')}"
|
self.backdrop_path = settings.TMDB_IMAGE_URL(path)
|
||||||
# 导演和演员
|
# 导演和演员
|
||||||
self.directors, self.actors = __directors_actors(info)
|
self.directors, self.actors = __directors_actors(info)
|
||||||
# 别名和译名
|
# 别名和译名
|
||||||
|
|||||||
@@ -867,19 +867,19 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
backdrops = images.get("backdrops")
|
backdrops = images.get("backdrops")
|
||||||
if backdrops:
|
if backdrops:
|
||||||
backdrops = sorted(backdrops, key=lambda x: x.get("vote_average"), reverse=True)
|
backdrops = sorted(backdrops, key=lambda x: x.get("vote_average"), reverse=True)
|
||||||
mediainfo.backdrop_path = backdrops[0].get("file_path")
|
mediainfo.backdrop_path = settings.TMDB_IMAGE_URL(backdrops[0].get("file_path"))
|
||||||
# 标志
|
# 标志
|
||||||
if not mediainfo.logo_path:
|
if not mediainfo.logo_path:
|
||||||
logos = images.get("logos")
|
logos = images.get("logos")
|
||||||
if logos:
|
if logos:
|
||||||
logos = sorted(logos, key=lambda x: x.get("vote_average"), reverse=True)
|
logos = sorted(logos, key=lambda x: x.get("vote_average"), reverse=True)
|
||||||
mediainfo.logo_path = logos[0].get("file_path")
|
mediainfo.logo_path = settings.TMDB_IMAGE_URL(logos[0].get("file_path"))
|
||||||
# 海报
|
# 海报
|
||||||
if not mediainfo.poster_path:
|
if not mediainfo.poster_path:
|
||||||
posters = images.get("posters")
|
posters = images.get("posters")
|
||||||
if posters:
|
if posters:
|
||||||
posters = sorted(posters, key=lambda x: x.get("vote_average"), reverse=True)
|
posters = sorted(posters, key=lambda x: x.get("vote_average"), reverse=True)
|
||||||
mediainfo.poster_path = posters[0].get("file_path")
|
mediainfo.poster_path = settings.TMDB_IMAGE_URL(posters[0].get("file_path"))
|
||||||
return mediainfo
|
return mediainfo
|
||||||
|
|
||||||
def obtain_images(self, mediainfo: MediaInfo) -> Optional[MediaInfo]:
|
def obtain_images(self, mediainfo: MediaInfo) -> Optional[MediaInfo]:
|
||||||
@@ -957,7 +957,7 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
image_path = seasoninfo.get(image_type.value)
|
image_path = seasoninfo.get(image_type.value)
|
||||||
|
|
||||||
if image_path:
|
if image_path:
|
||||||
return f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/{image_prefix}{image_path}"
|
return settings.TMDB_IMAGE_URL(image_path, image_prefix)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def tmdb_movie_similar(self, tmdbid: int) -> List[MediaInfo]:
|
def tmdb_movie_similar(self, tmdbid: int) -> List[MediaInfo]:
|
||||||
|
|||||||
@@ -85,10 +85,10 @@ class TmdbScraper:
|
|||||||
seasoninfo = self.original_tmdb(mediainfo).get_tv_season_detail(mediainfo.tmdb_id, season)
|
seasoninfo = self.original_tmdb(mediainfo).get_tv_season_detail(mediainfo.tmdb_id, season)
|
||||||
if seasoninfo:
|
if seasoninfo:
|
||||||
episodeinfo = self.__get_episode_detail(seasoninfo, episode)
|
episodeinfo = self.__get_episode_detail(seasoninfo, episode)
|
||||||
if episodeinfo and episodeinfo.get("still_path"):
|
if still_path := episodeinfo.get("still_path"):
|
||||||
# TMDB集still图片
|
# TMDB集still图片
|
||||||
still_name = f"{episode}"
|
still_name = f"{episode}"
|
||||||
still_url = f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{episodeinfo.get('still_path')}"
|
still_url = settings.TMDB_IMAGE_URL(still_path)
|
||||||
images[still_name] = still_url
|
images[still_name] = still_url
|
||||||
else:
|
else:
|
||||||
# 季的图片
|
# 季的图片
|
||||||
@@ -115,7 +115,7 @@ class TmdbScraper:
|
|||||||
if _mediainfo:
|
if _mediainfo:
|
||||||
for attr_name, attr_value in _mediainfo.items():
|
for attr_name, attr_value in _mediainfo.items():
|
||||||
if attr_name.endswith("_path") and attr_value is not None:
|
if attr_name.endswith("_path") and attr_value is not None:
|
||||||
image_url = f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{attr_value}"
|
image_url = settings.TMDB_IMAGE_URL(attr_value)
|
||||||
image_name = attr_name.replace("_path", "") + Path(image_url).suffix
|
image_name = attr_name.replace("_path", "") + Path(image_url).suffix
|
||||||
images[image_name] = image_url
|
images[image_name] = image_url
|
||||||
return images
|
return images
|
||||||
@@ -127,11 +127,11 @@ class TmdbScraper:
|
|||||||
"""
|
"""
|
||||||
# TMDB季poster图片
|
# TMDB季poster图片
|
||||||
sea_seq = str(season).rjust(2, '0')
|
sea_seq = str(season).rjust(2, '0')
|
||||||
if seasoninfo.get("poster_path"):
|
if poster_path := seasoninfo.get("poster_path"):
|
||||||
# 后缀
|
# 后缀
|
||||||
ext = Path(seasoninfo.get('poster_path')).suffix
|
ext = Path(poster_path).suffix
|
||||||
# URL
|
# URL
|
||||||
url = f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{seasoninfo.get('poster_path')}"
|
url = settings.TMDB_IMAGE_URL(poster_path)
|
||||||
# S0海报格式不同
|
# S0海报格式不同
|
||||||
if season == 0:
|
if season == 0:
|
||||||
image_name = f"season-specials-poster{ext}"
|
image_name = f"season-specials-poster{ext}"
|
||||||
@@ -190,8 +190,8 @@ class TmdbScraper:
|
|||||||
DomUtils.add_node(doc, xactor, "type", "Actor")
|
DomUtils.add_node(doc, xactor, "type", "Actor")
|
||||||
DomUtils.add_node(doc, xactor, "role", actor.get("character") or actor.get("role") or "")
|
DomUtils.add_node(doc, xactor, "role", actor.get("character") or actor.get("role") or "")
|
||||||
DomUtils.add_node(doc, xactor, "tmdbid", actor.get("id") or "")
|
DomUtils.add_node(doc, xactor, "tmdbid", actor.get("id") or "")
|
||||||
DomUtils.add_node(doc, xactor, "thumb",
|
if profile_path := actor.get('profile_path'):
|
||||||
f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{actor.get('profile_path')}")
|
DomUtils.add_node(doc, xactor, "thumb", settings.TMDB_IMAGE_URL(profile_path))
|
||||||
DomUtils.add_node(doc, xactor, "profile",
|
DomUtils.add_node(doc, xactor, "profile",
|
||||||
f"https://www.themoviedb.org/person/{actor.get('id')}")
|
f"https://www.themoviedb.org/person/{actor.get('id')}")
|
||||||
# 风格
|
# 风格
|
||||||
@@ -330,8 +330,8 @@ class TmdbScraper:
|
|||||||
DomUtils.add_node(doc, xactor, "name", actor.get("name") or "")
|
DomUtils.add_node(doc, xactor, "name", actor.get("name") or "")
|
||||||
DomUtils.add_node(doc, xactor, "type", "Actor")
|
DomUtils.add_node(doc, xactor, "type", "Actor")
|
||||||
DomUtils.add_node(doc, xactor, "tmdbid", actor.get("id") or "")
|
DomUtils.add_node(doc, xactor, "tmdbid", actor.get("id") or "")
|
||||||
DomUtils.add_node(doc, xactor, "thumb",
|
if profile_path := actor.get('profile_path'):
|
||||||
f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{actor.get('profile_path')}")
|
DomUtils.add_node(doc, xactor, "thumb", settings.TMDB_IMAGE_URL(profile_path))
|
||||||
DomUtils.add_node(doc, xactor, "profile",
|
DomUtils.add_node(doc, xactor, "profile",
|
||||||
f"https://www.themoviedb.org/person/{actor.get('id')}")
|
f"https://www.themoviedb.org/person/{actor.get('id')}")
|
||||||
return doc
|
return doc
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class TmdbCache(metaclass=WeakSingleton):
|
|||||||
"""
|
"""
|
||||||
获取缓存KEY
|
获取缓存KEY
|
||||||
"""
|
"""
|
||||||
return f"[{meta.type.value if meta.type else '未知'}]{meta.tmdbid or meta.name}-{meta.year}-{meta.begin_season}"
|
return f"[{meta.type.value if meta.type else '未知'}][{settings.TMDB_LOCALE}]{meta.tmdbid or meta.name}-{meta.year}-{meta.begin_season}"
|
||||||
|
|
||||||
def get(self, meta: MetaBase):
|
def get(self, meta: MetaBase):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -826,7 +826,7 @@ class TmdbApi:
|
|||||||
# 转换多语种标题
|
# 转换多语种标题
|
||||||
self.__update_tmdbinfo_extra_title(tmdb_info)
|
self.__update_tmdbinfo_extra_title(tmdb_info)
|
||||||
# 转换中文标题
|
# 转换中文标题
|
||||||
if settings.TMDB_LOCALE == "zh":
|
if self.tmdb.language in ("zh", "zh-CN"):
|
||||||
self.__update_tmdbinfo_cn_title(tmdb_info)
|
self.__update_tmdbinfo_cn_title(tmdb_info)
|
||||||
|
|
||||||
return tmdb_info
|
return tmdb_info
|
||||||
@@ -2134,7 +2134,7 @@ class TmdbApi:
|
|||||||
# 转换多语种标题
|
# 转换多语种标题
|
||||||
self.__update_tmdbinfo_extra_title(tmdb_info)
|
self.__update_tmdbinfo_extra_title(tmdb_info)
|
||||||
# 转换中文标题
|
# 转换中文标题
|
||||||
if settings.TMDB_LOCALE == "zh":
|
if self.tmdb.language in ("zh", "zh-CN"):
|
||||||
self.__update_tmdbinfo_cn_title(tmdb_info)
|
self.__update_tmdbinfo_cn_title(tmdb_info)
|
||||||
|
|
||||||
return tmdb_info
|
return tmdb_info
|
||||||
|
|||||||
Reference in New Issue
Block a user