-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of an extractor for regeringen.se
- Loading branch information
1 parent
5069e87
commit bffb6d0
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters