diff --git a/app/chain/search.py b/app/chain/search.py index ad523a71..cd62e6c0 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -227,24 +227,8 @@ class SearchChain(ChainBase): # 取搜索优先级规则 priority_rule = self.systemconfig.get(SystemConfigKey.SearchFilterRules) if priority_rule: - # 使用多线程进行优先级过滤,1个站点一个线程 logger.info(f'开始优先级规则/剧集过滤,当前规则:{priority_rule} ...') - # 站点列表 - filter_sites = set([t.site_name for t in _match_torrents]) - # 多线程 - executor = ThreadPoolExecutor(max_workers=len(filter_sites)) - all_task = [] - for site in filter_sites: - task = executor.submit(__do_filter, - torrent_list=[t for t in _match_torrents if t.site_name == site]) - all_task.append(task) - # 汇总结果 - results = [] - for future in as_completed(all_task): - result = future.result() - if result: - results.extend(result) - _match_torrents = results + _match_torrents = __do_filter(_match_torrents) if not _match_torrents: logger.warn(f'{keyword or mediainfo.title} 没有符合优先级规则的资源') return [] diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index cd1ffb4f..5f286ad8 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -512,6 +512,8 @@ class SubscribeChain(ChainBase): if not torrents: logger.warn('没有缓存资源,无法匹配订阅') return + # 记录重新识别过的种子 + _recognize_cached = [] # 所有订阅 subscribes = self.subscribeoper.list('R') # 遍历订阅 @@ -600,21 +602,24 @@ class SubscribeChain(ChainBase): # 先判断是否有没识别的种子 if not torrent_mediainfo or (not torrent_mediainfo.tmdb_id and not torrent_mediainfo.douban_id): - logger.info(f'{torrent_info.site_name} - {torrent_info.title} 订阅缓存为未识别状态,尝试重新识别...') - # 重新识别(不使用缓存) - torrent_mediainfo = self.recognize_media(meta=torrent_meta, cache=False) - if not torrent_mediainfo: - logger.warn(f'{torrent_info.site_name} - {torrent_info.title} 重新识别失败,尝试通过标题匹配...') - if self.torrenthelper.match_torrent(mediainfo=mediainfo, - torrent_meta=torrent_meta, - torrent=torrent_info): - # 匹配成功 - logger.info(f'{mediainfo.title_year} 通过标题匹配到资源:{torrent_info.site_name} - {torrent_info.title}') - # 更新缓存 - torrent_mediainfo = mediainfo - context.media_info = mediainfo - else: - continue + _cache_key = f"{torrent_info.title}_{torrent_info.description}" + if _cache_key not in _recognize_cached: + _recognize_cached.append(_cache_key) + logger.info(f'{torrent_info.site_name} - {torrent_info.title} 订阅缓存为未识别状态,尝试重新识别...') + # 重新识别(不使用缓存) + torrent_mediainfo = self.recognize_media(meta=torrent_meta, cache=False) + if not torrent_mediainfo: + logger.warn(f'{torrent_info.site_name} - {torrent_info.title} 重新识别失败,尝试通过标题匹配...') + if self.torrenthelper.match_torrent(mediainfo=mediainfo, + torrent_meta=torrent_meta, + torrent=torrent_info): + # 匹配成功 + logger.info(f'{mediainfo.title_year} 通过标题匹配到资源:{torrent_info.site_name} - {torrent_info.title}') + # 更新缓存 + torrent_mediainfo = mediainfo + context.media_info = mediainfo + else: + continue # 直接比对媒体信息 if torrent_mediainfo and (torrent_mediainfo.tmdb_id or torrent_mediainfo.douban_id): @@ -640,28 +645,28 @@ class SubscribeChain(ChainBase): mediainfo=torrent_mediainfo) if result is not None and not result: # 不符合过滤规则 - logger.info(f"{torrent_info.title} 不匹配当前过滤规则") + logger.debug(f"{torrent_info.title} 不匹配当前过滤规则") continue # 不在订阅站点范围的不处理 sub_sites = self.get_sub_sites(subscribe) if sub_sites and torrent_info.site not in sub_sites: - logger.info(f"{torrent_info.site_name} - {torrent_info.title} 不符合订阅站点要求") + logger.debug(f"{torrent_info.site_name} - {torrent_info.title} 不符合订阅站点要求") continue # 如果是电视剧 if torrent_mediainfo.type == MediaType.TV: # 有多季的不要 if len(torrent_meta.season_list) > 1: - logger.info(f'{torrent_info.title} 有多季,不处理') + logger.debug(f'{torrent_info.title} 有多季,不处理') continue # 比对季 if torrent_meta.begin_season: if meta.begin_season != torrent_meta.begin_season: - logger.info(f'{torrent_info.title} 季不匹配') + logger.debug(f'{torrent_info.title} 季不匹配') continue elif meta.begin_season != 1: - logger.info(f'{torrent_info.title} 季不匹配') + logger.debug(f'{torrent_info.title} 季不匹配') continue # 非洗版 if not subscribe.best_version: @@ -676,7 +681,7 @@ class SubscribeChain(ChainBase): not set(no_exists_info.episodes).intersection( set(torrent_meta.episode_list) ): - logger.info( + logger.debug( f'{torrent_info.title} 对应剧集 {torrent_meta.episode_list} 未包含缺失的剧集' ) continue @@ -688,7 +693,7 @@ class SubscribeChain(ChainBase): # 洗版时,非整季不要 if meta.type == MediaType.TV: if torrent_meta.episode_list: - logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季') + logger.debug(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季') continue # 过滤规则 diff --git a/app/helper/torrent.py b/app/helper/torrent.py index 3ec7ef0d..9a141d4b 100644 --- a/app/helper/torrent.py +++ b/app/helper/torrent.py @@ -428,14 +428,12 @@ class TorrentHelper(metaclass=Singleton): return True @staticmethod - def match_torrent(mediainfo: MediaInfo, torrent_meta: MetaInfo, - torrent: TorrentInfo, logerror: bool = True) -> bool: + def match_torrent(mediainfo: MediaInfo, torrent_meta: MetaInfo, torrent: TorrentInfo) -> bool: """ 检查种子是否匹配媒体信息 :param mediainfo: 需要匹配的媒体信息 :param torrent_meta: 种子识别信息 :param torrent: 种子信息 - :param logerror: 是否记录错误日志 """ # 比对词条指定的tmdbid if torrent_meta.tmdbid or torrent_meta.doubanid: @@ -461,15 +459,13 @@ class TorrentHelper(metaclass=Singleton): } - {""} # 比对种子识别类型 if torrent_meta.type == MediaType.TV and mediainfo.type != MediaType.TV: - if logerror: - logger.warn(f'{torrent.site_name} - {torrent.title} 种子标题类型为 {torrent_meta.type.value},' - f'不匹配 {mediainfo.type.value}') + logger.debug(f'{torrent.site_name} - {torrent.title} 种子标题类型为 {torrent_meta.type.value},' + f'不匹配 {mediainfo.type.value}') return False # 比对种子在站点中的类型 if torrent.category == MediaType.TV.value and mediainfo.type != MediaType.TV: - if logerror: - logger.warn(f'{torrent.site_name} - {torrent.title} 种子在站点中归类为 {torrent.category},' - f'不匹配 {mediainfo.type.value}') + logger.debug(f'{torrent.site_name} - {torrent.title} 种子在站点中归类为 {torrent.category},' + f'不匹配 {mediainfo.type.value}') return False # 比对年份 if mediainfo.year: @@ -477,16 +473,14 @@ class TorrentHelper(metaclass=Singleton): # 剧集年份,每季的年份可能不同,没年份时不比较年份(很多剧集种子不带年份) if torrent_meta.year and torrent_meta.year not in [year for year in mediainfo.season_years.values()]: - if logerror: - logger.warn(f'{torrent.site_name} - {torrent.title} 年份不匹配 {mediainfo.season_years}') + logger.debug(f'{torrent.site_name} - {torrent.title} 年份不匹配 {mediainfo.season_years}') return False else: # 电影年份,上下浮动1年,没年份时不通过 if not torrent_meta.year or torrent_meta.year not in [str(int(mediainfo.year) - 1), mediainfo.year, str(int(mediainfo.year) + 1)]: - if logerror: - logger.warn(f'{torrent.site_name} - {torrent.title} 年份不匹配 {mediainfo.year}') + logger.debug(f'{torrent.site_name} - {torrent.title} 年份不匹配 {mediainfo.year}') return False # 比对标题和原语种标题 if meta_names.intersection(media_titles): @@ -518,6 +512,5 @@ class TorrentHelper(metaclass=Singleton): f'副标题:{torrent.description}') return True # 未匹配 - if logerror: - logger.warn(f'{torrent.site_name} - {torrent.title} 标题不匹配,识别名称:{meta_names}') + logger.debug(f'{torrent.site_name} - {torrent.title} 标题不匹配,识别名称:{meta_names}') return False diff --git a/app/log.py b/app/log.py index 0717fdf7..6a65cf7a 100644 --- a/app/log.py +++ b/app/log.py @@ -136,6 +136,7 @@ class LoggerManager: if not _logger: _logger = self.__setup_logger(logfile) self._loggers[logfile] = _logger + # 调用logger的方法打印日志 if hasattr(_logger, method): method = getattr(_logger, method) method(f"{caller_name} - {msg}", *args, **kwargs) diff --git a/app/modules/filter/__init__.py b/app/modules/filter/__init__.py index 5da9a9af..65c4bce0 100644 --- a/app/modules/filter/__init__.py +++ b/app/modules/filter/__init__.py @@ -173,7 +173,7 @@ class FilterModule(_ModuleBase): continue # 能命中优先级的才返回 if not self.__get_order(torrent, rule_string): - logger.info(f"种子 {torrent.site_name} - {torrent.title} {torrent.description} 不匹配优先级规则") + logger.debug(f"种子 {torrent.site_name} - {torrent.title} {torrent.description} 不匹配优先级规则") continue ret_torrents.append(torrent) @@ -196,7 +196,7 @@ class FilterModule(_ModuleBase): torrent_episodes = meta.episode_list if not set(torrent_seasons).issubset(set(seasons)): # 种子季不在过滤季中 - logger.info(f"种子 {torrent.site_name} - {torrent.title} 包含季 {torrent_seasons} 不是需要的季 {list(seasons)}") + logger.debug(f"种子 {torrent.site_name} - {torrent.title} 包含季 {torrent_seasons} 不是需要的季 {list(seasons)}") return False if not torrent_episodes: # 整季按匹配处理 @@ -206,7 +206,7 @@ class FilterModule(_ModuleBase): if need_episodes \ and not set(torrent_episodes).intersection(set(need_episodes)): # 单季集没有交集的不要 - logger.info(f"种子 {torrent.site_name} - {torrent.title} " + logger.debug(f"种子 {torrent.site_name} - {torrent.title} " f"集 {torrent_episodes} 没有需要的集:{need_episodes}") return False return True @@ -228,7 +228,7 @@ class FilterModule(_ModuleBase): if self.__match_group(torrent, parsed_group.as_list()[0]): # 出现匹配时中断 matched = True - logger.info(f"种子 {torrent.site_name} - {torrent.title} 优先级为 {100 - res_order + 1}") + logger.debug(f"种子 {torrent.site_name} - {torrent.title} 优先级为 {100 - res_order + 1}") torrent.pri_order = res_order break # 优先级降低,继续匹配 diff --git a/app/modules/themoviedb/__init__.py b/app/modules/themoviedb/__init__.py index ded368df..61335cca 100644 --- a/app/modules/themoviedb/__init__.py +++ b/app/modules/themoviedb/__init__.py @@ -546,7 +546,7 @@ class TheMovieDbModule(_ModuleBase): detail = self.tmdb.get_person_detail(person_id=person_id) if detail: return schemas.MediaPerson(source="themoviedb", **detail) - return schemas.MediaPerson + return schemas.MediaPerson() def tmdb_person_credits(self, person_id: int, page: int = 1) -> List[MediaInfo]: """ diff --git a/app/modules/themoviedb/tmdbapi.py b/app/modules/themoviedb/tmdbapi.py index 06be477e..76230254 100644 --- a/app/modules/themoviedb/tmdbapi.py +++ b/app/modules/themoviedb/tmdbapi.py @@ -759,10 +759,10 @@ class TmdbApi: if not self.movie: return {} try: - logger.info("正在查询TMDB电影:%s ..." % tmdbid) + logger.debug("正在查询TMDB电影:%s ..." % tmdbid) tmdbinfo = self.movie.details(tmdbid, append_to_response) if tmdbinfo: - logger.info(f"{tmdbid} 查询结果:{tmdbinfo.get('title')}") + logger.debug(f"{tmdbid} 查询结果:{tmdbinfo.get('title')}") return tmdbinfo or {} except Exception as e: print(str(e)) @@ -942,10 +942,10 @@ class TmdbApi: if not self.tv: return {} try: - logger.info("正在查询TMDB电视剧:%s ..." % tmdbid) + logger.debug("正在查询TMDB电视剧:%s ..." % tmdbid) tmdbinfo = self.tv.details(tv_id=tmdbid, append_to_response=append_to_response) if tmdbinfo: - logger.info(f"{tmdbid} 查询结果:{tmdbinfo.get('name')}") + logger.debug(f"{tmdbid} 查询结果:{tmdbinfo.get('name')}") return tmdbinfo or {} except Exception as e: print(str(e)) @@ -1018,7 +1018,7 @@ class TmdbApi: if not self.season: return {} try: - logger.info("正在查询TMDB电视剧:%s,季:%s ..." % (tmdbid, season)) + logger.debug("正在查询TMDB电视剧:%s,季:%s ..." % (tmdbid, season)) tmdbinfo = self.season.details(tv_id=tmdbid, season_num=season) return tmdbinfo or {} except Exception as e: @@ -1035,7 +1035,7 @@ class TmdbApi: if not self.episode: return {} try: - logger.info("正在查询TMDB集详情:%s,季:%s,集:%s ..." % (tmdbid, season, episode)) + logger.debug("正在查询TMDB集详情:%s,季:%s,集:%s ..." % (tmdbid, season, episode)) tmdbinfo = self.episode.details(tv_id=tmdbid, season_num=season, episode_num=episode) return tmdbinfo or {} except Exception as e: @@ -1051,7 +1051,7 @@ class TmdbApi: if not self.discover: return [] try: - logger.info(f"正在发现电影:{kwargs}...") + logger.debug(f"正在发现电影:{kwargs}...") tmdbinfo = self.discover.discover_movies(kwargs) if tmdbinfo: for info in tmdbinfo: @@ -1070,7 +1070,7 @@ class TmdbApi: if not self.discover: return [] try: - logger.info(f"正在发现电视剧:{kwargs}...") + logger.debug(f"正在发现电视剧:{kwargs}...") tmdbinfo = self.discover.discover_tv_shows(kwargs) if tmdbinfo: for info in tmdbinfo: @@ -1087,7 +1087,7 @@ class TmdbApi: if not self.movie: return {} try: - logger.info(f"正在获取电影图片:{tmdbid}...") + logger.debug(f"正在获取电影图片:{tmdbid}...") return self.movie.images(movie_id=tmdbid) or {} except Exception as e: print(str(e)) @@ -1100,7 +1100,7 @@ class TmdbApi: if not self.tv: return {} try: - logger.info(f"正在获取电视剧图片:{tmdbid}...") + logger.debug(f"正在获取电视剧图片:{tmdbid}...") return self.tv.images(tv_id=tmdbid) or {} except Exception as e: print(str(e)) @@ -1113,7 +1113,7 @@ class TmdbApi: if not self.movie: return [] try: - logger.info(f"正在获取相似电影:{tmdbid}...") + logger.debug(f"正在获取相似电影:{tmdbid}...") return self.movie.similar(movie_id=tmdbid) or [] except Exception as e: print(str(e)) @@ -1126,7 +1126,7 @@ class TmdbApi: if not self.tv: return [] try: - logger.info(f"正在获取相似电视剧:{tmdbid}...") + logger.debug(f"正在获取相似电视剧:{tmdbid}...") return self.tv.similar(tv_id=tmdbid) or [] except Exception as e: print(str(e)) @@ -1139,7 +1139,7 @@ class TmdbApi: if not self.movie: return [] try: - logger.info(f"正在获取推荐电影:{tmdbid}...") + logger.debug(f"正在获取推荐电影:{tmdbid}...") return self.movie.recommendations(movie_id=tmdbid) or [] except Exception as e: print(str(e)) @@ -1152,7 +1152,7 @@ class TmdbApi: if not self.tv: return [] try: - logger.info(f"正在获取推荐电视剧:{tmdbid}...") + logger.debug(f"正在获取推荐电视剧:{tmdbid}...") return self.tv.recommendations(tv_id=tmdbid) or [] except Exception as e: print(str(e)) @@ -1165,7 +1165,7 @@ class TmdbApi: if not self.movie: return [] try: - logger.info(f"正在获取电影演职人员:{tmdbid}...") + logger.debug(f"正在获取电影演职人员:{tmdbid}...") info = self.movie.credits(movie_id=tmdbid) or {} cast = info.get('cast') or [] if cast: @@ -1182,7 +1182,7 @@ class TmdbApi: if not self.tv: return [] try: - logger.info(f"正在获取电视剧演职人员:{tmdbid}...") + logger.debug(f"正在获取电视剧演职人员:{tmdbid}...") info = self.tv.credits(tv_id=tmdbid) or {} cast = info.get('cast') or [] if cast: @@ -1219,7 +1219,7 @@ class TmdbApi: if not self.person: return {} try: - logger.info(f"正在获取人物详情:{person_id}...") + logger.debug(f"正在获取人物详情:{person_id}...") return self.person.details(person_id=person_id) or {} except Exception as e: print(str(e)) @@ -1232,7 +1232,7 @@ class TmdbApi: if not self.person: return [] try: - logger.info(f"正在获取人物参演作品:{person_id}...") + logger.debug(f"正在获取人物参演作品:{person_id}...") movies = self.person.movie_credits(person_id=person_id) or {} tvs = self.person.tv_credits(person_id=person_id) or {} cast = (movies.get('cast') or []) + (tvs.get('cast') or []) @@ -1262,7 +1262,7 @@ class TmdbApi: return {} episode_years = {} for episode_group in episode_groups: - logger.info(f"正在获取剧集组年份:{episode_group.get('id')}...") + logger.debug(f"正在获取剧集组年份:{episode_group.get('id')}...") if episode_group.get('type') != 6: # 只处理剧集部分 continue