2014-09-04 15:02:47 -04:00
|
|
|
|
# coding: utf-8
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2015-12-10 16:18:42 -05:00
|
|
|
|
from .xstream import XstreamIE
|
2015-05-30 05:15:42 -04:00
|
|
|
|
from ..utils import (
|
|
|
|
|
ExtractorError,
|
|
|
|
|
float_or_none,
|
2016-08-14 05:25:14 -04:00
|
|
|
|
try_get,
|
2015-05-30 05:15:42 -04:00
|
|
|
|
)
|
2014-09-04 15:02:47 -04:00
|
|
|
|
|
|
|
|
|
|
2015-12-10 16:18:42 -05:00
|
|
|
|
class VGTVIE(XstreamIE):
|
2015-10-30 05:20:38 -04:00
|
|
|
|
IE_DESC = 'VGTV, BTTV, FTV, Aftenposten and Aftonbladet'
|
2015-12-09 04:50:11 -05:00
|
|
|
|
|
|
|
|
|
_HOST_TO_APPNAME = {
|
|
|
|
|
'vgtv.no': 'vgtv',
|
|
|
|
|
'bt.no/tv': 'bttv',
|
|
|
|
|
'aftenbladet.no/tv': 'satv',
|
|
|
|
|
'fvn.no/fvntv': 'fvntv',
|
|
|
|
|
'aftenposten.no/webtv': 'aptv',
|
2016-03-05 11:51:46 -05:00
|
|
|
|
'ap.vgtv.no/webtv': 'aptv',
|
2016-09-29 13:15:09 -04:00
|
|
|
|
'tv.aftonbladet.se/abtv': 'abtv',
|
2015-12-09 04:50:11 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_APP_NAME_TO_VENDOR = {
|
|
|
|
|
'vgtv': 'vgtv',
|
|
|
|
|
'bttv': 'bt',
|
|
|
|
|
'satv': 'sa',
|
|
|
|
|
'fvntv': 'fvn',
|
|
|
|
|
'aptv': 'ap',
|
2016-09-29 13:15:09 -04:00
|
|
|
|
'abtv': 'ab',
|
2015-12-09 04:50:11 -05:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 12:18:43 -04:00
|
|
|
|
_VALID_URL = r'''(?x)
|
2015-12-09 04:50:11 -05:00
|
|
|
|
(?:https?://(?:www\.)?
|
2015-10-30 05:20:38 -04:00
|
|
|
|
(?P<host>
|
2015-12-09 04:50:11 -05:00
|
|
|
|
%s
|
2015-05-08 12:18:43 -04:00
|
|
|
|
)
|
2016-03-05 11:51:46 -05:00
|
|
|
|
/?
|
2015-05-08 12:18:43 -04:00
|
|
|
|
(?:
|
2015-10-30 05:20:38 -04:00
|
|
|
|
\#!/(?:video|live)/|
|
2016-09-29 13:15:09 -04:00
|
|
|
|
embed?.*id=|
|
|
|
|
|
articles/
|
2015-12-09 04:50:11 -05:00
|
|
|
|
)|
|
|
|
|
|
(?P<appname>
|
|
|
|
|
%s
|
|
|
|
|
):)
|
2015-12-06 01:43:46 -05:00
|
|
|
|
(?P<id>\d+)
|
2015-12-09 04:50:11 -05:00
|
|
|
|
''' % ('|'.join(_HOST_TO_APPNAME.keys()), '|'.join(_APP_NAME_TO_VENDOR.keys()))
|
|
|
|
|
|
2014-09-08 10:26:42 -04:00
|
|
|
|
_TESTS = [
|
|
|
|
|
{
|
|
|
|
|
# streamType: vod
|
|
|
|
|
'url': 'http://www.vgtv.no/#!/video/84196/hevnen-er-soet-episode-10-abu',
|
|
|
|
|
'md5': 'b8be7a234cebb840c0d512c78013e02f',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '84196',
|
|
|
|
|
'ext': 'mp4',
|
2014-12-03 13:07:09 -05:00
|
|
|
|
'title': 'Hevnen er søt: Episode 10 - Abu',
|
2014-09-08 10:26:42 -04:00
|
|
|
|
'description': 'md5:e25e4badb5f544b04341e14abdc72234',
|
2017-01-02 07:08:07 -05:00
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg',
|
2014-09-08 10:26:42 -04:00
|
|
|
|
'duration': 648.000,
|
|
|
|
|
'timestamp': 1404626400,
|
2014-09-08 10:33:03 -04:00
|
|
|
|
'upload_date': '20140706',
|
|
|
|
|
'view_count': int,
|
2014-09-08 10:26:42 -04:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
# streamType: wasLive
|
|
|
|
|
'url': 'http://www.vgtv.no/#!/live/100764/opptak-vgtv-foelger-em-kvalifiseringen',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '100764',
|
2014-09-30 08:50:14 -04:00
|
|
|
|
'ext': 'flv',
|
2014-09-08 10:26:42 -04:00
|
|
|
|
'title': 'OPPTAK: VGTV følger EM-kvalifiseringen',
|
|
|
|
|
'description': 'md5:3772d9c0dc2dff92a886b60039a7d4d3',
|
2017-01-02 07:08:07 -05:00
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg',
|
2014-12-03 13:07:09 -05:00
|
|
|
|
'duration': 9103.0,
|
2014-09-08 10:26:42 -04:00
|
|
|
|
'timestamp': 1410113864,
|
2014-09-08 10:33:03 -04:00
|
|
|
|
'upload_date': '20140907',
|
|
|
|
|
'view_count': int,
|
2014-09-08 10:26:42 -04:00
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
# m3u8 download
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
2015-10-30 04:48:56 -04:00
|
|
|
|
'skip': 'Video is no longer available',
|
2014-09-08 10:26:42 -04:00
|
|
|
|
},
|
|
|
|
|
{
|
2015-10-30 04:48:56 -04:00
|
|
|
|
# streamType: wasLive
|
2015-05-30 06:12:07 -04:00
|
|
|
|
'url': 'http://www.vgtv.no/#!/live/113063/direkte-v75-fra-solvalla',
|
2014-09-08 10:26:42 -04:00
|
|
|
|
'info_dict': {
|
2015-05-30 06:12:07 -04:00
|
|
|
|
'id': '113063',
|
2016-01-30 14:31:03 -05:00
|
|
|
|
'ext': 'mp4',
|
2015-10-30 04:48:56 -04:00
|
|
|
|
'title': 'V75 fra Solvalla 30.05.15',
|
2015-05-30 06:12:07 -04:00
|
|
|
|
'description': 'md5:b3743425765355855f88e096acc93231',
|
2017-01-02 07:08:07 -05:00
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg',
|
2015-10-30 04:48:56 -04:00
|
|
|
|
'duration': 25966,
|
2015-05-30 06:12:07 -04:00
|
|
|
|
'timestamp': 1432975582,
|
|
|
|
|
'upload_date': '20150530',
|
2014-09-08 10:33:03 -04:00
|
|
|
|
'view_count': int,
|
2014-09-08 10:26:42 -04:00
|
|
|
|
},
|
2016-01-30 14:31:03 -05:00
|
|
|
|
'params': {
|
|
|
|
|
# m3u8 download
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
2015-12-06 01:43:46 -05:00
|
|
|
|
},
|
|
|
|
|
{
|
2015-10-30 04:48:56 -04:00
|
|
|
|
'url': 'http://www.aftenposten.no/webtv/#!/video/21039/trailer-sweatshop-i-can-t-take-any-more',
|
2015-12-22 09:54:51 -05:00
|
|
|
|
'md5': 'fd828cd29774a729bf4d4425fe192972',
|
2015-10-30 04:48:56 -04:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '21039',
|
2016-03-05 11:51:46 -05:00
|
|
|
|
'ext': 'mp4',
|
2015-10-30 04:48:56 -04:00
|
|
|
|
'title': 'TRAILER: «SWEATSHOP» - I can´t take any more',
|
|
|
|
|
'description': 'md5:21891f2b0dd7ec2f78d84a50e54f8238',
|
|
|
|
|
'duration': 66,
|
|
|
|
|
'timestamp': 1417002452,
|
|
|
|
|
'upload_date': '20141126',
|
|
|
|
|
'view_count': int,
|
2016-03-05 11:51:46 -05:00
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
# m3u8 download
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
2014-09-08 10:26:42 -04:00
|
|
|
|
},
|
2015-05-08 12:03:03 -04:00
|
|
|
|
{
|
|
|
|
|
'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
},
|
2016-03-05 11:51:46 -05:00
|
|
|
|
{
|
|
|
|
|
'url': 'http://ap.vgtv.no/webtv#!/video/111084/de-nye-bysyklene-lettere-bedre-gir-stoerre-hjul-og-feste-til-mobil',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
},
|
2016-08-14 05:25:14 -04:00
|
|
|
|
{
|
|
|
|
|
# geoblocked
|
|
|
|
|
'url': 'http://www.vgtv.no/#!/video/127205/inside-the-mind-of-favela-funk',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
},
|
2016-09-29 13:15:09 -04:00
|
|
|
|
{
|
|
|
|
|
'url': 'http://tv.aftonbladet.se/abtv/articles/36015',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'url': 'abtv:140026',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}
|
2014-09-08 10:26:42 -04:00
|
|
|
|
]
|
2014-09-04 15:02:47 -04:00
|
|
|
|
|
2014-09-08 10:26:42 -04:00
|
|
|
|
def _real_extract(self, url):
|
2015-05-08 12:03:03 -04:00
|
|
|
|
mobj = re.match(self._VALID_URL, url)
|
|
|
|
|
video_id = mobj.group('id')
|
|
|
|
|
host = mobj.group('host')
|
2015-12-09 04:50:11 -05:00
|
|
|
|
appname = self._HOST_TO_APPNAME[host] if host else mobj.group('appname')
|
|
|
|
|
vendor = self._APP_NAME_TO_VENDOR[appname]
|
2015-05-08 12:03:03 -04:00
|
|
|
|
|
2014-09-08 10:26:42 -04:00
|
|
|
|
data = self._download_json(
|
2015-05-08 12:03:03 -04:00
|
|
|
|
'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
|
2015-12-09 04:50:11 -05:00
|
|
|
|
% (vendor, video_id, appname),
|
2014-09-08 10:26:42 -04:00
|
|
|
|
video_id, 'Downloading media JSON')
|
2014-09-04 15:02:47 -04:00
|
|
|
|
|
2015-05-30 05:15:42 -04:00
|
|
|
|
if data.get('status') == 'inactive':
|
|
|
|
|
raise ExtractorError(
|
|
|
|
|
'Video %s is no longer available' % video_id, expected=True)
|
|
|
|
|
|
2015-12-10 16:18:42 -05:00
|
|
|
|
info = {
|
|
|
|
|
'formats': [],
|
|
|
|
|
}
|
|
|
|
|
if len(video_id) == 5:
|
|
|
|
|
if appname == 'bttv':
|
|
|
|
|
info = self._extract_video_info('btno', video_id)
|
|
|
|
|
|
2014-09-08 10:26:42 -04:00
|
|
|
|
streams = data['streamUrls']
|
2015-05-30 06:12:07 -04:00
|
|
|
|
stream_type = data.get('streamType')
|
2014-09-04 15:02:47 -04:00
|
|
|
|
|
2014-09-08 10:26:42 -04:00
|
|
|
|
formats = []
|
2014-09-04 15:02:47 -04:00
|
|
|
|
|
2014-09-08 10:26:42 -04:00
|
|
|
|
hls_url = streams.get('hls')
|
|
|
|
|
if hls_url:
|
2015-12-28 13:58:24 -05:00
|
|
|
|
formats.extend(self._extract_m3u8_formats(
|
|
|
|
|
hls_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
|
2014-09-04 15:02:47 -04:00
|
|
|
|
|
2014-09-08 10:26:42 -04:00
|
|
|
|
hds_url = streams.get('hds')
|
2015-12-27 11:44:55 -05:00
|
|
|
|
if hds_url:
|
|
|
|
|
hdcore_sign = 'hdcore=3.7.0'
|
2015-12-09 04:50:11 -05:00
|
|
|
|
f4m_formats = self._extract_f4m_formats(
|
2015-12-27 11:44:55 -05:00
|
|
|
|
hds_url + '?%s' % hdcore_sign, video_id, f4m_id='hds', fatal=False)
|
2015-12-06 01:43:46 -05:00
|
|
|
|
if f4m_formats:
|
2015-12-27 11:44:55 -05:00
|
|
|
|
for entry in f4m_formats:
|
|
|
|
|
# URLs without the extra param induce an 404 error
|
|
|
|
|
entry.update({'extra_param_to_segment_url': hdcore_sign})
|
|
|
|
|
formats.append(entry)
|
2014-09-04 15:02:47 -04:00
|
|
|
|
|
2015-12-06 01:43:46 -05:00
|
|
|
|
mp4_urls = streams.get('pseudostreaming') or []
|
2014-09-08 10:26:42 -04:00
|
|
|
|
mp4_url = streams.get('mp4')
|
|
|
|
|
if mp4_url:
|
2015-12-06 01:43:46 -05:00
|
|
|
|
mp4_urls.append(mp4_url)
|
|
|
|
|
for mp4_url in mp4_urls:
|
|
|
|
|
format_info = {
|
|
|
|
|
'url': mp4_url,
|
|
|
|
|
}
|
2017-01-02 07:08:07 -05:00
|
|
|
|
mobj = re.search(r'(\d+)_(\d+)_(\d+)', mp4_url)
|
2015-12-06 01:43:46 -05:00
|
|
|
|
if mobj:
|
2015-12-22 09:54:51 -05:00
|
|
|
|
tbr = int(mobj.group(3))
|
2015-12-06 01:43:46 -05:00
|
|
|
|
format_info.update({
|
|
|
|
|
'width': int(mobj.group(1)),
|
|
|
|
|
'height': int(mobj.group(2)),
|
2015-12-22 09:54:51 -05:00
|
|
|
|
'tbr': tbr,
|
|
|
|
|
'format_id': 'mp4-%s' % tbr,
|
2014-09-08 10:26:42 -04:00
|
|
|
|
})
|
2015-12-06 01:43:46 -05:00
|
|
|
|
formats.append(format_info)
|
|
|
|
|
|
2015-12-10 16:18:42 -05:00
|
|
|
|
info['formats'].extend(formats)
|
2014-09-08 10:26:42 -04:00
|
|
|
|
|
2016-08-14 05:25:14 -04:00
|
|
|
|
if not info['formats']:
|
|
|
|
|
properties = try_get(
|
|
|
|
|
data, lambda x: x['streamConfiguration']['properties'], list)
|
|
|
|
|
if properties and 'geoblocked' in properties:
|
|
|
|
|
raise self.raise_geo_restricted()
|
|
|
|
|
|
2015-12-10 16:18:42 -05:00
|
|
|
|
self._sort_formats(info['formats'])
|
|
|
|
|
|
|
|
|
|
info.update({
|
2014-09-08 10:26:42 -04:00
|
|
|
|
'id': video_id,
|
2015-10-30 04:48:56 -04:00
|
|
|
|
'title': self._live_title(data['title']) if stream_type == 'live' else data['title'],
|
2014-09-08 10:26:42 -04:00
|
|
|
|
'description': data['description'],
|
|
|
|
|
'thumbnail': data['images']['main'] + '?t[]=900x506q80',
|
|
|
|
|
'timestamp': data['published'],
|
|
|
|
|
'duration': float_or_none(data['duration'], 1000),
|
|
|
|
|
'view_count': data['displays'],
|
2015-05-30 06:12:07 -04:00
|
|
|
|
'is_live': True if stream_type == 'live' else False,
|
2015-12-10 16:18:42 -05:00
|
|
|
|
})
|
|
|
|
|
return info
|
2015-05-08 12:18:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BTArticleIE(InfoExtractor):
|
2015-05-08 12:59:50 -04:00
|
|
|
|
IE_NAME = 'bt:article'
|
|
|
|
|
IE_DESC = 'Bergens Tidende Articles'
|
2016-03-21 11:36:32 -04:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
|
2015-05-08 12:18:43 -04:00
|
|
|
|
_TEST = {
|
|
|
|
|
'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
|
2015-12-22 09:54:51 -05:00
|
|
|
|
'md5': '2acbe8ad129b3469d5ae51b1158878df',
|
2015-05-08 12:18:43 -04:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '23199',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Alrekstad internat',
|
|
|
|
|
'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
|
2017-01-02 07:08:07 -05:00
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg',
|
2015-05-08 12:18:43 -04:00
|
|
|
|
'duration': 191,
|
|
|
|
|
'timestamp': 1289991323,
|
|
|
|
|
'upload_date': '20101117',
|
|
|
|
|
'view_count': int,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
webpage = self._download_webpage(url, self._match_id(url))
|
|
|
|
|
video_id = self._search_regex(
|
2015-12-22 09:54:51 -05:00
|
|
|
|
r'<video[^>]+data-id="(\d+)"', webpage, 'video id')
|
2015-12-09 04:50:11 -05:00
|
|
|
|
return self.url_result('bttv:%s' % video_id, 'VGTV')
|
2015-05-08 12:59:50 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BTVestlendingenIE(InfoExtractor):
|
|
|
|
|
IE_NAME = 'bt:vestlendingen'
|
|
|
|
|
IE_DESC = 'Bergens Tidende - Vestlendingen'
|
2016-03-21 11:36:32 -04:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
|
2015-12-22 09:54:51 -05:00
|
|
|
|
_TESTS = [{
|
2015-05-08 12:59:50 -04:00
|
|
|
|
'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
|
|
|
|
|
'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '86588',
|
|
|
|
|
'ext': 'mov',
|
|
|
|
|
'title': 'Otto Wollertsen',
|
|
|
|
|
'description': 'Vestlendingen Otto Fredrik Wollertsen',
|
|
|
|
|
'timestamp': 1430473209,
|
|
|
|
|
'upload_date': '20150501',
|
|
|
|
|
},
|
2015-12-22 09:54:51 -05:00
|
|
|
|
'skip': '404 Error',
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://www.bt.no/spesial/vestlendingen/#!/86255',
|
|
|
|
|
'md5': 'a2893f8632e96389f4bdf36aa9463ceb',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '86255',
|
|
|
|
|
'ext': 'mov',
|
|
|
|
|
'title': 'Du må tåle å fryse og være sulten',
|
|
|
|
|
'description': 'md5:b8046f4d022d5830ddab04865791d063',
|
|
|
|
|
'upload_date': '20150321',
|
|
|
|
|
'timestamp': 1426942023,
|
|
|
|
|
},
|
|
|
|
|
}]
|
2015-05-08 12:59:50 -04:00
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2015-12-09 04:50:11 -05:00
|
|
|
|
return self.url_result('bttv:%s' % self._match_id(url), 'VGTV')
|