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 -*-
|
2013-03-01 23:39:42 +01:00
|
|
|
from __future__ import absolute_import
|
2013-02-12 19:43:37 +01:00
|
|
|
import re
|
|
|
|
|
2013-04-21 12:44:31 +02:00
|
|
|
from svtplay_dl.service import Service
|
2014-05-01 21:46:44 +02:00
|
|
|
from svtplay_dl.error import UIException
|
2013-03-17 19:55:19 +01:00
|
|
|
from svtplay_dl.log import log
|
2014-04-21 18:26:57 +02:00
|
|
|
from svtplay_dl.fetcher.hls import HLS, hlsparse
|
|
|
|
from svtplay_dl.fetcher.http import HTTP
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2014-05-01 21:46:44 +02:00
|
|
|
class ExpressenException(UIException):
|
|
|
|
pass
|
|
|
|
|
2013-04-21 12:44:31 +02:00
|
|
|
class Expressen(Service):
|
2014-01-01 14:57:17 +01:00
|
|
|
supported_domains = ['expressen.se']
|
2014-05-01 21:46:44 +02:00
|
|
|
expressen_div_id = 'ctl00_WebTvArticleContent_BaseVideoHolder_VideoPlaceHolder_Satellite_Satellite'
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-05-01 21:46:44 +02:00
|
|
|
def _get_video_source(self, vtype):
|
|
|
|
match = re.search(
|
|
|
|
'<source src="([^"]+)" type="%s" />' % vtype, self.get_urldata()
|
|
|
|
)
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-05-01 21:46:44 +02:00
|
|
|
if not match:
|
|
|
|
raise ExpressenException(
|
|
|
|
"Could not find any videos of type %s" % vtype)
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-05-01 21:46:44 +02:00
|
|
|
return match.group(1)
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-05-01 21:46:44 +02:00
|
|
|
def _get_hls(self):
|
|
|
|
return self._get_video_source("application/x-mpegURL")
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-05-01 21:46:44 +02:00
|
|
|
def _get_mp4(self):
|
|
|
|
return self._get_video_source('video/mp4')
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-05-01 21:46:44 +02:00
|
|
|
def get(self, options):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
url = self._get_hls()
|
2014-04-21 18:26:57 +02:00
|
|
|
streams = hlsparse(url)
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield HLS(options, streams[n], n)
|
2014-05-01 21:46:44 +02:00
|
|
|
except ExpressenException as exc:
|
|
|
|
# Lower res, but static mp4 file.
|
|
|
|
log.debug(exc)
|
|
|
|
url = self._get_mp4()
|
2014-04-21 18:26:57 +02:00
|
|
|
yield HTTP(options, url)
|
2014-05-01 21:46:44 +02:00
|
|
|
except ExpressenException:
|
2014-05-01 21:59:51 +02:00
|
|
|
log.error("Could not find any videos in '%s'", self.url)
|