mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-03 22:04:57 +08:00
fix(schemas): 规范 import 格式并简化 MetaInfo 属性定义
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
from typing import Annotated, Any, Dict, List, Optional, Union
|
||||
|
||||
from pydantic import BaseModel, Discriminator, Field, PrivateAttr as _PrivateAttr, RootModel, Tag, model_validator
|
||||
from pydantic import BaseModel, Discriminator, Field, RootModel, Tag, model_validator
|
||||
|
||||
from app.schemas.category import ClassificationFactValue, ClassificationResult
|
||||
from app.schemas.common import JsonData
|
||||
from app.schemas.media import OptionalMediaIdentityMixin
|
||||
from app.schemas.music import MusicArtistInfo as _MusicArtistInfo
|
||||
from app.schemas.music import MusicInfo, MusicMeta
|
||||
from app.schemas.types import MediaSource, MediaType as _MediaType
|
||||
from app.schemas.types import MediaSource
|
||||
from app.schemas.types import MediaType as _MediaType
|
||||
|
||||
|
||||
class MetaInfo(OptionalMediaIdentityMixin, BaseModel):
|
||||
@@ -75,25 +76,9 @@ class MetaInfo(OptionalMediaIdentityMixin, BaseModel):
|
||||
# 显式媒体数据源原生ID
|
||||
media_id: Optional[str] = None
|
||||
|
||||
_season_list: Optional[List[int]] = _PrivateAttr(default=None)
|
||||
|
||||
@model_validator(mode="wrap")
|
||||
@classmethod
|
||||
def _handle_season_list(cls, data: Any, handler: Any) -> "MetaInfo":
|
||||
season_list = None
|
||||
if isinstance(data, dict) and "season_list" in data:
|
||||
data = data.copy()
|
||||
season_list = data.pop("season_list")
|
||||
instance = handler(data)
|
||||
if season_list is not None and isinstance(instance, MetaInfo):
|
||||
instance._season_list = list(season_list)
|
||||
return instance
|
||||
|
||||
@property
|
||||
def season_list(self) -> List[int]:
|
||||
"""返回识别的季数字列表。"""
|
||||
if self._season_list is not None:
|
||||
return self._season_list
|
||||
if self.begin_season is None:
|
||||
if self.type in (_MediaType.TV, _MediaType.TV.value):
|
||||
return [1]
|
||||
@@ -102,10 +87,6 @@ class MetaInfo(OptionalMediaIdentityMixin, BaseModel):
|
||||
return list(range(self.begin_season, self.end_season + 1))
|
||||
return [self.begin_season]
|
||||
|
||||
@season_list.setter
|
||||
def season_list(self, value: Optional[List[int]]) -> None:
|
||||
self._season_list = list(value) if value is not None else None
|
||||
|
||||
@property
|
||||
def season(self) -> str:
|
||||
"""返回开始季、结束季字符串,确定是剧集没有季的返回S01。"""
|
||||
|
||||
@@ -77,14 +77,3 @@ def test_schema_metainfo_season_and_episode_properties() -> None:
|
||||
assert movie.season == ""
|
||||
assert movie.season_seq == ""
|
||||
assert movie.episode == ""
|
||||
|
||||
# 显式覆盖与字典解析
|
||||
custom = MetaInfo(season_list=[0])
|
||||
assert custom.season_list == [0]
|
||||
|
||||
from_dict = MetaInfo.model_validate({"season_list": [2, 4], "type": "电视剧"})
|
||||
assert from_dict.season_list == [2, 4]
|
||||
|
||||
# setter 覆写
|
||||
tv_no_season.season_list = [5]
|
||||
assert tv_no_season.season_list == [5]
|
||||
|
||||
@@ -253,15 +253,21 @@ def test_workflow_manager_list_actions_exposes_contract():
|
||||
|
||||
def test_add_download_only_lack_handles_schema_metainfo(monkeypatch):
|
||||
"""添加下载动作开启仅下载缺失资源时应支持 Schema MetaInfo 的 season_list 属性并正确过滤已存在剧集。"""
|
||||
import app.workflow.actions.add_download as add_download_module
|
||||
from app.schemas.context import (
|
||||
Context as SchemaContext,
|
||||
)
|
||||
from app.schemas.context import (
|
||||
MediaInfo as SchemaMediaInfo,
|
||||
)
|
||||
from app.schemas.context import (
|
||||
MetaInfo as SchemaMetaInfo,
|
||||
)
|
||||
from app.schemas.context import (
|
||||
TorrentInfo as SchemaTorrentInfo,
|
||||
)
|
||||
from app.schemas.types import MediaType
|
||||
from app.workflow.actions.add_download import AddDownloadAction
|
||||
import app.workflow.actions.add_download as add_download_module
|
||||
|
||||
downloaded = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user