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/sportlib.py

79 lines
2.8 KiB
Python
Raw Normal View History

2018-01-04 00:49:33 +01:00
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
import re
2019-08-25 00:40:39 +02:00
from urllib.parse import urljoin
from urllib.parse import urlparse
2018-01-04 00:49:33 +01:00
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-01-04 00:49:33 +01:00
class Sportlib(Service, OpenGraphThumbMixin):
2019-08-25 00:27:31 +02:00
supported_domains = ["sportlib.se"]
2018-01-04 00:49:33 +01:00
def get(self):
data = self.http.get("https://www.sportlib.se/sportlib/login").text
match = re.search('src="(/app[^"]+)">', data)
if not match:
yield ServiceError("Can't find url for login info")
return
url = urljoin("https://www.sportlib.se", match.group(1))
data = self.http.get(url).text
match = re.search('CLIENT_SECRET:"([^"]+)"', data)
if not match:
yield ServiceError("Cant fint login info")
return
cs = match.group(1)
match = re.search('CLIENT_ID:"([^"]+)"', data)
if not match:
yield ServiceError("Cant fint login info")
return
2021-12-18 21:37:09 +01:00
res = self.http.get("https://core.oz.com/channels?slug=sportlib&org=www.sportlib.se")
2018-01-04 00:49:33 +01:00
janson = res.json()
sid = janson["data"][0]["id"]
2021-12-18 21:37:09 +01:00
res = self.http.post(
f"https://core.oz.com/oauth2/token?channelId={sid}",
data={
"client_id": match.group(1),
"client_secret": cs,
"grant_type": "password",
"username": self.config.get("username"),
"password": self.config.get("password"),
},
)
2018-01-04 00:49:33 +01:00
if res.status_code > 200:
yield ServiceError("Wrong username / password?")
return
janson = res.json()
parse = urlparse(self.url)
match = re.search("video/([-a-fA-F0-9]+)", parse.path)
if not match:
yield ServiceError("Cant find video id")
return
2021-12-18 21:37:09 +01:00
url = f"https://core.oz.com/channels/{sid}/videos/{match.group(1)}?include=collection,streamUrl"
res = self.http.get(
url,
headers={"content-type": "application/json", "authorization": f"{janson['token_type'].title()} {janson['access_token']}"},
)
2018-01-04 00:49:33 +01:00
janson = res.json()
2018-05-13 13:06:45 +02:00
self.output["title"] = janson["data"]["title"]
2018-01-04 00:49:33 +01:00
# get cookie
2021-12-18 21:37:09 +01:00
postjson = {"name": janson["data"]["streamUrl"]["cookieName"], "value": janson["data"]["streamUrl"]["token"]}
2018-01-04 00:49:33 +01:00
res = self.http.post("https://playlist.oz.com/cookie", json=postjson)
cookies = res.cookies
2021-12-18 21:37:09 +01:00
yield from hlsparse(
self.config,
self.http.request("get", janson["data"]["streamUrl"]["cdnUrl"]),
janson["data"]["streamUrl"]["cdnUrl"],
keycookie=cookies,
output=self.output,
)