From 24b6c970aade8711897f1369b72ed2582a8454b7 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 13 Sep 2025 10:34:41 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Aemby=E7=94=A8=E6=88=B7=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/system.py | 4 ++-- app/modules/emby/emby.py | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/api/endpoints/system.py b/app/api/endpoints/system.py index 26600b65..595eeb81 100644 --- a/app/api/endpoints/system.py +++ b/app/api/endpoints/system.py @@ -142,7 +142,7 @@ async def proxy_img( cache: bool = False, if_none_match: Annotated[str | None, Header()] = None, _: schemas.TokenPayload = Depends(verify_resource_token) -) -> Optional[Response]: +) -> Response: """ 图片代理,可选是否使用代理服务器,支持 HTTP 缓存 """ @@ -159,7 +159,7 @@ async def cache_img( url: str, if_none_match: Annotated[str | None, Header()] = None, _: schemas.TokenPayload = Depends(verify_resource_token) -) -> Optional[Response]: +) -> Response: """ 本地缓存图片文件,支持 HTTP 缓存,如果启用全局图片缓存,则使用磁盘缓存 """ diff --git a/app/modules/emby/emby.py b/app/modules/emby/emby.py index a15e425d..ed2b6915 100644 --- a/app/modules/emby/emby.py +++ b/app/modules/emby/emby.py @@ -10,10 +10,10 @@ from requests import Response from app import schemas from app.core.config import settings from app.log import logger +from app.schemas import MediaServerItem from app.schemas.types import MediaType from app.utils.http import RequestUtils from app.utils.url import UrlUtils -from app.schemas import MediaServerItem class Emby: @@ -22,9 +22,10 @@ class Emby: _apikey: Optional[str] = None _sync_libraries: List[str] = [] user: Optional[Union[str, int]] = None + _username: Optional[str] = None def __init__(self, host: Optional[str] = None, apikey: Optional[str] = None, play_host: Optional[str] = None, - sync_libraries: list = None, **kwargs): + username: Optional[str] = None, sync_libraries: list = None, **kwargs): if not host or not apikey: logger.error("Emby服务器配置不完整!") return @@ -35,7 +36,8 @@ class Emby: if self._playhost: self._playhost = UrlUtils.standardize_base_url(self._playhost) self._apikey = apikey - self.user = self.get_user(settings.SUPERUSER) + self._username = username + self.user = self.get_user(username or settings.SUPERUSER) self.folders = self.get_emby_folders() self.serverid = self.get_server_id() self._sync_libraries = sync_libraries or [] @@ -139,7 +141,8 @@ class Emby: logger.error(f"连接User/Views 出错:" + str(e)) return [] - def get_librarys(self, username: Optional[str] = None, hidden: Optional[bool] = False) -> List[schemas.MediaServerLibrary]: + def get_librarys(self, username: Optional[str] = None, hidden: Optional[bool] = False) -> List[ + schemas.MediaServerLibrary]: """ 获取媒体服务器所有媒体库列表 """ @@ -567,6 +570,7 @@ class Emby: if library_id != "/": return self.__refresh_emby_library_by_id(library_id) logger.info(f"Emby媒体库刷新完成") + return True def __get_emby_library_id_by_item(self, item: schemas.RefreshMediaItem) -> Optional[str]: """ @@ -706,9 +710,9 @@ class Emby: yield items elif item.get("Type") in ["Movie", "Series"]: yield self.__format_item_info(item) - except Exception as e: logger.error(f"连接Users/Items出错:" + str(e)) + return None def get_webhook_message(self, form: any, args: dict) -> Optional[schemas.WebhookEventInfo]: """ @@ -1109,7 +1113,8 @@ class Emby: return "" return "%sItems/%s/Images/Primary" % (self._host, item_id) - def get_resume(self, num: Optional[int] = 12, username: Optional[str] = None) -> Optional[List[schemas.MediaServerPlayItem]]: + def get_resume(self, num: Optional[int] = 12, username: Optional[str] = None) -> Optional[ + List[schemas.MediaServerPlayItem]]: """ 获得继续观看 """ @@ -1178,7 +1183,8 @@ class Emby: logger.error(f"连接Users/Items/Resume出错:" + str(e)) return [] - def get_latest(self, num: Optional[int] = 20, username: Optional[str] = None) -> Optional[List[schemas.MediaServerPlayItem]]: + def get_latest(self, num: Optional[int] = 20, username: Optional[str] = None) -> Optional[ + List[schemas.MediaServerPlayItem]]: """ 获得最近更新 """