From 3095165f8c9b333838dd6a183e36aa0097283854 Mon Sep 17 00:00:00 2001 From: stabbedbybrick <125766685+stabbedbybrick@users.noreply.github.com> Date: Wed, 17 Jul 2024 10:21:41 +0200 Subject: [PATCH] fix(iP): Set default version for UHD --- services/iP/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/services/iP/__init__.py b/services/iP/__init__.py index 09c195c..91729b2 100644 --- a/services/iP/__init__.py +++ b/services/iP/__init__.py @@ -143,21 +143,29 @@ class iP(Service): def get_tracks(self, title: Union[Movie, Episode]) -> Tracks: r = self.session.get(url=self.config["endpoints"]["playlist"].format(pid=title.id)) r.raise_for_status() + playlist = r.json() - versions = r.json().get("allAvailableVersions") + versions = playlist.get("allAvailableVersions") if not versions: # If API returns no versions, try to fetch from site source code r = self.session.get(self.config["base_url"].format(type="episode", pid=title.id)) redux = re.search("window.__IPLAYER_REDUX_STATE__ = (.*?);", r.text).group(1) data = json.loads(redux) - versions = [{"pid": x.get("id") for x in data["versions"] if not x.get("kind") == "audio-described"}] + versions = [{"pid": x.get("id") for x in data.get("versions", {}) if not x.get("kind") == "audio-described"}] + + if self.vcodec == "H.265": + versions = [{"pid": playlist.get("defaultAvailableVersion", {}).get("pid")}] + + if not versions: + self.log.error(" - No available versions for this title was found") + sys.exit(1) connections = [self.check_all_versions(version) for version in (x.get("pid") for x in versions)] quality = [connection.get("height") for i in connections for connection in i if connection.get("height")] max_quality = max((h for h in quality if h < "1080"), default=None) media = next( - (i for i in connections if any(connection.get("height") == max_quality or "2160" for connection in i)), + (i for i in connections if any(connection.get("height") == max_quality for connection in i)), None, )