From 405bb6cb61ecdf231e9ecaff6a27a6e75e86f947 Mon Sep 17 00:00:00 2001 From: stabbedbybrick <125766685+stabbedbybrick@users.noreply.github.com> Date: Sat, 10 Feb 2024 15:21:51 +0100 Subject: [PATCH] [plex] Include all streams, catch empty media info --- services/plex/api.yaml | 1 + services/plex/plex.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/services/plex/api.yaml b/services/plex/api.yaml index 2dd42dc..e1f667e 100644 --- a/services/plex/api.yaml +++ b/services/plex/api.yaml @@ -1,4 +1,5 @@ user: https://plex.tv/api/v2/users/anonymous provider: provider://tv.plex.provider.vod/library/metadata/{path} vod: https://vod.provider.plex.tv +manifest: https://vod.provider.plex.tv/{key}?includeAllStreams=1&X-Plex-Product=Plex+Mediaverse&X-Plex-Token={token} license: https://vod.provider.plex.tv/library/parts/{id}-dash/license?X-Plex-Token={token}&X-Plex-DRM=widevine diff --git a/services/plex/plex.py b/services/plex/plex.py index 934b75e..7121a2f 100644 --- a/services/plex/plex.py +++ b/services/plex/plex.py @@ -164,7 +164,7 @@ class Plex(Config): year=movie.get("year"), name=movie["title"], data=next( - f'{self.config["vod"]}{x.get("key")}?X-Plex-Token={self.auth_token}' + f'{self.config["manifest"].format(key=x.get("key"), token=self.auth_token)}' for x in movie["Media"][0]["Part"] if "-dash" in x.get("key") ), @@ -190,15 +190,20 @@ class Plex(Config): [int(x.attrs["height"]) for x in elements if x.attrs.get("height")], reverse=True, ) + if not heights: + self.log.warning("Manifest did not contain proper media info, using 720p as placeholder...") + resolution = 720 + else: + resolution = heights[0] if quality is not None: if int(quality) in heights: - return quality + resolution = quality else: closest_match = min(heights, key=lambda x: abs(int(x) - int(quality))) - return closest_match + resolution = closest_match - return heights[0] + return resolution def get_mediainfo(self, stream: object, quality: str) -> str: r = self.client.get(stream.data) @@ -293,6 +298,6 @@ class Plex(Config): else: self.log.warning(f"{self.filename} already exists. Skipping download...\n") self.sub_path.unlink() if self.sub_path else None - + if not self.skip_download and file_path.exists(): update_cache(self.cache, self.config, stream)