2014-08-11 23:20:17 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import re
|
|
|
|
import json
|
|
|
|
import copy
|
|
|
|
|
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2014-11-25 23:20:14 +01:00
|
|
|
from svtplay_dl.utils.urllib import urlparse, HTTPError
|
2014-08-11 23:20:17 +02:00
|
|
|
from svtplay_dl.fetcher.http import HTTP
|
|
|
|
from svtplay_dl.fetcher.hls import HLS, hlsparse
|
|
|
|
from svtplay_dl.log import log
|
|
|
|
|
|
|
|
class Dbtv(Service, OpenGraphThumbMixin):
|
|
|
|
supported_domains = ['dbtv.no']
|
|
|
|
|
|
|
|
def get(self, options):
|
2014-11-25 23:20:14 +01:00
|
|
|
try:
|
|
|
|
data = self.get_urldata()
|
|
|
|
except HTTPError as e:
|
|
|
|
log.error("Can't download webpage")
|
|
|
|
return
|
2014-08-11 23:20:17 +02:00
|
|
|
parse = urlparse(self.url)
|
|
|
|
vidoid = parse.path[parse.path.rfind("/")+1:]
|
|
|
|
match = re.search(r'JSONdata = ({.*});', data)
|
|
|
|
if not match:
|
|
|
|
log.error("Cant find json data")
|
2014-10-06 23:21:43 +02:00
|
|
|
return
|
2014-08-11 23:20:17 +02:00
|
|
|
janson = json.loads(match.group(1))
|
|
|
|
playlist = janson["playlist"]
|
|
|
|
for i in playlist:
|
|
|
|
if i["brightcoveId"] == vidoid:
|
|
|
|
if i["HLSURL"]:
|
|
|
|
streams = hlsparse(i["HLSURL"])
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield HLS(copy.copy(options), streams[n], n)
|
|
|
|
for n in i["renditions"]:
|
|
|
|
if n["container"] == "MP4":
|
|
|
|
yield HTTP(copy.copy(options), n["URL"], int(n["rate"])/1000)
|
|
|
|
|
|
|
|
|