From f73750fcf7d89cd4c665d7effeec1d5835f7eff6 Mon Sep 17 00:00:00 2001 From: amtoaer Date: Thu, 7 Nov 2024 15:01:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BA=20jellyfin=20=E7=9A=84=20webh?= =?UTF-8?q?ook=20=E4=BA=8B=E4=BB=B6=E5=A1=AB=E5=85=85=20item=5Fpath=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/jellyfin/jellyfin.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/modules/jellyfin/jellyfin.py b/app/modules/jellyfin/jellyfin.py index e84d4ac4..11c417ad 100644 --- a/app/modules/jellyfin/jellyfin.py +++ b/app/modules/jellyfin/jellyfin.py @@ -468,6 +468,30 @@ class Jellyfin: return None return None + def get_item_path_by_id(self, item_id: str) -> Optional[str]: + """ + 根据ItemId查询所在的Path + :param item_id: 在Jellyfin中的ID + :return: Path + """ + if not self._host or not self._apikey: + return None + url = f"{self._host}Items/{item_id}/PlaybackInfo" + params = {"api_key": self._apikey} + try: + res = RequestUtils(timeout=10).get_res(url, params) + if res: + media_sources = res.json().get("MediaSources") + if media_sources: + return media_sources[0].get("Path") + else: + logger.error("Items/Id/PlaybackInfo 未获取到返回数据,不设置 Path") + return None + except Exception as e: + logger.error("连接Items/Id/PlaybackInfo出错:" + str(e)) + return None + return None + def generate_image_link(self, item_id: str, image_type: str, host_type: bool) -> Optional[str]: """ 根据ItemId和imageType查询本地对应图片 @@ -662,6 +686,8 @@ class Jellyfin: item_id=eventItem.item_id, image_type="Backdrop" ) + # jellyfin 的 webhook 不含 item_path,需要单独获取 + eventItem.item_path = self.get_item_path_by_id(eventItem.item_id) return eventItem