2021-02-07 12:07:14 +01:00
|
|
|
import codecs
|
2019-01-06 21:55:48 +01:00
|
|
|
import copy
|
2020-06-02 17:41:30 +02:00
|
|
|
import json
|
2019-08-25 00:40:39 +02:00
|
|
|
import re
|
2017-05-08 00:14:05 +02:00
|
|
|
|
|
|
|
from svtplay_dl.error import ServiceError
|
|
|
|
from svtplay_dl.service.svtplay import Svtplay
|
2022-12-10 14:05:56 +01:00
|
|
|
from svtplay_dl.subtitle import subtitle_probe
|
2017-05-08 00:14:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Svt(Svtplay):
|
2019-08-25 00:27:31 +02:00
|
|
|
supported_domains = ["svt.se", "www.svt.se"]
|
2017-05-08 00:14:05 +02:00
|
|
|
|
|
|
|
def get(self):
|
2023-03-16 22:23:02 +01:00
|
|
|
vid = None
|
2018-03-19 21:53:27 +01:00
|
|
|
data = self.get_urldata()
|
2023-03-16 22:23:02 +01:00
|
|
|
match = re.search("n.urqlState=(.*);", data)
|
2020-06-02 17:41:30 +02:00
|
|
|
if not match:
|
2021-02-07 12:07:14 +01:00
|
|
|
match = re.search(r"stateData = JSON.parse\(\"(.*)\"\)\<\/script", data)
|
|
|
|
if not match:
|
|
|
|
yield ServiceError("Cant find video info.")
|
|
|
|
return
|
|
|
|
janson = json.loads(codecs.escape_decode(match.group(1))[0].decode("utf-8"))
|
|
|
|
if janson["recipe"]["content"]["data"]["videoClips"]:
|
|
|
|
vid = janson["recipe"]["content"]["data"]["videoClips"][0]["id"]
|
|
|
|
else:
|
|
|
|
vid = janson["recipe"]["content"]["data"]["videoEpisodes"][0]["id"]
|
2021-02-28 22:05:15 +01:00
|
|
|
res = self.http.get(f"https://api.svt.se/videoplayer-api/video/{vid}")
|
2021-02-07 12:07:14 +01:00
|
|
|
else:
|
|
|
|
janson = json.loads(match.group(1))
|
2023-03-16 22:23:02 +01:00
|
|
|
for key in list(janson.keys()):
|
|
|
|
janson2 = json.loads(janson[key]["data"])
|
|
|
|
if "page" in janson2 and "topMedia" in janson2["page"]:
|
|
|
|
vid = janson2["page"]["topMedia"]["svtId"]
|
|
|
|
if not vid:
|
|
|
|
yield ServiceError("Can't find any videos")
|
|
|
|
return
|
2021-02-28 22:05:15 +01:00
|
|
|
res = self.http.get(f"https://api.svt.se/video/{vid}")
|
2017-05-08 00:14:05 +02:00
|
|
|
|
|
|
|
janson = res.json()
|
2019-01-06 21:55:48 +01:00
|
|
|
if "subtitleReferences" in janson:
|
|
|
|
for i in janson["subtitleReferences"]:
|
2022-12-10 14:05:56 +01:00
|
|
|
if "url" in i:
|
|
|
|
yield from subtitle_probe(copy.copy(self.config), i["url"], output=self.output)
|
2019-01-06 21:55:48 +01:00
|
|
|
|
2021-05-16 02:22:37 +02:00
|
|
|
yield from self._get_video(janson)
|