mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
refactor(media): unify source identity and music browsing
This commit is contained in:
+21
-16
@@ -9,10 +9,10 @@ from requests import Response
|
||||
|
||||
from app import schemas
|
||||
from app.core.config import settings
|
||||
from app.helper.mediaserver import MusicMediaServerHelper
|
||||
from app.helper.mediaserver import MediaServerIdentityHelper, MusicMediaServerHelper
|
||||
from app.log import logger
|
||||
from app.schemas import MediaServerItem
|
||||
from app.schemas.types import MediaType
|
||||
from app.schemas.types import MediaSource, MediaType
|
||||
from app.utils.http import RequestUtils
|
||||
from app.utils.url import UrlUtils
|
||||
|
||||
@@ -380,12 +380,14 @@ class Emby:
|
||||
def get_movies(self,
|
||||
title: str,
|
||||
year: Optional[str] = None,
|
||||
tmdb_id: Optional[int] = None) -> Optional[List[schemas.MediaServerItem]]:
|
||||
media_source: Optional[MediaSource] = None,
|
||||
media_id: Optional[str] = None) -> Optional[List[schemas.MediaServerItem]]:
|
||||
"""
|
||||
根据标题和年份,检查电影是否在Emby中存在,存在则返回列表
|
||||
:param title: 标题
|
||||
:param year: 年份,可以为空,为空时不按年份过滤
|
||||
:param tmdb_id: TMDB ID
|
||||
:param media_source: 媒体来源
|
||||
:param media_id: 媒体来源原生ID
|
||||
:return: 含title、year属性的字典列表
|
||||
"""
|
||||
if not self._host or not self._apikey:
|
||||
@@ -412,7 +414,9 @@ class Emby:
|
||||
continue
|
||||
mediaserver_item = self.__format_item_info(item)
|
||||
if mediaserver_item:
|
||||
if (not tmdb_id or mediaserver_item.tmdbid == tmdb_id) and \
|
||||
if MediaServerIdentityHelper.is_compatible(
|
||||
mediaserver_item, media_source, media_id
|
||||
) and \
|
||||
mediaserver_item.title == title and \
|
||||
(not year or str(mediaserver_item.year) == str(year)):
|
||||
ret_movies.append(mediaserver_item)
|
||||
@@ -454,7 +458,8 @@ class Emby:
|
||||
item_id: Optional[str] = None,
|
||||
title: Optional[str] = None,
|
||||
year: Optional[str] = None,
|
||||
tmdb_id: Optional[int] = None,
|
||||
media_source: Optional[MediaSource] = None,
|
||||
media_id: Optional[str] = None,
|
||||
season: Optional[int] = None
|
||||
) -> Tuple[Optional[str], Optional[Dict[int, List[int]]]]:
|
||||
"""
|
||||
@@ -462,7 +467,8 @@ class Emby:
|
||||
:param item_id: Emby中的ID
|
||||
:param title: 标题
|
||||
:param year: 年份
|
||||
:param tmdb_id: TMDBID
|
||||
:param media_source: 媒体来源
|
||||
:param media_id: 媒体来源原生ID
|
||||
:param season: 季
|
||||
:return: 每一季的已有集数
|
||||
"""
|
||||
@@ -476,7 +482,7 @@ class Emby:
|
||||
return None, None
|
||||
if not item_id:
|
||||
return None, {}
|
||||
# 验证tmdbid是否相同
|
||||
# 校验媒体服务器返回的主身份是否与目标冲突
|
||||
item_info = self.get_iteminfo(item_id)
|
||||
if not item_info and cached_item_id and title:
|
||||
# 媒体删除后重新入库会导致缓存ID失效,回退到标题搜索避免误判整部剧缺失。
|
||||
@@ -489,10 +495,8 @@ class Emby:
|
||||
item_info = self.get_iteminfo(item_id)
|
||||
if not item_info:
|
||||
return None, {}
|
||||
if item_info:
|
||||
if tmdb_id and item_info.tmdbid:
|
||||
if str(tmdb_id) != str(item_info.tmdbid):
|
||||
return None, {}
|
||||
if not MediaServerIdentityHelper.is_compatible(item_info, media_source, media_id):
|
||||
return None, {}
|
||||
# 查集的信息
|
||||
if season is None:
|
||||
season = None
|
||||
@@ -740,7 +744,9 @@ class Emby:
|
||||
play_count=item.get("UserData", {}).get("PlayCount"),
|
||||
percentage=item.get("UserData", {}).get("PlayedPercentage"),
|
||||
)
|
||||
tmdbid = item.get("ProviderIds", {}).get("Tmdb")
|
||||
media_source, media_id = MediaServerIdentityHelper.from_provider_ids(
|
||||
item.get("ProviderIds")
|
||||
)
|
||||
return schemas.MediaServerItem(
|
||||
server="emby",
|
||||
library=item.get("ParentId"),
|
||||
@@ -750,9 +756,8 @@ class Emby:
|
||||
title=item.get("Name"),
|
||||
original_title=item.get("OriginalTitle"),
|
||||
year=item.get("ProductionYear"),
|
||||
tmdbid=int(tmdbid) if tmdbid else None,
|
||||
imdbid=item.get("ProviderIds", {}).get("Imdb"),
|
||||
tvdbid=item.get("ProviderIds", {}).get("Tvdb"),
|
||||
media_source=media_source,
|
||||
media_id=media_id,
|
||||
path=item.get("Path"),
|
||||
note=MusicMediaServerHelper.build_note(item)
|
||||
if item.get("Type") in {"MusicAlbum", "Audio"} else None,
|
||||
|
||||
Reference in New Issue
Block a user