1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 12:15:40 +01:00
svtplay-dl/lib/svtplay_dl/service/svt.py

40 lines
1.5 KiB
Python
Raw Normal View History

import codecs
import copy
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
from svtplay_dl.subtitle import subtitle
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):
2018-03-19 21:53:27 +01:00
data = self.get_urldata()
match = re.search("n.reduxState=(.*);", data)
if not match:
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}")
else:
janson = json.loads(match.group(1))
vid = janson["areaData"]["articles"][list(janson["areaData"]["articles"].keys())[0]]["media"][0]["image"]["svtId"]
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()
if "subtitleReferences" in janson:
for i in janson["subtitleReferences"]:
if i["format"] == "websrt" and "url" in i:
yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output)
yield from self._get_video(janson)