1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-30 23:24:16 +01:00
svtplay-dl/lib/svtplay_dl/service/svt.py
2019-09-06 22:49:49 +02:00

33 lines
951 B
Python

import copy
import re
from svtplay_dl.error import ServiceError
from svtplay_dl.service.svtplay import Svtplay
from svtplay_dl.subtitle import subtitle
class Svt(Svtplay):
supported_domains = ["svt.se", "www.svt.se"]
def get(self):
data = self.get_urldata()
match_data_video_id = re.search('data-video-id="(.+?)"', data)
if match_data_video_id:
id = match_data_video_id.group(1)
else:
yield ServiceError("Cant find video info.")
return
res = self.http.get("http://api.svt.se/videoplayer-api/video/{}".format(id))
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)
videos = self._get_video(janson)
yield from videos