From 7bffda758f88996cc95d0ce6333f48172e512869 Mon Sep 17 00:00:00 2001 From: stabbedbybrick <125766685+stabbedbybrick@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:24:30 +0200 Subject: [PATCH] fix(iP): Fix missing version data Some episodes return nothing from the API. In those cases, the episode id will be fetched from the page source code. --- services/iP/__init__.py | 18 +++++++++++++++--- services/iP/config.yaml | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/services/iP/__init__.py b/services/iP/__init__.py index fb915e1..da45483 100644 --- a/services/iP/__init__.py +++ b/services/iP/__init__.py @@ -126,13 +126,24 @@ 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() + if not r.ok: + self.log.error(r.text) + sys.exit(1) + versions = r.json().get("allAvailableVersions") + if not versions: + 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"} + ] + quality = [ connection.get("height") for i in ( self.check_all_versions(version) - for version in (x.get("pid") for x in r.json()["allAvailableVersions"]) + for version in (x.get("pid") for x in versions) ) for connection in i if connection.get("height") @@ -140,7 +151,7 @@ class iP(Service): max_quality = max((h for h in quality if h < "1080"), default=None) media = next((i for i in (self.check_all_versions(version) - for version in (x.get("pid") for x in r.json()["allAvailableVersions"])) + for version in (x.get("pid") for x in versions)) if any(connection.get("height") == max_quality for connection in i)), None) connection = {} @@ -296,6 +307,7 @@ class iP(Service): number=ep_num, name=ep_name, language="en", + data=episode, ) def get_single_episode(self, url: str) -> Series: diff --git a/services/iP/config.yaml b/services/iP/config.yaml index 8c60032..7675834 100644 --- a/services/iP/config.yaml +++ b/services/iP/config.yaml @@ -1,3 +1,4 @@ +base_url: https://www.bbc.co.uk/iplayer/{type}/{pid} user_agent: 'smarttv_AFTMM_Build_0003255372676_Chromium_41.0.2250.2' api_key: 'D2FgtcTxGqqIgLsfBWTJdrQh2tVdeaAp' @@ -7,3 +8,4 @@ endpoints: manifest: "https://open.live.bbc.co.uk/mediaselector/6/select/version/2.0/mediaset/{mediaset}/vpid/{vpid}/" manifest_: 'https://securegate.iplayer.bbc.co.uk/mediaselector/6/select/version/2.0/vpid/{vpid}/format/json/mediaset/{mediaset}/proto/https' search: "https://search.api.bbci.co.uk/formula/iplayer-ibl-root" +