Skip to content

Commit

Permalink
refactor:media_exists 支持指定服务器
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Oct 19, 2024
1 parent 69c0229 commit 1e4f3e9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
6 changes: 4 additions & 2 deletions app/chain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,16 @@ def torrent_files(self, tid: str,
"""
return self.run_module("torrent_files", tid=tid, downloader=downloader)

def media_exists(self, mediainfo: MediaInfo, itemid: str = None) -> Optional[ExistMediaInfo]:
def media_exists(self, mediainfo: MediaInfo, itemid: str = None,
server: str = None) -> Optional[ExistMediaInfo]:
"""
判断媒体文件是否存在
:param mediainfo: 识别的媒体信息
:param itemid: 媒体服务器ItemID
:param server: 媒体服务器
:return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}}
"""
return self.run_module("media_exists", mediainfo=mediainfo, itemid=itemid)
return self.run_module("media_exists", mediainfo=mediainfo, itemid=itemid, server=server)

def media_files(self, mediainfo: MediaInfo) -> Optional[List[FileItem]]:
"""
Expand Down
12 changes: 10 additions & 2 deletions app/modules/emby/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,22 @@ def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[schemas.We
return result
return None

def media_exists(self, mediainfo: MediaInfo, itemid: str = None) -> Optional[schemas.ExistMediaInfo]:
def media_exists(self, mediainfo: MediaInfo, itemid: str = None,
server: str = None) -> Optional[schemas.ExistMediaInfo]:
"""
判断媒体文件是否存在
:param mediainfo: 识别的媒体信息
:param itemid: 媒体服务器ItemID
:param server: 媒体服务器名称
:return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}}
"""
for name, server in self.get_instances().items():
if server:
servers = [(server, self.get_instance(server))]
else:
servers = self.get_instances().items()
for name, server in servers:
if not server:
continue
if mediainfo.type == MediaType.MOVIE:
if itemid:
movie = server.get_iteminfo(itemid)
Expand Down
12 changes: 10 additions & 2 deletions app/modules/jellyfin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,22 @@ def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[schemas.We
return result
return None

def media_exists(self, mediainfo: MediaInfo, itemid: str = None) -> Optional[schemas.ExistMediaInfo]:
def media_exists(self, mediainfo: MediaInfo, itemid: str = None,
server: str = None) -> Optional[schemas.ExistMediaInfo]:
"""
判断媒体文件是否存在
:param mediainfo: 识别的媒体信息
:param itemid: 媒体服务器ItemID
:param server: 媒体服务器名称
:return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}}
"""
for name, server in self.get_instances().items():
if server:
servers = [(server, self.get_instance(server))]
else:
servers = self.get_instances().items()
for name, server in servers:
if not server:
continue
if mediainfo.type == MediaType.MOVIE:
if itemid:
movie = server.get_iteminfo(itemid)
Expand Down
12 changes: 10 additions & 2 deletions app/modules/plex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,22 @@ def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[schemas.We
return result
return None

def media_exists(self, mediainfo: MediaInfo, itemid: str = None) -> Optional[schemas.ExistMediaInfo]:
def media_exists(self, mediainfo: MediaInfo, itemid: str = None,
server: str = None) -> Optional[schemas.ExistMediaInfo]:
"""
判断媒体文件是否存在
:param mediainfo: 识别的媒体信息
:param itemid: 媒体服务器ItemID
:param server: 媒体服务器名称
:return: 如不存在返回None,存在时返回信息,包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}}
"""
for name, server in self.get_instances().items():
if server:
servers = [(server, self.get_instance(server))]
else:
servers = self.get_instances().items()
for name, server in servers:
if not server:
continue
if mediainfo.type == MediaType.MOVIE:
if itemid:
movie = server.get_iteminfo(itemid)
Expand Down

0 comments on commit 1e4f3e9

Please sign in to comment.