Skip to content

Commit

Permalink
fix bug #2993
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Nov 5, 2024
1 parent 656cc1f commit 08aa5fe
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 91 deletions.
60 changes: 30 additions & 30 deletions app/modules/emby/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ def media_statistic(self, server: str = None) -> Optional[List[schemas.Statistic
媒体数量统计
"""
if server:
server: Emby = self.get_instance(server)
if not server:
server_obj: Emby = self.get_instance(server)
if not server_obj:
return None
servers = [server]
servers = [server_obj]
else:
servers = self.get_instances().values()
media_statistics = []
Expand All @@ -205,9 +205,9 @@ def mediaserver_librarys(self, server: str,
"""
媒体库列表
"""
server: Emby = self.get_instance(server)
if server:
return server.get_librarys(username=username, hidden=hidden)
server_obj: Emby = self.get_instance(server)
if server_obj:
return server_obj.get_librarys(username=username, hidden=hidden)
return None

def mediaserver_items(self, server: str, library_id: Union[str, int], start_index: int = 0,
Expand All @@ -222,29 +222,29 @@ def mediaserver_items(self, server: str, library_id: Union[str, int], start_inde
:return: 返回一个生成器对象,用于逐步获取媒体服务器中的项目
"""
server: Emby = self.get_instance(server)
if server:
return server.get_items(library_id, start_index, limit)
server_obj: Emby = self.get_instance(server)
if server_obj:
return server_obj.get_items(library_id, start_index, limit)
return None

def mediaserver_iteminfo(self, server: str, item_id: str) -> Optional[schemas.MediaServerItem]:
"""
媒体库项目详情
"""
server: Emby = self.get_instance(server)
if server:
return server.get_iteminfo(item_id)
server_obj: Emby = self.get_instance(server)
if server_obj:
return server_obj.get_iteminfo(item_id)
return None

def mediaserver_tv_episodes(self, server: str,
item_id: Union[str, int]) -> Optional[List[schemas.MediaServerSeasonInfo]]:
"""
获取剧集信息
"""
server: Emby = self.get_instance(server)
if not server:
server_obj: Emby = self.get_instance(server)
if not server_obj:
return None
_, seasoninfo = server.get_tv_episodes(item_id=item_id)
_, seasoninfo = server_obj.get_tv_episodes(item_id=item_id)
if not seasoninfo:
return []
return [schemas.MediaServerSeasonInfo(
Expand All @@ -257,29 +257,29 @@ def mediaserver_playing(self, server: str,
"""
获取媒体服务器正在播放信息
"""
server: Emby = self.get_instance(server)
if not server:
server_obj: Emby = self.get_instance(server)
if not server_obj:
return []
return server.get_resume(num=count, username=username)
return server_obj.get_resume(num=count, username=username)

def mediaserver_play_url(self, server: str, item_id: Union[str, int]) -> Optional[str]:
"""
获取媒体库播放地址
"""
server: Emby = self.get_instance(server)
if not server:
server_obj: Emby = self.get_instance(server)
if not server_obj:
return None
return server.get_play_url(item_id)
return server_obj.get_play_url(item_id)

def mediaserver_latest(self, server: str,
def mediaserver_latest(self, server: str = None,
count: int = 20, username: str = None) -> List[schemas.MediaServerPlayItem]:
"""
获取媒体服务器最新入库条目
"""
server: Emby = self.get_instance(server)
if not server:
server_obj: Emby = self.get_instance(server)
if not server_obj:
return []
return server.get_latest(num=count, username=username)
return server_obj.get_latest(num=count, username=username)

def mediaserver_latest_images(self,
server: str = None,
Expand All @@ -296,18 +296,18 @@ def mediaserver_latest_images(self,
:param host_type: True为外网链接, False为内网链接
:return: 图片链接列表
"""
server: Emby = self.get_instance(server)
if not server:
server_obj: Emby = self.get_instance(server)
if not server_obj:
return []

links = []
items: List[schemas.MediaServerPlayItem] = self.mediaserver_latest(num=count, username=username)
items: List[schemas.MediaServerPlayItem] = self.mediaserver_latest(server=server, count=count,
username=username)
for item in items:
if host_type and item.id:
_link = server.generate_external_image_link(id=item.id, image_type="Backdrop")
_link = server_obj.generate_external_image_link(item_id=item.id, image_type="Backdrop")
if _link:
links.append(_link)
elif item.image:
links.append(item.image)

return links
58 changes: 29 additions & 29 deletions app/modules/jellyfin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ def media_statistic(self, server: str = None) -> Optional[List[schemas.Statistic
媒体数量统计
"""
if server:
server: Jellyfin = self.get_instance(server)
if not server:
server_obj: Jellyfin = self.get_instance(server)
if not server_obj:
return None
servers = [server]
servers = [server_obj]
else:
servers = self.get_instances().values()
media_statistics = []
Expand All @@ -203,9 +203,9 @@ def mediaserver_librarys(self, server: str = None,
"""
媒体库列表
"""
server: Jellyfin = self.get_instance(server)
if server:
return server.get_librarys(username=username, hidden=hidden)
server_obj: Jellyfin = self.get_instance(server)
if server_obj:
return server_obj.get_librarys(username=username, hidden=hidden)
return None

def mediaserver_items(self, server: str, library_id: Union[str, int], start_index: int = 0,
Expand All @@ -220,29 +220,29 @@ def mediaserver_items(self, server: str, library_id: Union[str, int], start_inde
:return: 返回一个生成器对象,用于逐步获取媒体服务器中的项目
"""
server: Jellyfin = self.get_instance(server)
if server:
return server.get_items(library_id, start_index, limit)
server_obj: Jellyfin = self.get_instance(server)
if server_obj:
return server_obj.get_items(library_id, start_index, limit)
return None

def mediaserver_iteminfo(self, server: str, item_id: str) -> Optional[schemas.MediaServerItem]:
"""
媒体库项目详情
"""
server: Jellyfin = self.get_instance(server)
if server:
return server.get_iteminfo(item_id)
server_obj: Jellyfin = self.get_instance(server)
if server_obj:
return server_obj.get_iteminfo(item_id)
return None

def mediaserver_tv_episodes(self, server: str,
item_id: Union[str, int]) -> Optional[List[schemas.MediaServerSeasonInfo]]:
"""
获取剧集信息
"""
server: Jellyfin = self.get_instance(server)
if not server:
server_obj: Jellyfin = self.get_instance(server)
if not server_obj:
return None
_, seasoninfo = server.get_tv_episodes(item_id=item_id)
_, seasoninfo = server_obj.get_tv_episodes(item_id=item_id)
if not seasoninfo:
return []
return [schemas.MediaServerSeasonInfo(
Expand All @@ -255,29 +255,29 @@ def mediaserver_playing(self, server: str,
"""
获取媒体服务器正在播放信息
"""
server: Jellyfin = self.get_instance(server)
if not server:
server_obj: Jellyfin = self.get_instance(server)
if not server_obj:
return []
return server.get_resume(num=count, username=username)
return server_obj.get_resume(num=count, username=username)

def mediaserver_play_url(self, server: str, item_id: Union[str, int]) -> Optional[str]:
"""
获取媒体库播放地址
"""
server: Jellyfin = self.get_instance(server)
if not server:
server_obj: Jellyfin = self.get_instance(server)
if not server_obj:
return None
return server.get_play_url(item_id)
return server_obj.get_play_url(item_id)

def mediaserver_latest(self, server: str,
def mediaserver_latest(self, server: str = None,
count: int = 20, username: str = None) -> List[schemas.MediaServerPlayItem]:
"""
获取媒体服务器最新入库条目
"""
server: Jellyfin = self.get_instance(server)
if not server:
server_obj: Jellyfin = self.get_instance(server)
if not server_obj:
return []
return server.get_latest(num=count, username=username)
return server_obj.get_latest(num=count, username=username)

def mediaserver_latest_images(self,
server: str = None,
Expand All @@ -294,15 +294,15 @@ def mediaserver_latest_images(self,
:param host_type: True为外网链接, False为内网链接
:return: 图片链接列表
"""
server: Jellyfin = self.get_instance(server)
server_obj: Jellyfin = self.get_instance(server)
if not server:
return []

links = []
items: List[schemas.MediaServerPlayItem] = self.mediaserver_latest(num=count, username=username)
items: List[schemas.MediaServerPlayItem] = self.mediaserver_latest(server=server, count=count,
username=username)
for item in items:
link = server.generate_image_link(item_id=item.id, image_type="Backdrop", host_type=host_type)
link = server_obj.generate_image_link(item_id=item.id, image_type="Backdrop", host_type=host_type)
if link:
links.append(link)

return links
65 changes: 33 additions & 32 deletions app/modules/plex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ def media_statistic(self, server: str = None) -> Optional[List[schemas.Statistic
媒体数量统计
"""
if server:
server: Plex = self.get_instance(server)
if not server:
server_obj: Plex = self.get_instance(server)
if not server_obj:
return None
servers = [server]
servers = [server_obj]
else:
servers = self.get_instances().values()
media_statistics = []
Expand All @@ -209,9 +209,9 @@ def mediaserver_librarys(self, server: str = None, hidden: bool = False,
"""
媒体库列表
"""
server: Plex = self.get_instance(server)
if server:
return server.get_librarys(hidden)
server_obj: Plex = self.get_instance(server)
if server_obj:
return server_obj.get_librarys(hidden)
return None

def mediaserver_items(self, server: str, library_id: Union[str, int], start_index: int = 0,
Expand All @@ -226,29 +226,29 @@ def mediaserver_items(self, server: str, library_id: Union[str, int], start_inde
:return: 返回一个生成器对象,用于逐步获取媒体服务器中的项目
"""
server: Plex = self.get_instance(server)
if server:
return server.get_items(library_id, start_index, limit)
server_obj: Plex = self.get_instance(server)
if server_obj:
return server_obj.get_items(library_id, start_index, limit)
return None

def mediaserver_iteminfo(self, server: str, item_id: str) -> Optional[schemas.MediaServerItem]:
"""
媒体库项目详情
"""
server: Plex = self.get_instance(server)
if server:
return server.get_iteminfo(item_id)
server_obj: Plex = self.get_instance(server)
if server_obj:
return server_obj.get_iteminfo(item_id)
return None

def mediaserver_tv_episodes(self, server: str,
item_id: Union[str, int]) -> Optional[List[schemas.MediaServerSeasonInfo]]:
"""
获取剧集信息
"""
server: Plex = self.get_instance(server)
if not server:
server_obj: Plex = self.get_instance(server)
if not server_obj:
return None
_, seasoninfo = server.get_tv_episodes(item_id=item_id)
_, seasoninfo = server_obj.get_tv_episodes(item_id=item_id)
if not seasoninfo:
return []
return [schemas.MediaServerSeasonInfo(
Expand All @@ -260,19 +260,20 @@ def mediaserver_playing(self, server: str, count: int = 20, **kwargs) -> List[sc
"""
获取媒体服务器正在播放信息
"""
server: Plex = self.get_instance(server)
if not server:
server_obj: Plex = self.get_instance(server)
if not server_obj:
return []
return server.get_resume(num=count)
return server_obj.get_resume(num=count)

def mediaserver_latest(self, server: str, count: int = 20, **kwargs) -> List[schemas.MediaServerPlayItem]:
def mediaserver_latest(self, server: str = None, count: int = 20,
**kwargs) -> List[schemas.MediaServerPlayItem]:
"""
获取媒体服务器最新入库条目
"""
server: Plex = self.get_instance(server)
if not server:
server_obj: Plex = self.get_instance(server)
if not server_obj:
return []
return server.get_latest(num=count)
return server_obj.get_latest(num=count)

def mediaserver_latest_images(self,
server: str = None,
Expand All @@ -287,26 +288,26 @@ def mediaserver_latest_images(self,
:param username: 用户名
:return: 图片链接列表
"""
server: Plex = self.get_instance(server)
if not server:
server_obj: Plex = self.get_instance(server)
if not server_obj:
return []

links = []
items: List[schemas.MediaServerPlayItem] = self.mediaserver_latest(num=count, username=username)
items: List[schemas.MediaServerPlayItem] = self.mediaserver_latest(server=server, count=count,
username=username)
for item in items:
link = server.get_remote_image_by_id(item_id=item.id,
image_type="Backdrop",
plex_url=False)
link = server_obj.get_remote_image_by_id(item_id=item.id,
image_type="Backdrop",
plex_url=False)
if link:
links.append(link)

return links

def mediaserver_play_url(self, server: str, item_id: Union[str, int]) -> Optional[str]:
"""
获取媒体库播放地址
"""
server: Plex = self.get_instance(server)
if not server:
server_obj: Plex = self.get_instance(server)
if not server_obj:
return None
return server.get_play_url(item_id)
return server_obj.get_play_url(item_id)

0 comments on commit 08aa5fe

Please sign in to comment.