mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
feat(subscribe): record episode download facts (#6015)
This commit is contained in:
+34
-20
@@ -5,6 +5,39 @@ from pydantic import BaseModel, Field, ConfigDict, model_validator
|
||||
from app.schemas.types import MediaType
|
||||
|
||||
|
||||
def compute_subscribe_completed_episode(subscribe: Any) -> Optional[int]:
|
||||
"""
|
||||
计算订阅"已完成"集数派生值,仅用于响应填充,不入库。
|
||||
|
||||
普通电视剧按 ``total_episode - lack_episode`` 计算;洗版电视剧按订阅目标范围内
|
||||
priority==100 的分集数量,加上起始集前的逻辑完成集数计算。
|
||||
"""
|
||||
total_episode = getattr(subscribe, "total_episode", None) or 0
|
||||
if getattr(subscribe, "type", None) != MediaType.TV.value or not total_episode:
|
||||
return None
|
||||
|
||||
start_episode = getattr(subscribe, "start_episode", None) or 1
|
||||
if not getattr(subscribe, "best_version", None):
|
||||
lack = getattr(subscribe, "lack_episode", None) or 0
|
||||
return max(total_episode - lack, 0)
|
||||
|
||||
episode_priority = getattr(subscribe, "episode_priority", None) or {}
|
||||
if not episode_priority and getattr(subscribe, "current_priority", None) is not None:
|
||||
# 兼容只有整体优先级的洗版快照,响应派生值需与链路侧按集口径保持一致。
|
||||
episode_priority = {
|
||||
str(episode): int(getattr(subscribe, "current_priority"))
|
||||
for episode in range(start_episode, total_episode + 1)
|
||||
}
|
||||
priority_completed = sum(
|
||||
1
|
||||
for ep_key, priority in episode_priority.items()
|
||||
if str(ep_key).isdigit()
|
||||
and start_episode <= int(ep_key) <= total_episode
|
||||
and priority == 100
|
||||
)
|
||||
return min(max(start_episode - 1, 0), total_episode) + priority_completed
|
||||
|
||||
|
||||
class Subscribe(BaseModel):
|
||||
id: Optional[int] = None
|
||||
# 订阅名称
|
||||
@@ -95,26 +128,7 @@ class Subscribe(BaseModel):
|
||||
if self.completed_episode is not None:
|
||||
# 调用方显式提供过的值不覆盖
|
||||
return self
|
||||
total_episode = self.total_episode or 0
|
||||
if self.type != MediaType.TV.value or not total_episode:
|
||||
return self
|
||||
start_episode = self.start_episode or 1
|
||||
if not self.best_version:
|
||||
lack = self.lack_episode or 0
|
||||
self.completed_episode = max(total_episode - lack, 0)
|
||||
return self
|
||||
# 洗版口径:起始集前视为逻辑完成 + [start, total] 范围内 priority==100 命中。
|
||||
# ``start_episode > total_episode`` 属于异常配置,需把 "起始集前" 偏移截断到 total,
|
||||
# 防止 completed_episode 越过分母 total_episode。
|
||||
episode_priority = self.episode_priority or {}
|
||||
priority_completed = sum(
|
||||
1
|
||||
for ep_key, priority in episode_priority.items()
|
||||
if str(ep_key).isdigit()
|
||||
and start_episode <= int(ep_key) <= total_episode
|
||||
and priority == 100
|
||||
)
|
||||
self.completed_episode = min(max(start_episode - 1, 0), total_episode) + priority_completed
|
||||
self.completed_episode = compute_subscribe_completed_episode(self)
|
||||
return self
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user