Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aftonbladet premium #1652

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions lib/svtplay_dl/service/aftonbladet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
import json
import re
import logging

from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.hls import hlsparse
Expand All @@ -14,7 +15,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)
Expand All @@ -24,7 +24,49 @@ def get(self):
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 _get_service(self):
try:
url = self.url
vid_ref = "video/"
if not vid_ref in url:
return None
index = url.find(vid_ref)+len(vid_ref)
service = url[index:].split("/")[0]
return service

except Exception as e:
logging.error(f"Can't find service in video link")
return None

def _login(self):
if (service := self._get_service()) is None:
return None
if (token := self.config.get("token")) is None:
return None

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):
Expand Down
Loading