1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-28 14:14:15 +01:00
svtplay-dl/lib/svtplay_dl/service/aftonbladet.py

52 lines
1.9 KiB
Python
Raw Normal View History

2013-03-02 21:26:28 +01:00
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
from __future__ import absolute_import
import sys
import re
2014-02-05 23:15:19 +01:00
import json
2014-06-07 20:43:40 +02:00
import copy
from svtplay_dl.service import Service
from svtplay_dl.utils import get_http_data
from svtplay_dl.log import log
from svtplay_dl.fetcher.hls import HLS
class Aftonbladet(Service):
2014-02-05 23:15:19 +01:00
supported_domains = ['tv.aftonbladet.se']
2014-01-06 23:14:06 +01:00
def get(self, options):
data = self.get_urldata()
match = re.search('data-aptomaId="([-0-9a-z]+)"', data)
if not match:
2014-02-05 23:15:19 +01:00
log.error("Can't find video info")
sys.exit(2)
2014-02-05 23:15:19 +01:00
videoId = match.group(1)
match = re.search(r'data-isLive="(\w+)"', data)
2014-02-05 23:15:19 +01:00
if not match:
log.error("Can't find live info")
sys.exit(2)
if match.group(1) == "true":
options.live = True
2014-02-05 23:15:19 +01:00
if not options.live:
dataurl = "http://aftonbladet-play-metadata.cdn.drvideo.aptoma.no/video/%s.json" % videoId
data = get_http_data(dataurl)
data = json.loads(data)
videoId = data["videoId"]
streamsurl = "http://aftonbladet-play-static-ext.cdn.drvideo.aptoma.no/actions/video/?id=%s&formats&callback=" % videoId
streams = json.loads(get_http_data(streamsurl))
hlsstreams = streams["formats"]["hls"]
if "level3" in hlsstreams.keys():
hls = hlsstreams["level3"]["csmil"][0]
else:
hls = hlsstreams["akamai"]["m3u8"][0]
address = hls["address"]
path = hls["path"]
for i in hls["files"]:
if "filename" in i.keys():
playlist = "http://%s/%s/%s/master.m3u8" % (address, path, i["filename"])
else:
playlist = "http://%s/%s/%s/master.m3u8" % (address, path, hls["filename"])
yield HLS(copy.copy(options), playlist, i["bitrate"])