From c4afda5919dbefb6814ee614a586c21114b4faae Mon Sep 17 00:00:00 2001 From: Filip Elander <1filipelander@gmail.com> Date: Fri, 25 Oct 2024 21:31:10 +0200 Subject: [PATCH] Aftonbladet premium (#1653) * added token and HMAC encoding to tv.aftonbladet url Co-authored-by: filipelander --- lib/svtplay_dl/service/aftonbladet.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/svtplay_dl/service/aftonbladet.py b/lib/svtplay_dl/service/aftonbladet.py index 3c4a607..95aa4d5 100644 --- a/lib/svtplay_dl/service/aftonbladet.py +++ b/lib/svtplay_dl/service/aftonbladet.py @@ -14,7 +14,6 @@ class Aftonbladettv(Service): def get(self): data = self.get_urldata() - match = re.search('data-player-config="([^"]+)"', data) if not match: match = re.search('data-svpPlayer-video="([^"]+)"', data) @@ -24,7 +23,27 @@ class Aftonbladettv(Service): yield ServiceError("Can't find video info") return data = json.loads(decode_html_entities(match.group(1))) - yield from hlsparse(self.config, self.http.request("get", data["streamUrls"]["hls"]), data["streamUrls"]["hls"], output=self.output) + hdnea = self._login() + url = data["streamUrls"]["hls"] + hdnea if hdnea else data["streamUrls"]["hls"] + yield from hlsparse(config=self.config, res=self.http.request("get", url), url=url, output=self.output) + + def _login(self): + if (token := self.config.get("token")) is None: + return None + if (match := re.search(r"^.*tv.aftonbladet.+video/([a-zA-Z0-9]+)/.*$", self.url)) is None: + return None + + service = match.group(1) + res = self.http.request("get", f"https://svp-token-api.aftonbladet.se/svp/token/{service}?access=plus", headers={"x-sp-id": token}) + if res.status_code != 200: + return None + expires = res.json()["expiry"] + hmac = res.json()["value"] + + res = self.http.request("get", f"https://svp.vg.no/svp/token/v1/?vendor=ab&assetId={service}&expires={expires}&hmac={hmac}") + if res.status_code != 200: + return None + return f"?hdnea={res.text.replace('/', '%2F').replace('=', '%3D').replace(',', '%2C')}" class Aftonbladet(Service):