mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-21 00:07:32 +08:00
feat: 统一音乐识别与影视共享上报,优化相关参数处理
This commit is contained in:
@@ -14,7 +14,7 @@ from transmission_rpc import File
|
||||
|
||||
from app.core.cache import FileCache, AsyncFileCache, fresh, async_fresh
|
||||
from app.core.config import settings
|
||||
from app.core.context import Context, MediaInfo, MusicInfo, SubtitleInfo, TorrentInfo
|
||||
from app.core.context import Context, MediaInfo, SubtitleInfo, TorrentInfo
|
||||
from app.core.event import EventManager
|
||||
from app.core.meta import MetaBase
|
||||
from app.core.module import ModuleManager
|
||||
@@ -705,10 +705,8 @@ class ChainBase(metaclass=ABCMeta):
|
||||
**module_kwargs,
|
||||
)
|
||||
if mediainfo:
|
||||
# 音乐识别结果不参与影视共享上报
|
||||
if isinstance(mediainfo, MusicInfo):
|
||||
return mediainfo
|
||||
if not mediainfo.recognize_cache_hit:
|
||||
# 电影、电视剧、音乐统一上报;音乐的 tmdb 等字段恒为 None,身份取数据源原生 ID
|
||||
if not getattr(mediainfo, "recognize_cache_hit", False):
|
||||
MoviePilotServerHelper.report_recognize_share(
|
||||
meta=meta,
|
||||
mediainfo=mediainfo,
|
||||
@@ -716,7 +714,7 @@ class ChainBase(metaclass=ABCMeta):
|
||||
)
|
||||
return mediainfo
|
||||
|
||||
if not source and mtype != MediaType.MUSIC and self._can_use_media_recognize_share(
|
||||
if not source and self._can_use_media_recognize_share(
|
||||
share_query_meta, tmdbid, doubanid, bangumiid, anilistid
|
||||
):
|
||||
shared_cache_meta = self._snapshot_recognize_cache_meta(meta)
|
||||
@@ -818,10 +816,8 @@ class ChainBase(metaclass=ABCMeta):
|
||||
**module_kwargs,
|
||||
)
|
||||
if mediainfo:
|
||||
# 音乐识别结果不参与影视共享上报
|
||||
if isinstance(mediainfo, MusicInfo):
|
||||
return mediainfo
|
||||
if not mediainfo.recognize_cache_hit:
|
||||
# 电影、电视剧、音乐统一上报;音乐的 tmdb 等字段恒为 None,身份取数据源原生 ID
|
||||
if not getattr(mediainfo, "recognize_cache_hit", False):
|
||||
await MoviePilotServerHelper.async_report_recognize_share(
|
||||
meta=meta,
|
||||
mediainfo=mediainfo,
|
||||
@@ -829,7 +825,7 @@ class ChainBase(metaclass=ABCMeta):
|
||||
)
|
||||
return mediainfo
|
||||
|
||||
if not source and mtype != MediaType.MUSIC and self._can_use_media_recognize_share(
|
||||
if not source and self._can_use_media_recognize_share(
|
||||
share_query_meta, tmdbid, doubanid, bangumiid, anilistid
|
||||
):
|
||||
shared_cache_meta = self._snapshot_recognize_cache_meta(meta)
|
||||
|
||||
@@ -2,12 +2,12 @@ import json
|
||||
import platform
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
from urllib.parse import parse_qs, quote, urlparse, urlsplit
|
||||
|
||||
from app.core.cache import cached
|
||||
from app.core.config import settings
|
||||
from app.core.context import MediaInfo
|
||||
from app.core.context import MediaInfo, MusicInfo
|
||||
from app.core.meta import MetaBase
|
||||
from app.db.subscribe_oper import SubscribeOper
|
||||
from app.db.systemconfig_oper import SystemConfigOper
|
||||
@@ -1366,11 +1366,11 @@ class MoviePilotServerHelper:
|
||||
def report_recognize_share(
|
||||
cls,
|
||||
meta: Optional[MetaBase],
|
||||
mediainfo: Optional[MediaInfo],
|
||||
mediainfo: Optional[Union[MediaInfo, MusicInfo]],
|
||||
keyword_meta: Optional[MetaBase] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
上报共享识别结果。
|
||||
上报共享识别结果,电影、电视剧、音乐共用。
|
||||
"""
|
||||
if not settings.MEDIA_RECOGNIZE_SHARE:
|
||||
return False
|
||||
@@ -1388,11 +1388,11 @@ class MoviePilotServerHelper:
|
||||
async def async_report_recognize_share(
|
||||
cls,
|
||||
meta: Optional[MetaBase],
|
||||
mediainfo: Optional[MediaInfo],
|
||||
mediainfo: Optional[Union[MediaInfo, MusicInfo]],
|
||||
keyword_meta: Optional[MetaBase] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
异步上报共享识别结果。
|
||||
异步上报共享识别结果,电影、电视剧、音乐共用。
|
||||
"""
|
||||
if not settings.MEDIA_RECOGNIZE_SHARE:
|
||||
return False
|
||||
@@ -1409,7 +1409,7 @@ class MoviePilotServerHelper:
|
||||
@classmethod
|
||||
def to_recognize_params(cls, item: Optional[dict]) -> Optional[dict]:
|
||||
"""
|
||||
将服务端返回的共享识别结果转成本地识别参数。
|
||||
将服务端返回的共享识别结果转成本地识别参数,音乐仅携带数据源原生 ID。
|
||||
"""
|
||||
if not isinstance(item, dict):
|
||||
return None
|
||||
@@ -1461,13 +1461,15 @@ class MoviePilotServerHelper:
|
||||
统一媒体类型,兼容枚举、中文值和 agent 风格字符串。
|
||||
"""
|
||||
normalized = media_type_to_agent(media_type)
|
||||
if normalized in {"movie", "tv"}:
|
||||
if normalized in {"movie", "tv", "music"}:
|
||||
return normalized
|
||||
if isinstance(media_type, str):
|
||||
if media_type == MediaType.MOVIE.value:
|
||||
return "movie"
|
||||
if media_type == MediaType.TV.value:
|
||||
return "tv"
|
||||
if media_type == MediaType.MUSIC.value:
|
||||
return "music"
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
@@ -1495,9 +1497,10 @@ class MoviePilotServerHelper:
|
||||
media_type = cls._normalize_media_type(mtype)
|
||||
if media_type:
|
||||
return media_type
|
||||
if mediainfo and mediainfo.type in {MediaType.MOVIE, MediaType.TV}:
|
||||
shareable_types = {MediaType.MOVIE, MediaType.TV, MediaType.MUSIC}
|
||||
if mediainfo and mediainfo.type in shareable_types:
|
||||
return mediainfo.type.to_agent()
|
||||
if meta and meta.type in {MediaType.MOVIE, MediaType.TV}:
|
||||
if meta and meta.type in shareable_types:
|
||||
return meta.type.to_agent()
|
||||
if meta and (meta.begin_season is not None or meta.begin_episode is not None):
|
||||
return "tv"
|
||||
@@ -1566,11 +1569,11 @@ class MoviePilotServerHelper:
|
||||
def _build_recognize_report_payload(
|
||||
cls,
|
||||
meta: Optional[MetaBase],
|
||||
mediainfo: Optional[MediaInfo],
|
||||
mediainfo: Optional[Union[MediaInfo, MusicInfo]],
|
||||
keyword_meta: Optional[MetaBase] = None,
|
||||
) -> Optional[dict]:
|
||||
"""
|
||||
组装共享识别上报载荷。
|
||||
组装共享识别上报载荷,电影、电视剧、音乐共用同一结构。
|
||||
"""
|
||||
if not meta or not mediainfo:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user