[ie/dplay] Fix extractors (#10471)
[yt-dlp3.git] / yt_dlp / extractor / vgtv.py
blob1eb25530f833f8e470a873704d0808c8c381e092
1 import re
3 from .common import InfoExtractor
4 from .xstream import XstreamIE
5 from ..utils import (
6 ExtractorError,
7 float_or_none,
8 try_get,
12 class VGTVIE(XstreamIE): # XXX: Do not subclass from concrete IE
13 IE_DESC = 'VGTV, BTTV, FTV, Aftenposten and Aftonbladet'
14 _GEO_BYPASS = False
16 _HOST_TO_APPNAME = {
17 'tv.vg.no': 'vgtv',
18 'vgtv.no': 'vgtv',
19 'bt.no/tv': 'bttv',
20 'aftenbladet.no/tv': 'satv',
21 'fvn.no/fvntv': 'fvntv',
22 'aftenposten.no/webtv': 'aptv',
23 'ap.vgtv.no/webtv': 'aptv',
24 'tv.aftonbladet.se': 'abtv',
25 # obsolete URL schemas, kept in order to save one HTTP redirect
26 'tv.aftonbladet.se/abtv': 'abtv',
27 'www.aftonbladet.se/tv': 'abtv',
30 _APP_NAME_TO_VENDOR = {
31 'vgtv': 'vgtv',
32 'bttv': 'bt',
33 'satv': 'sa',
34 'fvntv': 'fvn',
35 'aptv': 'ap',
36 'abtv': 'ab',
39 _VALID_URL = r'''(?x)
40 (?:https?://(?:www\.)?
41 (?P<host>
45 (?:
46 (?:\#!/)?(?:video|live)/|
47 embed?.*id=|
48 a(?:rticles)?/
50 (?P<appname>
52 ):)
53 (?P<id>\d+)
54 '''.format('|'.join(_HOST_TO_APPNAME.keys()), '|'.join(_APP_NAME_TO_VENDOR.keys()))
56 _TESTS = [
58 # streamType: vod
59 'url': 'http://www.vgtv.no/#!/video/84196/hevnen-er-soet-episode-10-abu',
60 'md5': 'b8be7a234cebb840c0d512c78013e02f',
61 'info_dict': {
62 'id': '84196',
63 'ext': 'mp4',
64 'title': 'Hevnen er søt: Episode 10 - Abu',
65 'description': 'md5:e25e4badb5f544b04341e14abdc72234',
66 'thumbnail': r're:^https?://.*\.jpg',
67 'duration': 648.000,
68 'timestamp': 1404626400,
69 'upload_date': '20140706',
70 'view_count': int,
74 # streamType: wasLive
75 'url': 'http://www.vgtv.no/#!/live/100764/opptak-vgtv-foelger-em-kvalifiseringen',
76 'info_dict': {
77 'id': '100764',
78 'ext': 'flv',
79 'title': 'OPPTAK: VGTV følger EM-kvalifiseringen',
80 'description': 'md5:3772d9c0dc2dff92a886b60039a7d4d3',
81 'thumbnail': r're:^https?://.*\.jpg',
82 'duration': 9103.0,
83 'timestamp': 1410113864,
84 'upload_date': '20140907',
85 'view_count': int,
87 'params': {
88 # m3u8 download
89 'skip_download': True,
91 'skip': 'Video is no longer available',
94 # streamType: wasLive
95 'url': 'http://www.vgtv.no/#!/live/113063/direkte-v75-fra-solvalla',
96 'info_dict': {
97 'id': '113063',
98 'ext': 'mp4',
99 'title': 'V75 fra Solvalla 30.05.15',
100 'description': 'md5:b3743425765355855f88e096acc93231',
101 'thumbnail': r're:^https?://.*\.jpg',
102 'duration': 25966,
103 'timestamp': 1432975582,
104 'upload_date': '20150530',
105 'view_count': int,
107 'params': {
108 # m3u8 download
109 'skip_download': True,
113 'url': 'http://www.aftenposten.no/webtv/#!/video/21039/trailer-sweatshop-i-can-t-take-any-more',
114 'md5': 'fd828cd29774a729bf4d4425fe192972',
115 'info_dict': {
116 'id': '21039',
117 'ext': 'mp4',
118 'title': 'TRAILER: «SWEATSHOP» - I can´t take any more',
119 'description': 'md5:21891f2b0dd7ec2f78d84a50e54f8238',
120 'duration': 66,
121 'timestamp': 1417002452,
122 'upload_date': '20141126',
123 'view_count': int,
125 'params': {
126 # m3u8 download
127 'skip_download': True,
131 'url': 'https://tv.vg.no/video/241779/politiets-ekstremkjoering',
132 'only_matching': True,
135 'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
136 'only_matching': True,
139 'url': 'http://ap.vgtv.no/webtv#!/video/111084/de-nye-bysyklene-lettere-bedre-gir-stoerre-hjul-og-feste-til-mobil',
140 'only_matching': True,
143 # geoblocked
144 'url': 'http://www.vgtv.no/#!/video/127205/inside-the-mind-of-favela-funk',
145 'only_matching': True,
148 'url': 'https://tv.aftonbladet.se/video/36015/vulkanutbrott-i-rymden-nu-slapper-nasa-bilderna',
149 'only_matching': True,
152 'url': 'http://tv.aftonbladet.se/abtv/articles/36015',
153 'only_matching': True,
156 'url': 'https://www.aftonbladet.se/tv/a/36015',
157 'only_matching': True,
160 'url': 'abtv:140026',
161 'only_matching': True,
164 'url': 'http://www.vgtv.no/video/84196/hevnen-er-soet-episode-10-abu',
165 'only_matching': True,
169 def _real_extract(self, url):
170 mobj = self._match_valid_url(url)
171 video_id = mobj.group('id')
172 host = mobj.group('host')
173 appname = self._HOST_TO_APPNAME[host] if host else mobj.group('appname')
174 vendor = self._APP_NAME_TO_VENDOR[appname]
176 data = self._download_json(
177 f'http://svp.vg.no/svp/api/v1/{vendor}/assets/{video_id}?appName={appname}-website',
178 video_id, 'Downloading media JSON')
180 if data.get('status') == 'inactive':
181 raise ExtractorError(
182 f'Video {video_id} is no longer available', expected=True)
184 info = {
185 'formats': [],
187 if len(video_id) == 5:
188 if appname == 'bttv':
189 info = self._extract_video_info('btno', video_id)
191 streams = data['streamUrls']
192 stream_type = data.get('streamType')
193 is_live = stream_type == 'live'
194 formats = []
196 hls_url = streams.get('hls')
197 if hls_url:
198 formats.extend(self._extract_m3u8_formats(
199 hls_url, video_id, 'mp4', live=is_live, m3u8_id='hls', fatal=False))
201 hds_url = streams.get('hds')
202 if hds_url:
203 hdcore_sign = 'hdcore=3.7.0'
204 f4m_formats = self._extract_f4m_formats(
205 hds_url + f'?{hdcore_sign}', video_id, f4m_id='hds', fatal=False)
206 if f4m_formats:
207 for entry in f4m_formats:
208 # URLs without the extra param induce an 404 error
209 entry.update({'extra_param_to_segment_url': hdcore_sign})
210 formats.append(entry)
212 mp4_urls = streams.get('pseudostreaming') or []
213 mp4_url = streams.get('mp4')
214 if mp4_url:
215 mp4_urls.append(mp4_url)
216 for mp4_url in mp4_urls:
217 format_info = {
218 'url': mp4_url,
220 mobj = re.search(r'(\d+)_(\d+)_(\d+)', mp4_url)
221 if mobj:
222 tbr = int(mobj.group(3))
223 format_info.update({
224 'width': int(mobj.group(1)),
225 'height': int(mobj.group(2)),
226 'tbr': tbr,
227 'format_id': f'mp4-{tbr}',
229 formats.append(format_info)
231 info['formats'].extend(formats)
233 if not info['formats']:
234 properties = try_get(
235 data, lambda x: x['streamConfiguration']['properties'], list)
236 if properties and 'geoblocked' in properties:
237 raise self.raise_geo_restricted(
238 countries=[host.rpartition('.')[-1].partition('/')[0].upper()])
240 info.update({
241 'id': video_id,
242 'title': data['title'],
243 'description': data['description'],
244 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
245 'timestamp': data['published'],
246 'duration': float_or_none(data['duration'], 1000),
247 'view_count': data['displays'],
248 'is_live': is_live,
250 return info
253 class BTArticleIE(InfoExtractor):
254 IE_NAME = 'bt:article'
255 IE_DESC = 'Bergens Tidende Articles'
256 _VALID_URL = r'https?://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
257 _TEST = {
258 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
259 'md5': '2acbe8ad129b3469d5ae51b1158878df',
260 'info_dict': {
261 'id': '23199',
262 'ext': 'mp4',
263 'title': 'Alrekstad internat',
264 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
265 'thumbnail': r're:^https?://.*\.jpg',
266 'duration': 191,
267 'timestamp': 1289991323,
268 'upload_date': '20101117',
269 'view_count': int,
273 def _real_extract(self, url):
274 webpage = self._download_webpage(url, self._match_id(url))
275 video_id = self._search_regex(
276 r'<video[^>]+data-id="(\d+)"', webpage, 'video id')
277 return self.url_result(f'bttv:{video_id}', 'VGTV')
280 class BTVestlendingenIE(InfoExtractor):
281 IE_NAME = 'bt:vestlendingen'
282 IE_DESC = 'Bergens Tidende - Vestlendingen'
283 _VALID_URL = r'https?://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
284 _TESTS = [{
285 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
286 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
287 'info_dict': {
288 'id': '86588',
289 'ext': 'mov',
290 'title': 'Otto Wollertsen',
291 'description': 'Vestlendingen Otto Fredrik Wollertsen',
292 'timestamp': 1430473209,
293 'upload_date': '20150501',
295 'skip': '404 Error',
296 }, {
297 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86255',
298 'md5': 'a2893f8632e96389f4bdf36aa9463ceb',
299 'info_dict': {
300 'id': '86255',
301 'ext': 'mov',
302 'title': 'Du må tåle å fryse og være sulten',
303 'description': 'md5:b8046f4d022d5830ddab04865791d063',
304 'upload_date': '20150321',
305 'timestamp': 1426942023,
309 def _real_extract(self, url):
310 return self.url_result(f'bttv:{self._match_id(url)}', 'VGTV')