This commit is contained in:
jxxghp
2025-06-03 08:19:15 +08:00
parent fb2b29d088
commit 9d436ec7ed
3 changed files with 18 additions and 12 deletions

View File

@@ -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(

View File

@@ -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

View File

@@ -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 = ""
# 重启自动升级