diff --git a/lib/svtplay_dl/service/svt.py b/lib/svtplay_dl/service/svt.py index 7326237..b84e7f3 100644 --- a/lib/svtplay_dl/service/svt.py +++ b/lib/svtplay_dl/service/svt.py @@ -1,3 +1,4 @@ +import codecs import copy import json import re @@ -11,16 +12,24 @@ class Svt(Svtplay): supported_domains = ["svt.se", "www.svt.se"] def get(self): - data = self.get_urldata() match = re.search("n.reduxState=(.*);", data) if not match: - yield ServiceError("Cant find video info.") - return + 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"] + res = self.http.get("https://api.svt.se/videoplayer-api/video/{}".format(vid)) + else: + janson = json.loads(match.group(1)) + vid = janson["areaData"]["articles"][list(janson["areaData"]["articles"].keys())[0]]["media"][0]["image"]["svtId"] + res = self.http.get("https://api.svt.se/video/{}".format(vid)) - janson = json.loads(match.group(1)) - vid = janson["areaData"]["articles"][list(janson["areaData"]["articles"].keys())[0]]["media"][0]["image"]["svtId"] - res = self.http.get("https://api.svt.se/video/{}".format(vid)) janson = res.json() if "subtitleReferences" in janson: for i in janson["subtitleReferences"]: