From db4b9fcef8d3847705bc0642aee59ae3dc2eff20 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 11 Jun 2023 18:42:23 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=B9=B4=E4=BB=BD=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/download.py | 4 ++-- app/chain/search.py | 14 ++++++++++++++ app/chain/user_message.py | 4 +++- app/core/context.py | 14 ++++++++++++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/chain/download.py b/app/chain/download.py index 78162dad..5412bcc4 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -386,7 +386,7 @@ class DownloadChain(ChainBase): # 所有剧集均缺失 for season, episodes in mediainfo.seasons.items(): # 全季不存在 - if meta.get_season_list() \ + if meta.begin_season \ and season not in meta.get_season_list(): continue __append_no_exists(_season=season, _episodes=[], _total=len(episodes), _start=min(episodes)) @@ -394,7 +394,7 @@ class DownloadChain(ChainBase): else: # 存在一些,检查缺失的季集 for season, episodes in mediainfo.seasons.items(): - if meta.get_season_list() \ + if meta.begin_season \ and season not in meta.get_season_list(): continue exist_seasons = exists_tvs.get("seasons") diff --git a/app/chain/search.py b/app/chain/search.py index 7499e766..583ac99d 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -8,6 +8,7 @@ from app.core.metainfo import MetaInfo from app.helper.sites import SitesHelper from app.log import logger from app.utils.string import StringUtils +from app.utils.types import MediaType class SearchChain(ChainBase): @@ -64,6 +65,7 @@ class SearchChain(ChainBase): logger.warn(f'{keyword or mediainfo.title} 未搜索到资源') return [] # 过滤种子 + logger.info(f'开始过滤资源,当前规则:{settings.FILTER_RULE} ...') result: List[TorrentInfo] = self.filter_torrents(torrent_list=torrents, season_episodes=season_episodes) if result is not None: @@ -72,6 +74,7 @@ class SearchChain(ChainBase): logger.warn(f'{keyword or mediainfo.title} 没有符合过滤条件的资源') return [] # 过滤不匹配的资源 + logger.info(f'开始匹配,总 {len(torrents)} 个资源 ...') _match_torrents = [] if mediainfo: for torrent in torrents: @@ -84,6 +87,16 @@ class SearchChain(ChainBase): continue # 识别 torrent_meta = MetaInfo(torrent.title, torrent.description) + # 比对年份 + if torrent_meta.year and mediainfo.year: + if mediainfo.type == MediaType.TV: + # 剧集 + if torrent_meta.year not in [year for year in mediainfo.season_years.values()]: + continue + else: + # 没有季的剧集或者电影 + if torrent_meta.year != mediainfo.year: + continue # 比对标题 if torrent_meta.get_name() in [mediainfo.title, mediainfo.original_title]: logger.info(f'{mediainfo.title} 匹配到资源:{torrent.site_name} - {torrent.title}') @@ -98,6 +111,7 @@ class SearchChain(ChainBase): break else: _match_torrents = torrents + logger.info(f"匹配完成,共匹配到 {len(_match_torrents)} 个资源") # 组装上下文返回 return [Context(meta=MetaInfo(torrent.title), mediainfo=mediainfo, diff --git a/app/chain/user_message.py b/app/chain/user_message.py index f58b828c..2329d28f 100644 --- a/app/chain/user_message.py +++ b/app/chain/user_message.py @@ -105,7 +105,9 @@ class UserMessageChain(ChainBase): no_exists=no_exists) if not contexts: # 没有数据 - self.post_message(title=f"{mediainfo.title} 未搜索到资源!", userid=userid) + self.post_message(title=f"{mediainfo.title}" + f"{self._current_meta.get_season_string()} 未搜索到资源!", + userid=userid) return # 搜索结果排序 contexts = TorrentHelper.sort_torrents(contexts) diff --git a/app/core/context.py b/app/core/context.py index f76dd49f..422c69ae 100644 --- a/app/core/context.py +++ b/app/core/context.py @@ -122,6 +122,8 @@ class MediaInfo: names: Optional[list] = [] # 各季的剧集清单信息 seasons: Optional[dict] = {} + # 各季的年份 + season_years: Optional[dict] = {} # 二级分类 category: str = "" # TMDB INFO @@ -137,6 +139,7 @@ class MediaInfo: # 初始化 self.seasons = {} self.names = [] + self.season_years = {} self.directors = [] self.actors = [] self.tmdb_info = {} @@ -267,10 +270,17 @@ class MediaInfo: # 季集信息 if info.get('seasons'): for season_info in info.get('seasons'): - if not season_info.get("season_number"): + # 季 + season = season_info.get("season_number") + if not season: continue + # 集 episode_count = season_info.get("episode_count") - self.seasons[season_info.get("season_number")] = list(range(1, episode_count + 1)) + self.seasons[season] = list(range(1, episode_count + 1)) + # 年份 + air_date = season_info.get("air_date") + if air_date: + self.season_years[season] = air_date[:4] # 海报 if info.get('poster_path'): self.poster_path = f"https://{settings.TMDB_IMAGE_DOMAIN}/t/p/original{info.get('poster_path')}"