调整INFO日志打印量 && 回滚多线程过滤

This commit is contained in:
jxxghp 2024-05-24 10:48:56 +08:00
parent a278c80951
commit be11ef72a9
7 changed files with 61 additions and 78 deletions

View File

@ -227,24 +227,8 @@ class SearchChain(ChainBase):
# 取搜索优先级规则 # 取搜索优先级规则
priority_rule = self.systemconfig.get(SystemConfigKey.SearchFilterRules) priority_rule = self.systemconfig.get(SystemConfigKey.SearchFilterRules)
if priority_rule: if priority_rule:
# 使用多线程进行优先级过滤1个站点一个线程
logger.info(f'开始优先级规则/剧集过滤,当前规则:{priority_rule} ...') logger.info(f'开始优先级规则/剧集过滤,当前规则:{priority_rule} ...')
# 站点列表 _match_torrents = __do_filter(_match_torrents)
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
if not _match_torrents: if not _match_torrents:
logger.warn(f'{keyword or mediainfo.title} 没有符合优先级规则的资源') logger.warn(f'{keyword or mediainfo.title} 没有符合优先级规则的资源')
return [] return []

View File

@ -512,6 +512,8 @@ class SubscribeChain(ChainBase):
if not torrents: if not torrents:
logger.warn('没有缓存资源,无法匹配订阅') logger.warn('没有缓存资源,无法匹配订阅')
return return
# 记录重新识别过的种子
_recognize_cached = []
# 所有订阅 # 所有订阅
subscribes = self.subscribeoper.list('R') 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): 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} 订阅缓存为未识别状态,尝试重新识别...') _cache_key = f"{torrent_info.title}_{torrent_info.description}"
# 重新识别(不使用缓存) if _cache_key not in _recognize_cached:
torrent_mediainfo = self.recognize_media(meta=torrent_meta, cache=False) _recognize_cached.append(_cache_key)
if not torrent_mediainfo: logger.info(f'{torrent_info.site_name} - {torrent_info.title} 订阅缓存为未识别状态,尝试重新识别...')
logger.warn(f'{torrent_info.site_name} - {torrent_info.title} 重新识别失败,尝试通过标题匹配...') # 重新识别(不使用缓存)
if self.torrenthelper.match_torrent(mediainfo=mediainfo, torrent_mediainfo = self.recognize_media(meta=torrent_meta, cache=False)
torrent_meta=torrent_meta, if not torrent_mediainfo:
torrent=torrent_info): logger.warn(f'{torrent_info.site_name} - {torrent_info.title} 重新识别失败,尝试通过标题匹配...')
# 匹配成功 if self.torrenthelper.match_torrent(mediainfo=mediainfo,
logger.info(f'{mediainfo.title_year} 通过标题匹配到资源:{torrent_info.site_name} - {torrent_info.title}') torrent_meta=torrent_meta,
# 更新缓存 torrent=torrent_info):
torrent_mediainfo = mediainfo # 匹配成功
context.media_info = mediainfo logger.info(f'{mediainfo.title_year} 通过标题匹配到资源:{torrent_info.site_name} - {torrent_info.title}')
else: # 更新缓存
continue torrent_mediainfo = mediainfo
context.media_info = mediainfo
else:
continue
# 直接比对媒体信息 # 直接比对媒体信息
if torrent_mediainfo and (torrent_mediainfo.tmdb_id or torrent_mediainfo.douban_id): if torrent_mediainfo and (torrent_mediainfo.tmdb_id or torrent_mediainfo.douban_id):
@ -640,28 +645,28 @@ class SubscribeChain(ChainBase):
mediainfo=torrent_mediainfo) mediainfo=torrent_mediainfo)
if result is not None and not result: if result is not None and not result:
# 不符合过滤规则 # 不符合过滤规则
logger.info(f"{torrent_info.title} 不匹配当前过滤规则") logger.debug(f"{torrent_info.title} 不匹配当前过滤规则")
continue continue
# 不在订阅站点范围的不处理 # 不在订阅站点范围的不处理
sub_sites = self.get_sub_sites(subscribe) sub_sites = self.get_sub_sites(subscribe)
if sub_sites and torrent_info.site not in sub_sites: 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 continue
# 如果是电视剧 # 如果是电视剧
if torrent_mediainfo.type == MediaType.TV: if torrent_mediainfo.type == MediaType.TV:
# 有多季的不要 # 有多季的不要
if len(torrent_meta.season_list) > 1: if len(torrent_meta.season_list) > 1:
logger.info(f'{torrent_info.title} 有多季,不处理') logger.debug(f'{torrent_info.title} 有多季,不处理')
continue continue
# 比对季 # 比对季
if torrent_meta.begin_season: if torrent_meta.begin_season:
if meta.begin_season != 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 continue
elif meta.begin_season != 1: elif meta.begin_season != 1:
logger.info(f'{torrent_info.title} 季不匹配') logger.debug(f'{torrent_info.title} 季不匹配')
continue continue
# 非洗版 # 非洗版
if not subscribe.best_version: if not subscribe.best_version:
@ -676,7 +681,7 @@ class SubscribeChain(ChainBase):
not set(no_exists_info.episodes).intersection( not set(no_exists_info.episodes).intersection(
set(torrent_meta.episode_list) set(torrent_meta.episode_list)
): ):
logger.info( logger.debug(
f'{torrent_info.title} 对应剧集 {torrent_meta.episode_list} 未包含缺失的剧集' f'{torrent_info.title} 对应剧集 {torrent_meta.episode_list} 未包含缺失的剧集'
) )
continue continue
@ -688,7 +693,7 @@ class SubscribeChain(ChainBase):
# 洗版时,非整季不要 # 洗版时,非整季不要
if meta.type == MediaType.TV: if meta.type == MediaType.TV:
if torrent_meta.episode_list: if torrent_meta.episode_list:
logger.info(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季') logger.debug(f'{subscribe.name} 正在洗版,{torrent_info.title} 不是整季')
continue continue
# 过滤规则 # 过滤规则

View File

@ -428,14 +428,12 @@ class TorrentHelper(metaclass=Singleton):
return True return True
@staticmethod @staticmethod
def match_torrent(mediainfo: MediaInfo, torrent_meta: MetaInfo, def match_torrent(mediainfo: MediaInfo, torrent_meta: MetaInfo, torrent: TorrentInfo) -> bool:
torrent: TorrentInfo, logerror: bool = True) -> bool:
""" """
检查种子是否匹配媒体信息 检查种子是否匹配媒体信息
:param mediainfo: 需要匹配的媒体信息 :param mediainfo: 需要匹配的媒体信息
:param torrent_meta: 种子识别信息 :param torrent_meta: 种子识别信息
:param torrent: 种子信息 :param torrent: 种子信息
:param logerror: 是否记录错误日志
""" """
# 比对词条指定的tmdbid # 比对词条指定的tmdbid
if torrent_meta.tmdbid or torrent_meta.doubanid: 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 torrent_meta.type == MediaType.TV and mediainfo.type != MediaType.TV:
if logerror: logger.debug(f'{torrent.site_name} - {torrent.title} 种子标题类型为 {torrent_meta.type.value}'
logger.warn(f'{torrent.site_name} - {torrent.title} 种子标题类型为 {torrent_meta.type.value}' f'不匹配 {mediainfo.type.value}')
f'不匹配 {mediainfo.type.value}')
return False return False
# 比对种子在站点中的类型 # 比对种子在站点中的类型
if torrent.category == MediaType.TV.value and mediainfo.type != MediaType.TV: if torrent.category == MediaType.TV.value and mediainfo.type != MediaType.TV:
if logerror: logger.debug(f'{torrent.site_name} - {torrent.title} 种子在站点中归类为 {torrent.category}'
logger.warn(f'{torrent.site_name} - {torrent.title} 种子在站点中归类为 {torrent.category}' f'不匹配 {mediainfo.type.value}')
f'不匹配 {mediainfo.type.value}')
return False return False
# 比对年份 # 比对年份
if mediainfo.year: 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 if torrent_meta.year and torrent_meta.year not in [year for year in
mediainfo.season_years.values()]: mediainfo.season_years.values()]:
if logerror: logger.debug(f'{torrent.site_name} - {torrent.title} 年份不匹配 {mediainfo.season_years}')
logger.warn(f'{torrent.site_name} - {torrent.title} 年份不匹配 {mediainfo.season_years}')
return False return False
else: else:
# 电影年份上下浮动1年没年份时不通过 # 电影年份上下浮动1年没年份时不通过
if not torrent_meta.year or torrent_meta.year not in [str(int(mediainfo.year) - 1), if not torrent_meta.year or torrent_meta.year not in [str(int(mediainfo.year) - 1),
mediainfo.year, mediainfo.year,
str(int(mediainfo.year) + 1)]: str(int(mediainfo.year) + 1)]:
if logerror: logger.debug(f'{torrent.site_name} - {torrent.title} 年份不匹配 {mediainfo.year}')
logger.warn(f'{torrent.site_name} - {torrent.title} 年份不匹配 {mediainfo.year}')
return False return False
# 比对标题和原语种标题 # 比对标题和原语种标题
if meta_names.intersection(media_titles): if meta_names.intersection(media_titles):
@ -518,6 +512,5 @@ class TorrentHelper(metaclass=Singleton):
f'副标题:{torrent.description}') f'副标题:{torrent.description}')
return True return True
# 未匹配 # 未匹配
if logerror: logger.debug(f'{torrent.site_name} - {torrent.title} 标题不匹配,识别名称:{meta_names}')
logger.warn(f'{torrent.site_name} - {torrent.title} 标题不匹配,识别名称:{meta_names}')
return False return False

