@@ -490,6 +490,7 @@ def recognize_media(self, meta: MetaBase = None,
490490 group_seasons = []
491491 if episode_group :
492492 group_seasons = self .tmdb .get_tv_group_seasons (episode_group )
493+ cache_hit = False
493494
494495 # 识别匹配
495496 if not cache_info or not cache :
@@ -525,6 +526,7 @@ def recognize_media(self, meta: MetaBase = None,
525526 self .cache .update (meta , info )
526527 else :
527528 # 使用缓存信息
529+ cache_hit = True
528530 if cache_info .get ("title" ):
529531 logger .info (f"{ meta .name } 使用TMDB识别缓存:{ cache_info .get ('title' )} " )
530532 info = self .tmdb .get_info (mtype = cache_info .get ("type" ),
@@ -534,7 +536,10 @@ def recognize_media(self, meta: MetaBase = None,
534536 info = None
535537
536538 if info :
537- return self ._build_media_info_result (info , meta , tmdbid , episode_group , group_seasons )
539+ mediainfo = self ._build_media_info_result (info , meta , tmdbid , episode_group , group_seasons )
540+ if mediainfo :
541+ mediainfo .recognize_cache_hit = cache_hit
542+ return mediainfo
538543 else :
539544 logger .info (f"{ meta .name if meta else tmdbid } 未匹配到TMDB媒体信息" )
540545
@@ -574,6 +579,7 @@ async def async_recognize_media(self, meta: MetaBase = None,
574579 group_seasons = []
575580 if episode_group :
576581 group_seasons = await self .tmdb .async_get_tv_group_seasons (episode_group )
582+ cache_hit = False
577583
578584 # 识别匹配
579585 if not cache_info or not cache :
@@ -609,6 +615,7 @@ async def async_recognize_media(self, meta: MetaBase = None,
609615 self .cache .update (meta , info )
610616 else :
611617 # 使用缓存信息
618+ cache_hit = True
612619 if cache_info .get ("title" ):
613620 logger .info (f"{ meta .name } 使用TMDB识别缓存:{ cache_info .get ('title' )} " )
614621 info = await self .tmdb .async_get_info (mtype = cache_info .get ("type" ),
@@ -618,7 +625,10 @@ async def async_recognize_media(self, meta: MetaBase = None,
618625 info = None
619626
620627 if info :
621- return await self ._async_build_media_info_result (info , meta , tmdbid , episode_group , group_seasons )
628+ mediainfo = await self ._async_build_media_info_result (info , meta , tmdbid , episode_group , group_seasons )
629+ if mediainfo :
630+ mediainfo .recognize_cache_hit = cache_hit
631+ return mediainfo
622632 else :
623633 logger .info (f"{ meta .name if meta else tmdbid } 未匹配到TMDB媒体信息" )
624634
@@ -692,6 +702,31 @@ async def async_tmdb_info(self, tmdbid: int, mtype: MediaType, season: Optional[
692702 else :
693703 return await self .tmdb .async_get_tv_season_detail (tmdbid = tmdbid , season = season )
694704
705+ def update_recognize_cache (
706+ self ,
707+ meta : MetaBase ,
708+ mediainfo : MediaInfo ,
709+ ) -> Optional [bool ]:
710+ """
711+ 回填TMDB本地识别缓存,覆盖名称负缓存,避免共享识别后重复回查。
712+ """
713+ if not meta or not mediainfo :
714+ return None
715+ if mediainfo .source != "themoviedb" or not mediainfo .tmdb_info :
716+ return None
717+ self .cache .update (meta , mediainfo .tmdb_info )
718+ return True
719+
720+ async def async_update_recognize_cache (
721+ self ,
722+ meta : MetaBase ,
723+ mediainfo : MediaInfo ,
724+ ) -> Optional [bool ]:
725+ """
726+ 异步回填TMDB本地识别缓存。
727+ """
728+ return self .update_recognize_cache (meta = meta , mediainfo = mediainfo )
729+
695730 def media_category (self ) -> Optional [Dict [str , list ]]:
696731 """
697732 获取媒体分类
0 commit comments