2014-09-05 03:02:47 +08:00
|
|
|
|
# coding: utf-8
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2015-12-11 05:18:42 +08:00
|
|
|
|
from .xstream import XstreamIE
|
2015-05-30 17:15:42 +08:00
|
|
|
|
from ..utils import (
|
|
|
|
|
ExtractorError,
|
|
|
|
|
float_or_none,
|
|
|
|
|
)
|
2014-09-05 03:02:47 +08:00
|
|
|
|
|
|
|
|
|
|
2015-12-11 05:18:42 +08:00
|
|
|
|
class VGTVIE(XstreamIE):
|
2015-10-30 17:20:38 +08:00
|
|
|
|
IE_DESC = 'VGTV, BTTV, FTV, Aftenposten and Aftonbladet'
|
2015-12-09 17:50:11 +08:00
|
|
|
|
|
|
|
|
|
_HOST_TO_APPNAME = {
|
|
|
|
|
'vgtv.no': 'vgtv',
|
|
|
|
|
'bt.no/tv': 'bttv',
|
|
|
|
|
'aftenbladet.no/tv': 'satv',
|
|
|
|
|
'fvn.no/fvntv': 'fvntv',
|
|
|
|
|
'aftenposten.no/webtv': 'aptv',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_APP_NAME_TO_VENDOR = {
|
|
|
|
|
'vgtv': 'vgtv',
|
|
|
|
|
'bttv': 'bt',
|
|
|
|
|
'satv': 'sa',
|
|
|
|
|
'fvntv': 'fvn',
|
|
|
|
|
'aptv': 'ap',
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-09 00:18:43 +08:00
|
|
|
|
_VALID_URL = r'''(?x)
|
2015-12-09 17:50:11 +08:00
|
|
|
|
(?:https?://(?:www\.)?
|
2015-10-30 17:20:38 +08:00
|
|
|
|
(?P<host>
|
2015-12-09 17:50:11 +08:00
|
|
|
|
%s
|
2015-05-09 00:18:43 +08:00
|
|
|
|
)
|
2015-10-30 17:20:38 +08:00
|
|
|
|
/
|
2015-05-09 00:18:43 +08:00
|
|
|
|
(?:
|
2015-10-30 17:20:38 +08:00
|
|
|
|
\#!/(?:video|live)/|
|
|
|
|
|
embed?.*id=
|
2015-12-09 17:50:11 +08:00
|
|
|
|
)|
|
|
|
|
|
(?P<appname>
|
|
|
|
|
%s
|
|
|
|
|
):)
|
2015-12-06 14:43:46 +08:00
|
|
|
|
(?P<id>\d+)
|
2015-12-09 17:50:11 +08:00
|
|
|
|
''' % ('|'.join(_HOST_TO_APPNAME.keys()), '|'.join(_APP_NAME_TO_VENDOR.keys()))
|
|
|
|
|
|
2014-09-08 22:26:42 +08: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-04 02:07:09 +08:00
|
|
|
|
'title': 'Hevnen er søt: Episode 10 - Abu',
|
2014-09-08 22:26:42 +08:00
|
|
|
|
'description': 'md5:e25e4badb5f544b04341e14abdc72234',
|
|
|
|
|
'thumbnail': 're:^https?://.*\.jpg',
|
|
|
|
|
'duration': 648.000,
|
|
|
|
|
'timestamp': 1404626400,
|
2014-09-08 22:33:03 +08:00
|
|
|
|
'upload_date': '20140706',
|
|
|
|
|
'view_count': int,
|
2014-09-08 22:26:42 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
# streamType: wasLive
|
|
|
|
|
'url': 'http://www.vgtv.no/#!/live/100764/opptak-vgtv-foelger-em-kvalifiseringen',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '100764',
|
2014-09-30 20:50:14 +08:00
|
|
|
|
'ext': 'flv',
|
2014-09-08 22:26:42 +08:00
|
|
|
|
'title': 'OPPTAK: VGTV følger EM-kvalifiseringen',
|
|
|
|
|
'description': 'md5:3772d9c0dc2dff92a886b60039a7d4d3',
|
|
|
|
|
'thumbnail': 're:^https?://.*\.jpg',
|
2014-12-04 02:07:09 +08:00
|
|
|
|
'duration': 9103.0,
|
2014-09-08 22:26:42 +08:00
|
|
|
|
'timestamp': 1410113864,
|
2014-09-08 22:33:03 +08:00
|
|
|
|
'upload_date': '20140907',
|
|
|
|
|
'view_count': int,
|
2014-09-08 22:26:42 +08:00
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
# m3u8 download
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
2015-10-30 16:48:56 +08:00
|
|
|
|
'skip': 'Video is no longer available',
|
2014-09-08 22:26:42 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2015-10-30 16:48:56 +08:00
|
|
|
|
# streamType: wasLive
|
2015-05-30 18:12:07 +08:00
|
|
|
|
'url': 'http://www.vgtv.no/#!/live/113063/direkte-v75-fra-solvalla',
|
2015-12-28 00:44:55 +08:00
|
|
|
|
'md5': '458f4841239dab414343b50e5af8869c',
|
2014-09-08 22:26:42 +08:00
|
|
|
|
'info_dict': {
|
2015-05-30 18:12:07 +08:00
|
|
|
|
'id': '113063',
|
2015-12-28 00:44:55 +08:00
|
|
|
|
'ext': 'flv',
|
2015-10-30 16:48:56 +08:00
|
|
|
|
'title': 'V75 fra Solvalla 30.05.15',
|
2015-05-30 18:12:07 +08:00
|
|
|
|
'description': 'md5:b3743425765355855f88e096acc93231',
|
2014-09-08 22:26:42 +08:00
|
|
|
|
'thumbnail': 're:^https?://.*\.jpg',
|
2015-10-30 16:48:56 +08:00
|
|
|
|
'duration': 25966,
|
2015-05-30 18:12:07 +08:00
|
|
|
|
'timestamp': 1432975582,
|
|
|
|
|
'upload_date': '20150530',
|
2014-09-08 22:33:03 +08:00
|
|
|
|
'view_count': int,
|
2014-09-08 22:26:42 +08:00
|
|
|
|
},
|
2015-12-06 14:43:46 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2015-10-30 16:48:56 +08:00
|
|
|
|
'url': 'http://www.aftenposten.no/webtv/#!/video/21039/trailer-sweatshop-i-can-t-take-any-more',
|
2015-12-22 22:54:51 +08:00
|
|
|
|
'md5': 'fd828cd29774a729bf4d4425fe192972',
|
2015-10-30 16:48:56 +08:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '21039',
|
2015-12-22 22:54:51 +08:00
|
|
|
|
'ext': 'mov',
|
2015-10-30 16:48:56 +08:00
|
|
|
|
'title': 'TRAILER: «SWEATSHOP» - I can´t take any more',
|
|
|
|
|
'description': 'md5:21891f2b0dd7ec2f78d84a50e54f8238',
|
|
|
|
|
'duration': 66,
|
|
|
|
|
'timestamp': 1417002452,
|
|
|
|
|
'upload_date': '20141126',
|
|
|
|
|
'view_count': int,
|
|
|
|
|
}
|
2014-09-08 22:26:42 +08:00
|
|
|
|
},
|
2015-05-09 00:03:03 +08:00
|
|
|
|
{
|
|
|
|
|
'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
},
|
2014-09-08 22:26:42 +08:00
|
|
|
|
]
|
2014-09-05 03:02:47 +08:00
|
|
|
|
|
2014-09-08 22:26:42 +08:00
|
|
|
|
def _real_extract(self, url):
|
2015-05-09 00:03:03 +08:00
|
|
|
|
mobj = re.match(self._VALID_URL, url)
|
|
|
|
|
video_id = mobj.group('id')
|
|
|
|
|
host = mobj.group('host')
|
2015-12-09 17:50:11 +08:00
|
|
|
|
appname = self._HOST_TO_APPNAME[host] if host else mobj.group('appname')
|
|
|
|
|
vendor = self._APP_NAME_TO_VENDOR[appname]
|
2015-05-09 00:03:03 +08:00
|
|
|
|
|
2014-09-08 22:26:42 +08:00
|
|
|
|
data = self._download_json(
|
2015-05-09 00:03:03 +08:00
|
|
|
|
'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
|
2015-12-09 17:50:11 +08:00
|
|
|
|
% (vendor, video_id, appname),
|
2014-09-08 22:26:42 +08:00
|
|
|
|
video_id, 'Downloading media JSON')
|
2014-09-05 03:02:47 +08:00
|
|
|
|
|
2015-05-30 17:15:42 +08:00
|
|
|
|
if data.get('status') == 'inactive':
|
|
|
|
|
raise ExtractorError(
|
|
|
|
|
'Video %s is no longer available' % video_id, expected=True)
|
|
|
|
|
|
2015-12-11 05:18:42 +08:00
|
|
|
|
info = {
|
|
|
|
|
'formats': [],
|
|
|
|
|
}
|
|
|
|
|
if len(video_id) == 5:
|
|
|
|
|
if appname == 'bttv':
|
|
|
|
|
info = self._extract_video_info('btno', video_id)
|
|
|
|
|
elif appname == 'aptv':
|
|
|
|
|
info = self._extract_video_info('ap', video_id)
|
|
|
|
|
|
2014-09-08 22:26:42 +08:00
|
|
|
|
streams = data['streamUrls']
|
2015-05-30 18:12:07 +08:00
|
|
|
|
stream_type = data.get('streamType')
|
2014-09-05 03:02:47 +08:00
|
|
|
|
|
2014-09-08 22:26:42 +08:00
|
|
|
|
formats = []
|
2014-09-05 03:02:47 +08:00
|
|
|
|
|
2014-09-08 22:26:42 +08:00
|
|
|
|
hls_url = streams.get('hls')
|
|
|
|
|
if hls_url:
|
2015-12-09 17:50:11 +08:00
|
|
|
|
m3u8_formats = self._extract_m3u8_formats(
|
|
|
|
|
hls_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
|
2015-12-06 14:43:46 +08:00
|
|
|
|
if m3u8_formats:
|
|
|
|
|
formats.extend(m3u8_formats)
|
2014-09-05 03:02:47 +08:00
|
|
|
|
|
2014-09-08 22:26:42 +08:00
|
|
|
|
hds_url = streams.get('hds')
|
2015-12-28 00:44:55 +08:00
|
|
|
|
if hds_url:
|
|
|
|
|
hdcore_sign = 'hdcore=3.7.0'
|
2015-12-09 17:50:11 +08:00
|
|
|
|
f4m_formats = self._extract_f4m_formats(
|
2015-12-28 00:44:55 +08:00
|
|
|
|
hds_url + '?%s' % hdcore_sign, video_id, f4m_id='hds', fatal=False)
|
2015-12-06 14:43:46 +08:00
|
|
|
|
if f4m_formats:
|
2015-12-28 00:44:55 +08: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-05 03:02:47 +08:00
|
|
|
|
|
2015-12-06 14:43:46 +08:00
|
|
|
|
mp4_urls = streams.get('pseudostreaming') or []
|
2014-09-08 22:26:42 +08:00
|
|
|
|
mp4_url = streams.get('mp4')
|
|
|
|
|
if mp4_url:
|
2015-12-06 14:43:46 +08:00
|
|
|
|
mp4_urls.append(mp4_url)
|
|
|
|
|
for mp4_url in mp4_urls:
|
|
|
|
|
format_info = {
|
|
|
|
|
'url': mp4_url,
|
|
|
|
|
}
|
|
|
|
|
mobj = re.search('(\d+)_(\d+)_(\d+)', mp4_url)
|
|
|
|
|
if mobj:
|
2015-12-22 22:54:51 +08:00
|
|
|
|
tbr = int(mobj.group(3))
|
2015-12-06 14:43:46 +08:00
|
|
|
|
format_info.update({
|
|
|
|
|
'width': int(mobj.group(1)),
|
|
|
|
|
'height': int(mobj.group(2)),
|
2015-12-22 22:54:51 +08:00
|
|
|
|
'tbr': tbr,
|
|
|
|
|
'format_id': 'mp4-%s' % tbr,
|
2014-09-08 22:26:42 +08:00
|
|
|
|
})
|
2015-12-06 14:43:46 +08:00
|
|
|
|
formats.append(format_info)
|
|
|
|
|
|
2015-12-11 05:18:42 +08:00
|
|
|
|
info['formats'].extend(formats)
|
2014-09-08 22:26:42 +08:00
|
|
|
|
|
2015-12-11 05:18:42 +08:00
|
|
|
|
self._sort_formats(info['formats'])
|
|
|
|
|
|
|
|
|
|
info.update({
|
2014-09-08 22:26:42 +08:00
|
|
|
|
'id': video_id,
|
2015-10-30 16:48:56 +08:00
|
|
|
|
'title': self._live_title(data['title']) if stream_type == 'live' else data['title'],
|
2014-09-08 22:26:42 +08: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 18:12:07 +08:00
|
|
|
|
'is_live': True if stream_type == 'live' else False,
|
2015-12-11 05:18:42 +08:00
|
|
|
|
})
|
|
|
|
|
return info
|
2015-05-09 00:18:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BTArticleIE(InfoExtractor):
|
2015-05-09 00:59:50 +08:00
|
|
|
|
IE_NAME = 'bt:article'
|
|
|
|
|
IE_DESC = 'Bergens Tidende Articles'
|
2015-05-09 00:18:43 +08:00
|
|
|
|
_VALID_URL = 'http://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
|
|
|
|
|
_TEST = {
|
|
|
|
|
'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
|
2015-12-22 22:54:51 +08:00
|
|
|
|
'md5': '2acbe8ad129b3469d5ae51b1158878df',
|
2015-05-09 00:18:43 +08:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '23199',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Alrekstad internat',
|
|
|
|
|
'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
|
|
|
|
|
'thumbnail': 're:^https?://.*\.jpg',
|
|
|
|
|
'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 22:54:51 +08:00
|
|
|
|
r'<video[^>]+data-id="(\d+)"', webpage, 'video id')
|
2015-12-09 17:50:11 +08:00
|
|
|
|
return self.url_result('bttv:%s' % video_id, 'VGTV')
|
2015-05-09 00:59:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BTVestlendingenIE(InfoExtractor):
|
|
|
|
|
IE_NAME = 'bt:vestlendingen'
|
|
|
|
|
IE_DESC = 'Bergens Tidende - Vestlendingen'
|
|
|
|
|
_VALID_URL = 'http://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
|
2015-12-22 22:54:51 +08:00
|
|
|
|
_TESTS = [{
|
2015-05-09 00:59:50 +08: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 22:54:51 +08: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-09 00:59:50 +08:00
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2015-12-09 17:50:11 +08:00
|
|
|
|
return self.url_result('bttv:%s' % self._match_id(url), 'VGTV')
|