mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
fix: 清理音乐刮削结果中 album_type 等字段的尾部空格 (#6327)
MusicBrainz 和 ListenBrainz 模块从 API 响应中提取 album_type、 secondary_types 时直接使用 dict.get() 取值,未做 strip() 处理, 导致部分结果带有尾部空格(如 'Album '、'Broadcast ')。 修复: - MusicBrainz 新增 _stripped() 工具方法,3 处 album_type 赋值统一清理 - ListenBrainz 新增 _stripped() 工具方法,_fresh_release_to_info 中清理 - Pydantic schema 层增加 field_validator 作为兜底安全网 - 新增 9 个回归测试覆盖所有场景
This commit is contained in:
+13
-1
@@ -1,6 +1,6 @@
|
||||
from typing import Literal, Optional, Union
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
from app.schemas.common import JsonData
|
||||
from app.schemas.media import OptionalMediaIdentityMixin, RequiredMediaIdentityMixin
|
||||
@@ -83,6 +83,12 @@ class MusicInfo(OptionalMediaIdentityMixin, BaseModel):
|
||||
overview: Optional[str] = None
|
||||
vote_average: float = 0.0
|
||||
|
||||
@field_validator("album_type", mode="before")
|
||||
@classmethod
|
||||
def _strip_album_type(cls, v: Optional[str]) -> Optional[str]:
|
||||
"""去除专辑类型字段两端的空白,防止数据源返回带空格的值。"""
|
||||
return v.strip() if isinstance(v, str) and v.strip() else None
|
||||
|
||||
def __getattr__(self, name: str) -> None:
|
||||
"""影视专用字段兜底返回 None:音乐模型不存在这些字段,避免下游逐点安全访问。
|
||||
|
||||
@@ -144,6 +150,12 @@ class MusicAlbumInfo(OptionalMediaIdentityMixin, BaseModel):
|
||||
overview: Optional[str] = None
|
||||
vote_average: float = 0.0
|
||||
|
||||
@field_validator("album_type", mode="before")
|
||||
@classmethod
|
||||
def _strip_album_type(cls, v: Optional[str]) -> Optional[str]:
|
||||
"""去除专辑类型字段两端的空白,防止数据源返回带空格的值。"""
|
||||
return v.strip() if isinstance(v, str) and v.strip() else None
|
||||
|
||||
|
||||
class MusicArtistInfo(OptionalMediaIdentityMixin, BaseModel):
|
||||
"""标准化音乐艺术家信息。"""
|
||||
|
||||
Reference in New Issue
Block a user