From 9d436ec7ed292e35c4e22a018d5739419a8d1d43 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 3 Jun 2025 08:19:15 +0800 Subject: [PATCH] fix #4382 --- app/chain/download.py | 10 +++++++--- app/chain/subscribe.py | 16 +++++++++------- app/core/config.py | 4 ++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/chain/download.py b/app/chain/download.py index 71dcc3f7..825b2a32 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -19,8 +19,10 @@ from app.helper.directory import DirectoryHelper from app.helper.message import MessageHelper from app.helper.torrent import TorrentHelper from app.log import logger -from app.schemas import ExistMediaInfo, NotExistMediaInfo, DownloadingTorrent, Notification, ResourceSelectionEventData, ResourceDownloadEventData -from app.schemas.types import MediaType, TorrentStatus, EventType, MessageChannel, NotificationType, ContentType, ChainEventType +from app.schemas import ExistMediaInfo, NotExistMediaInfo, DownloadingTorrent, Notification, ResourceSelectionEventData, \ + ResourceDownloadEventData +from app.schemas.types import MediaType, TorrentStatus, EventType, MessageChannel, NotificationType, ContentType, \ + ChainEventType from app.utils.http import RequestUtils from app.utils.string import StringUtils @@ -450,6 +452,7 @@ class DownloadChain(ChainBase): if not no_exist.get(season): return 9999 return no_exist[season].total_episode + def _calculate_intersection_ratio(episodes_set: set, target_set: set) -> Tuple[float, set]: """ 计算种子与目标缺失集之间的交集比例。 @@ -462,6 +465,7 @@ class DownloadChain(ChainBase): return 0.0, set() cal_ratio = len(cal_intersection) / len(episodes_set) return cal_ratio, cal_intersection + # 发送资源选择事件,允许外部修改上下文数据 logger.debug(f"Initial contexts: {len(contexts)} items, Downloader: {downloader}") event_data = ResourceSelectionEventData( @@ -651,7 +655,7 @@ class DownloadChain(ChainBase): # 计算交集 # 若种子[5-10],[7-10],[9-10] need_episodes=[9,10,11,12,13,14] # 计算后的交集比例( len(torrent_episodes ∩ need_episodes) / len(torrent_episodes) )分别 0.33 0.66 1.0 - ratio, intersection = _calculate_intersection_ratio(torrent_episodes,set(need_episodes)) + ratio, intersection = _calculate_intersection_ratio(torrent_episodes, set(need_episodes)) if ratio <= (settings.EPISODE_INTERSECTION_MIN_CONFIDENCE or 0.05): # 可以设定阈值 logger.info( diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index e9b43a5c..8ca55bff 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -569,15 +569,14 @@ class SubscribeChain(ChainBase, metaclass=Singleton): for context in contexts: # 复制上下文避免修改原始数据 _context = copy.deepcopy(context) - torrent_meta = _context.meta_info - torrent_mediainfo = _context.media_info - # 如果种子未识别,尝试识别 - if not torrent_mediainfo or (not torrent_mediainfo.tmdb_id and not torrent_mediainfo.douban_id): - torrent_mediainfo = self.recognize_media(meta=torrent_meta) - if torrent_mediainfo: + if not _context.media_info or (not _context.media_info.tmdb_id + and not _context.media_info.douban_id): + re_mediainfo = self.recognize_media(meta=_context.meta_info) + if re_mediainfo: # 更新种子缓存 - context.media_info = torrent_mediainfo + _context.media_info = re_mediainfo + context.media_info = re_mediainfo # 添加已预处理 processed_torrents[domain].append(_context) @@ -657,12 +656,14 @@ class SubscribeChain(ChainBase, metaclass=Singleton): torrent_meta = MetaInfo(title=torrent_info.title, subtitle=torrent_info.description, custom_words=custom_words_list) # 更新元数据缓存 + _context.meta_info = torrent_meta context.meta_info = torrent_meta # 重新识别媒体信息 torrent_mediainfo = self.recognize_media(meta=torrent_meta, episode_group=subscribe.episode_group) if torrent_mediainfo: # 更新种子缓存 + _context.media_info = torrent_mediainfo context.media_info = torrent_mediainfo # 如果仍然没有识别到媒体信息,尝试标题匹配 @@ -677,6 +678,7 @@ class SubscribeChain(ChainBase, metaclass=Singleton): f'{mediainfo.title_year} 通过标题匹配到可选资源:{torrent_info.site_name} - {torrent_info.title}') torrent_mediainfo = mediainfo # 更新种子缓存 + _context.media_info = mediainfo context.media_info = mediainfo else: continue diff --git a/app/core/config.py b/app/core/config.py index 6537de3c..2eb38dcf 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -6,7 +6,7 @@ import secrets import sys import threading from pathlib import Path -from typing import Any, Dict, List, Optional, Tuple, Type, Union +from typing import Any, Dict, List, Optional, Tuple, Type from dotenv import set_key from pydantic import BaseModel, BaseSettings, validator, Field @@ -124,7 +124,7 @@ class ConfigModel(BaseModel): # 元数据识别缓存过期时间(小时) META_CACHE_EXPIRE: int = 0 # 电视剧动漫的分类genre_ids - ANIME_GENREIDS: list[int] = [16] + ANIME_GENREIDS: List[int] = [16] # 用户认证站点 AUTH_SITE: str = "" # 重启自动升级