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
|
2019-01-06 21:55:48 +01:00
|
|
|
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()
|
2020-06-02 17:41:30 +02:00
|
|
|
match = re.search("n.reduxState=(.*);", data)
|
|
|
|
if not match:
|
2017-05-08 00:14:05 +02:00
|
|
|
yield ServiceError("Cant find video info.")
|
|
|
|
return
|
|
|
|
|
2020-06-02 17:41:30 +02:00
|
|
|
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))
|
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"]:
|
|
|
|
if i["format"] == "websrt" and "url" in i:
|
2019-09-06 22:49:49 +02:00
|
|
|
yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output)
|
2019-01-06 21:55:48 +01:00
|
|
|
|
2017-05-08 00:14:05 +02:00
|
|
|
videos = self._get_video(janson)
|
2019-08-25 00:33:51 +02:00
|
|
|
yield from videos
|