1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-27 21:54:17 +01:00
svtplay-dl/lib/svtplay_dl/service/koket.py

56 lines
1.9 KiB
Python
Raw Normal View History

2018-08-23 23:54:32 +02:00
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
2021-11-23 23:33:51 +01:00
import json
import re
2018-08-23 23:54:32 +02:00
from urllib.parse import urlparse
from svtplay_dl.error import ServiceError
2019-08-25 00:40:39 +02:00
from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.service import OpenGraphThumbMixin
from svtplay_dl.service import Service
2018-08-23 23:54:32 +02:00
class Koket(Service, OpenGraphThumbMixin):
2019-08-25 00:27:31 +02:00
supported_domains = ["koket.se"]
2018-08-24 01:51:17 +02:00
2018-08-23 23:54:32 +02:00
def get(self):
urlp = urlparse(self.url)
2021-11-23 23:33:51 +01:00
if urlp.path.startswith("/kurser"):
res = self.http.post(
"https://www.koket.se/konto/authentication/login",
json={"username": self.config.get("username"), "password": self.config.get("password")},
)
if "errorMessage" in res.json():
yield ServiceError("Wrong username or password")
return
data = self.http.get(self.url)
match = re.search(r'({"@.*})', data)
if not match:
yield ServiceError("Can't find video info")
2018-08-23 23:54:32 +02:00
return
2021-11-23 23:33:51 +01:00
janson = json.loads(f"[{match.group(1)}]")
for i in janson:
if "video" in i:
self.output["title"] = i["video"]["name"]
break
2018-08-23 23:54:32 +02:00
2021-11-23 23:33:51 +01:00
match = re.search(r"dataLayer = (\[.*\]);<", data)
if not match:
yield ServiceError("Can't find video id")
2018-08-23 23:54:32 +02:00
return
2021-11-23 23:33:51 +01:00
janson = json.loads(match.group(1))
self.output["id"] = janson[0]["video"]
2018-08-23 23:54:32 +02:00
2021-12-18 19:52:08 +01:00
url = f"https://playback-api.b17g.net/media/{self.output['id']}?service=tv4&device=browser&protocol=hls%2Cdash&drm=widevine"
2018-08-23 23:54:32 +02:00
2018-08-24 00:25:05 +02:00
videoDataRes = self.http.get(url)
2018-08-23 23:54:32 +02:00
if videoDataRes.json()["playbackItem"]["type"] == "hls":
yield from hlsparse(
2019-08-25 00:27:31 +02:00
self.config,
self.http.get(videoDataRes.json()["playbackItem"]["manifestUrl"]),
videoDataRes.json()["playbackItem"]["manifestUrl"],
output=self.output,
)