View File

@ -136,6 +136,7 @@ class LoggerManager:
if not _logger: if not _logger:
_logger = self.__setup_logger(logfile) _logger = self.__setup_logger(logfile)
self._loggers[logfile] = _logger self._loggers[logfile] = _logger
# 调用logger的方法打印日志
if hasattr(_logger, method): if hasattr(_logger, method):
method = getattr(_logger, method) method = getattr(_logger, method)
method(f"{caller_name} - {msg}", *args, **kwargs) method(f"{caller_name} - {msg}", *args, **kwargs)

View File

@ -173,7 +173,7 @@ class FilterModule(_ModuleBase):
continue continue
# 能命中优先级的才返回 # 能命中优先级的才返回
if not self.__get_order(torrent, rule_string): 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 continue
ret_torrents.append(torrent) ret_torrents.append(torrent)
@ -196,7 +196,7 @@ class FilterModule(_ModuleBase):
torrent_episodes = meta.episode_list torrent_episodes = meta.episode_list
if not set(torrent_seasons).issubset(set(seasons)): 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 return False
if not torrent_episodes: if not torrent_episodes:
# 整季按匹配处理 # 整季按匹配处理
@ -206,7 +206,7 @@ class FilterModule(_ModuleBase):
if need_episodes \ if need_episodes \
and not set(torrent_episodes).intersection(set(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}") f"{torrent_episodes} 没有需要的集:{need_episodes}")
return False return False
return True return True
@ -228,7 +228,7 @@ class FilterModule(_ModuleBase):
if self.__match_group(torrent, parsed_group.as_list()[0]): if self.__match_group(torrent, parsed_group.as_list()[0]):
# 出现匹配时中断 # 出现匹配时中断
matched = True 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 torrent.pri_order = res_order
break break
# 优先级降低,继续匹配 # 优先级降低,继续匹配

View File

@ -546,7 +546,7 @@ class TheMovieDbModule(_ModuleBase):
detail = self.tmdb.get_person_detail(person_id=person_id) detail = self.tmdb.get_person_detail(person_id=person_id)
if detail: if detail:
return schemas.MediaPerson(source="themoviedb", **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]: def tmdb_person_credits(self, person_id: int, page: int = 1) -> List[MediaInfo]:
""" """

View File

@ -759,10 +759,10 @@ class TmdbApi:
if not self.movie: if not self.movie:
return {} return {}
try: try:
logger.info("正在查询TMDB电影%s ..." % tmdbid) logger.debug("正在查询TMDB电影%s ..." % tmdbid)
tmdbinfo = self.movie.details(tmdbid, append_to_response) tmdbinfo = self.movie.details(tmdbid, append_to_response)
if tmdbinfo: if tmdbinfo:
logger.info(f"{tmdbid} 查询结果:{tmdbinfo.get('title')}") logger.debug(f"{tmdbid} 查询结果:{tmdbinfo.get('title')}")
return tmdbinfo or {} return tmdbinfo or {}
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
@ -942,10 +942,10 @@ class TmdbApi:
if not self.tv: if not self.tv:
return {} return {}
try: try:
logger.info("正在查询TMDB电视剧%s ..." % tmdbid) logger.debug("正在查询TMDB电视剧%s ..." % tmdbid)
tmdbinfo = self.tv.details(tv_id=tmdbid, append_to_response=append_to_response) tmdbinfo = self.tv.details(tv_id=tmdbid, append_to_response=append_to_response)
if tmdbinfo: if tmdbinfo:
logger.info(f"{tmdbid} 查询结果:{tmdbinfo.get('name')}") logger.debug(f"{tmdbid} 查询结果:{tmdbinfo.get('name')}")
return tmdbinfo or {} return tmdbinfo or {}
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
@ -1018,7 +1018,7 @@ class TmdbApi:
if not self.season: if not self.season:
return {} return {}
try: 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) tmdbinfo = self.season.details(tv_id=tmdbid, season_num=season)
return tmdbinfo or {} return tmdbinfo or {}
except Exception as e: except Exception as e:
@ -1035,7 +1035,7 @@ class TmdbApi:
if not self.episode: if not self.episode:
return {} return {}
try: 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) tmdbinfo = self.episode.details(tv_id=tmdbid, season_num=season, episode_num=episode)
return tmdbinfo or {} return tmdbinfo or {}
except Exception as e: except Exception as e:
@ -1051,7 +1051,7 @@ class TmdbApi:
if not self.discover: if not self.discover:
return [] return []
try: try:
logger.info(f"正在发现电影:{kwargs}...") logger.debug(f"正在发现电影:{kwargs}...")
tmdbinfo = self.discover.discover_movies(kwargs) tmdbinfo = self.discover.discover_movies(kwargs)
if tmdbinfo: if tmdbinfo:
for info in tmdbinfo: for info in tmdbinfo:
@ -1070,7 +1070,7 @@ class TmdbApi:
if not self.discover: if not self.discover:
return [] return []
try: try:
logger.info(f"正在发现电视剧:{kwargs}...") logger.debug(f"正在发现电视剧:{kwargs}...")
tmdbinfo = self.discover.discover_tv_shows(kwargs) tmdbinfo = self.discover.discover_tv_shows(kwargs)
if tmdbinfo: if tmdbinfo:
for info in tmdbinfo: for info in tmdbinfo:
@ -1087,7 +1087,7 @@ class TmdbApi:
if not self.movie: if not self.movie:
return {} return {}
try: try:
logger.info(f"正在获取电影图片:{tmdbid}...") logger.debug(f"正在获取电影图片:{tmdbid}...")
return self.movie.images(movie_id=tmdbid) or {} return self.movie.images(movie_id=tmdbid) or {}
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
@ -1100,7 +1100,7 @@ class TmdbApi:
if not self.tv: if not self.tv:
return {} return {}
try: try:
logger.info(f"正在获取电视剧图片:{tmdbid}...") logger.debug(f"正在获取电视剧图片:{tmdbid}...")
return self.tv.images(tv_id=tmdbid) or {} return self.tv.images(tv_id=tmdbid) or {}
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
@ -1113,7 +1113,7 @@ class TmdbApi:
if not self.movie: if not self.movie:
return [] return []
try: try:
logger.info(f"正在获取相似电影:{tmdbid}...") logger.debug(f"正在获取相似电影:{tmdbid}...")
return self.movie.similar(movie_id=tmdbid) or [] return self.movie.similar(movie_id=tmdbid) or []
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
@ -1126,7 +1126,7 @@ class TmdbApi:
if not self.tv: if not self.tv:
return [] return []
try: try:
logger.info(f"正在获取相似电视剧:{tmdbid}...") logger.debug(f"正在获取相似电视剧:{tmdbid}...")
return self.tv.similar(tv_id=tmdbid) or [] return self.tv.similar(tv_id=tmdbid) or []
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
@ -1139,7 +1139,7 @@ class TmdbApi:
if not self.movie: if not self.movie:
return [] return []
try: try:
logger.info(f"正在获取推荐电影:{tmdbid}...") logger.debug(f"正在获取推荐电影:{tmdbid}...")
return self.movie.recommendations(movie_id=tmdbid) or [] return self.movie.recommendations(movie_id=tmdbid) or []
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
@ -1152,7 +1152,7 @@ class TmdbApi:
if not self.tv: if not self.tv:
return [] return []
try: try:
logger.info(f"正在获取推荐电视剧:{tmdbid}...") logger.debug(f"正在获取推荐电视剧:{tmdbid}...")
return self.tv.recommendations(tv_id=tmdbid) or [] return self.tv.recommendations(tv_id=tmdbid) or []
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
@ -1165,7 +1165,7 @@ class TmdbApi:
if not self.movie: if not self.movie:
return [] return []
try: try:
logger.info(f"正在获取电影演职人员:{tmdbid}...") logger.debug(f"正在获取电影演职人员:{tmdbid}...")
info = self.movie.credits(movie_id=tmdbid) or {} info = self.movie.credits(movie_id=tmdbid) or {}
cast = info.get('cast') or [] cast = info.get('cast') or []
if cast: if cast:
@ -1182,7 +1182,7 @@ class TmdbApi:
if not self.tv: if not self.tv:
return [] return []
try: try:
logger.info(f"正在获取电视剧演职人员:{tmdbid}...") logger.debug(f"正在获取电视剧演职人员:{tmdbid}...")
info = self.tv.credits(tv_id=tmdbid) or {} info = self.tv.credits(tv_id=tmdbid) or {}
cast = info.get('cast') or [] cast = info.get('cast') or []
if cast: if cast:
@ -1219,7 +1219,7 @@ class TmdbApi:
if not self.person: if not self.person:
return {} return {}
try: try:
logger.info(f"正在获取人物详情:{person_id}...") logger.debug(f"正在获取人物详情:{person_id}...")
return self.person.details(person_id=person_id) or {} return self.person.details(person_id=person_id) or {}
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
@ -1232,7 +1232,7 @@ class TmdbApi:
if not self.person: if not self.person:
return [] return []
try: try:
logger.info(f"正在获取人物参演作品:{person_id}...") logger.debug(f"正在获取人物参演作品:{person_id}...")
movies = self.person.movie_credits(person_id=person_id) or {} movies = self.person.movie_credits(person_id=person_id) or {}
tvs = self.person.tv_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 []) cast = (movies.get('cast') or []) + (tvs.get('cast') or [])
@ -1262,7 +1262,7 @@ class TmdbApi:
return {} return {}
episode_years = {} episode_years = {}
for episode_group in episode_groups: 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: if episode_group.get('type') != 6:
# 只处理剧集部分 # 只处理剧集部分
continue continue