]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/vgtv.py
[moniker] Add tests for #7244
[yt-dlp.git] / youtube_dl / extractor / vgtv.py
CommitLineData
78149a96
MK
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
4d454c5e
S
7from ..utils import (
8 ExtractorError,
9 float_or_none,
10)
78149a96 11
78149a96
MK
12
13class VGTVIE(InfoExtractor):
34e7dc81 14 IE_DESC = 'VGTV and BTTV'
0ceab847
S
15 _VALID_URL = r'''(?x)
16 (?:
17 vgtv:|
18 http://(?:www\.)?
19 )
20 (?P<host>vgtv|bt)
21 (?:
22 :|
5c0b2c16 23 \.no/(?:tv/)?\#!/(?:video|live)/
0ceab847
S
24 )
25 (?P<id>[0-9]+)
26 '''
321c1e44
S
27 _TESTS = [
28 {
29 # streamType: vod
30 'url': 'http://www.vgtv.no/#!/video/84196/hevnen-er-soet-episode-10-abu',
31 'md5': 'b8be7a234cebb840c0d512c78013e02f',
32 'info_dict': {
33 'id': '84196',
34 'ext': 'mp4',
eecd6a46 35 'title': 'Hevnen er søt: Episode 10 - Abu',
321c1e44
S
36 'description': 'md5:e25e4badb5f544b04341e14abdc72234',
37 'thumbnail': 're:^https?://.*\.jpg',
38 'duration': 648.000,
39 'timestamp': 1404626400,
3fbeb95e
S
40 'upload_date': '20140706',
41 'view_count': int,
321c1e44
S
42 },
43 },
44 {
45 # streamType: wasLive
46 'url': 'http://www.vgtv.no/#!/live/100764/opptak-vgtv-foelger-em-kvalifiseringen',
47 'info_dict': {
48 'id': '100764',
b7bb0df2 49 'ext': 'flv',
321c1e44
S
50 'title': 'OPPTAK: VGTV følger EM-kvalifiseringen',
51 'description': 'md5:3772d9c0dc2dff92a886b60039a7d4d3',
52 'thumbnail': 're:^https?://.*\.jpg',
eecd6a46 53 'duration': 9103.0,
321c1e44 54 'timestamp': 1410113864,
3fbeb95e
S
55 'upload_date': '20140907',
56 'view_count': int,
321c1e44
S
57 },
58 'params': {
59 # m3u8 download
60 'skip_download': True,
61 },
62 },
63 {
64 # streamType: live
b4dd9835 65 'url': 'http://www.vgtv.no/#!/live/113063/direkte-v75-fra-solvalla',
321c1e44 66 'info_dict': {
b4dd9835 67 'id': '113063',
b7bb0df2 68 'ext': 'flv',
b4dd9835
S
69 'title': 're:^DIREKTE: V75 fra Solvalla [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
70 'description': 'md5:b3743425765355855f88e096acc93231',
321c1e44
S
71 'thumbnail': 're:^https?://.*\.jpg',
72 'duration': 0,
b4dd9835
S
73 'timestamp': 1432975582,
74 'upload_date': '20150530',
3fbeb95e 75 'view_count': int,
321c1e44
S
76 },
77 'params': {
78 # m3u8 download
79 'skip_download': True,
80 },
81 },
34e7dc81
S
82 {
83 'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
84 'only_matching': True,
85 },
321c1e44 86 ]
78149a96 87
321c1e44 88 def _real_extract(self, url):
34e7dc81
S
89 mobj = re.match(self._VALID_URL, url)
90 video_id = mobj.group('id')
91 host = mobj.group('host')
92
93 HOST_WEBSITES = {
94 'vgtv': 'vgtv',
95 'bt': 'bttv',
96 }
97
321c1e44 98 data = self._download_json(
34e7dc81
S
99 'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
100 % (host, video_id, HOST_WEBSITES[host]),
321c1e44 101 video_id, 'Downloading media JSON')
78149a96 102
4d454c5e
S
103 if data.get('status') == 'inactive':
104 raise ExtractorError(
105 'Video %s is no longer available' % video_id, expected=True)
106
321c1e44 107 streams = data['streamUrls']
b4dd9835 108 stream_type = data.get('streamType')
78149a96 109
321c1e44 110 formats = []
78149a96 111
321c1e44
S
112 hls_url = streams.get('hls')
113 if hls_url:
f2e00565
S
114 formats.extend(self._extract_m3u8_formats(
115 hls_url, video_id, 'mp4', m3u8_id='hls'))
78149a96 116
321c1e44 117 hds_url = streams.get('hds')
5c2191a6 118 # wasLive hds are always 404
b4dd9835 119 if hds_url and stream_type != 'wasLive':
f2e00565
S
120 formats.extend(self._extract_f4m_formats(
121 hds_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
122 video_id, f4m_id='hds'))
78149a96 123
321c1e44
S
124 mp4_url = streams.get('mp4')
125 if mp4_url:
126 _url = hls_url or hds_url
127 MP4_URL_TEMPLATE = '%s/%%s.%s' % (mp4_url.rpartition('/')[0], mp4_url.rpartition('.')[-1])
128 for mp4_format in _url.split(','):
129 m = re.search('(?P<width>\d+)_(?P<height>\d+)_(?P<vbr>\d+)', mp4_format)
130 if not m:
131 continue
132 width = int(m.group('width'))
133 height = int(m.group('height'))
134 vbr = int(m.group('vbr'))
135 formats.append({
136 'url': MP4_URL_TEMPLATE % mp4_format,
137 'format_id': 'mp4-%s' % vbr,
138 'width': width,
139 'height': height,
140 'vbr': vbr,
141 'preference': 1,
142 })
143 self._sort_formats(formats)
144
145 return {
146 'id': video_id,
b4dd9835 147 'title': self._live_title(data['title']),
321c1e44
S
148 'description': data['description'],
149 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
150 'timestamp': data['published'],
151 'duration': float_or_none(data['duration'], 1000),
152 'view_count': data['displays'],
153 'formats': formats,
b4dd9835 154 'is_live': True if stream_type == 'live' else False,
5f6a1245 155 }
0ceab847
S
156
157
158class BTArticleIE(InfoExtractor):
fe373287
S
159 IE_NAME = 'bt:article'
160 IE_DESC = 'Bergens Tidende Articles'
0ceab847
S
161 _VALID_URL = 'http://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
162 _TEST = {
163 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
164 'md5': 'd055e8ee918ef2844745fcfd1a4175fb',
165 'info_dict': {
166 'id': '23199',
167 'ext': 'mp4',
168 'title': 'Alrekstad internat',
169 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
170 'thumbnail': 're:^https?://.*\.jpg',
171 'duration': 191,
172 'timestamp': 1289991323,
173 'upload_date': '20101117',
174 'view_count': int,
175 },
176 }
177
178 def _real_extract(self, url):
179 webpage = self._download_webpage(url, self._match_id(url))
180 video_id = self._search_regex(
181 r'SVP\.Player\.load\(\s*(\d+)', webpage, 'video id')
182 return self.url_result('vgtv:bt:%s' % video_id, 'VGTV')
fe373287
S
183
184
185class BTVestlendingenIE(InfoExtractor):
186 IE_NAME = 'bt:vestlendingen'
187 IE_DESC = 'Bergens Tidende - Vestlendingen'
188 _VALID_URL = 'http://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
189 _TEST = {
190 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
191 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
192 'info_dict': {
193 'id': '86588',
194 'ext': 'mov',
195 'title': 'Otto Wollertsen',
196 'description': 'Vestlendingen Otto Fredrik Wollertsen',
197 'timestamp': 1430473209,
198 'upload_date': '20150501',
199 },
200 }
201
202 def _real_extract(self, url):
203 return self.url_result('xstream:btno:%s' % self._match_id(url), 'Xstream')