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/dbtv.py
2018-05-13 13:06:45 +02:00

37 lines
1.2 KiB
Python

from __future__ import absolute_import
import re
import json
import copy
from urllib.parse import urlparse
from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.fetcher.http import HTTP
from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.error import ServiceError
class Dbtv(Service, OpenGraphThumbMixin):
supported_domains = ['dbtv.no']
def get(self):
data = self.get_urldata()
parse = urlparse(self.url)
vidoid = parse.path[parse.path.rfind("/") + 1:]
match = re.search(r'JSONdata = ({.*});', data)
if not match:
yield ServiceError("Cant find json data")
return
janson = json.loads(match.group(1))
playlist = janson["playlist"]
for i in playlist:
if i["brightcoveId"] == int(vidoid):
if i["HLSURL"]:
streams = hlsparse(self.config, self.http.request("get", i["HLSURL"]), i["HLSURL"])
for n in list(streams.keys()):
yield streams[n]
for n in i["renditions"]:
if n["container"] == "MP4":
yield HTTP(copy.copy(self.config), n["URL"], int(n["rate"]) / 1000)