Skip to content

Commit

Permalink
fix #2751
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinityPacer committed Sep 26, 2024
1 parent ddfcdf9 commit e1aa4b7
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions app/modules/plex/plex.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from pathlib import Path
from typing import List, Optional, Dict, Tuple, Generator, Any
from typing import List, Optional, Dict, Tuple, Generator, Any, Union
from urllib.parse import quote_plus

from cachetools import TTLCache, cached
Expand All @@ -9,7 +9,6 @@
from requests import Response, Session

from app import schemas
from app.core.config import settings
from app.log import logger
from app.schemas import MediaType
from app.utils.http import RequestUtils
Expand Down Expand Up @@ -238,7 +237,7 @@ def get_tv_episodes(self,
if not self._plex:
return None, {}
if item_id:
videos = self._plex.fetchItem(int(item_id))
videos = self.__fetch_item(item_id)
else:
# 兼容年份为空的场景
kwargs = {"year": year} if year else {}
Expand Down Expand Up @@ -274,7 +273,7 @@ def get_tv_episodes(self,
def get_remote_image_by_id(self, item_id: str, image_type: str, depth: int = 0) -> Optional[str]:
"""
根据ItemId从Plex查询图片地址
:param item_id: 在Emby中的ID
:param item_id: 在Plex中的ID
:param image_type: 图片的类型,Poster或者Backdrop等
:param depth: 当前递归深度,默认为0
:return: 图片对应在TMDB中的URL
Expand Down Expand Up @@ -392,7 +391,7 @@ def get_iteminfo(self, itemid: str) -> Optional[schemas.MediaServerItem]:
if not self._plex:
return None
try:
item = self._plex.fetchItem(int(itemid))
item = self.__fetch_item(itemid)
ids = self.__get_ids(item.guids)
path = None
if item.locations:
Expand Down Expand Up @@ -446,6 +445,15 @@ def parse_tmdb_id(value: str) -> (bool, int):

return ids

def __fetch_item(self, item_id: Union[int, str]):
"""
根据给定的item_id获取媒体项
:param item_id: 媒体项的ID,可以是整数或字符串,如果是字符串且表示为数字,将会被转换为整数
"""
if isinstance(item_id, str) and item_id.isdigit():
item_id = int(item_id)
return self._plex.fetchItem(item_id)

def get_items(self, parent: str, start_index: int = 0, limit: int = 100) -> Generator:
"""
获取媒体服务器所有媒体库列表
Expand Down

0 comments on commit e1aa4b7

Please sign in to comment.