Skip to content

Commit

Permalink
First version of an extractor for regeringen.se
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreMesure authored and spaam committed Apr 1, 2024
1 parent 5069e87 commit bffb6d0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/svtplay_dl/service/regeringen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import html
import re

from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.service import Service


class Regeringen(Service):
supported_domains_re = ["regeringen.se", "www.regeringen.se"]

def get(self):
res = self.http.get(self.url)
html_data = res.text

match = re.search(r"<title>(.*?) -", html_data)
if match:
self.output["title"] = html.unescape(match.group(1))

match = re.search(r"//video.qbrick.com/api/v1/(.*?)'", html_data)
if match:
result = match.group(1)
else:
yield ServiceError("Cant find the video.")

data_url = f"https://video.qbrick.com/api/v1/{result}"

res = self.http.get(data_url)
data = res.json()
resources = data["asset"]["resources"]
index_resources = [resource for resource in resources if resource["type"] == "index"]
links = index_resources[0]["renditions"][0]["links"]
hls_url = [link for link in links if "x-mpegURL" in link["mimeType"]][0]["href"]

if hls_url.find(".m3u8") > 0:
yield from hlsparse(self.config, self.http.request("get", hls_url), hls_url, output=self.output)
2 changes: 2 additions & 0 deletions lib/svtplay_dl/service/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from svtplay_dl.service.pokemon import Pokemon
from svtplay_dl.service.radioplay import Radioplay
from svtplay_dl.service.raw import Raw
from svtplay_dl.service.regeringen import Regeringen
from svtplay_dl.service.riksdagen import Riksdagen
from svtplay_dl.service.ruv import Ruv
from svtplay_dl.service.solidtango import Solidtango
Expand Down Expand Up @@ -84,6 +85,7 @@
Vimeo,
Vg,
Youplay,
Regeringen,
Riksdagen,
Raw,
]

0 comments on commit bffb6d0

Please sign in to comment.