]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/orf.py
cc3c003fa024f2833fd9afd0b72dbf5265540dd3
[yt-dlp.git] / yt_dlp / extractor / orf.py
1 import functools
2 import re
3
4 from .common import InfoExtractor
5 from ..networking import HEADRequest
6 from ..utils import (
7 clean_html,
8 determine_ext,
9 float_or_none,
10 InAdvancePagedList,
11 int_or_none,
12 join_nonempty,
13 orderedSet,
14 remove_end,
15 make_archive_id,
16 smuggle_url,
17 strip_jsonp,
18 try_call,
19 unescapeHTML,
20 unified_strdate,
21 unsmuggle_url,
22 url_or_none,
23 )
24
25
26 class ORFTVthekIE(InfoExtractor):
27 IE_NAME = 'orf:tvthek'
28 IE_DESC = 'ORF TVthek'
29 _VALID_URL = r'(?P<url>https?://tvthek\.orf\.at/(?:(?:[^/]+/){2}){1,2}(?P<id>\d+))(/[^/]+/(?P<vid>\d+))?(?:$|[?#])'
30
31 _TESTS = [{
32 'url': 'https://tvthek.orf.at/profile/ZIB-2/1211/ZIB-2/14121079',
33 'info_dict': {
34 'id': '14121079',
35 },
36 'playlist_count': 11,
37 'params': {'noplaylist': True}
38 }, {
39 'url': 'https://tvthek.orf.at/profile/ZIB-2/1211/ZIB-2/14121079/Umfrage-Welches-Tier-ist-Sebastian-Kurz/15083150',
40 'info_dict': {
41 'id': '14121079',
42 },
43 'playlist_count': 1,
44 'params': {'playlist_items': '5'}
45 }, {
46 'url': 'https://tvthek.orf.at/profile/ZIB-2/1211/ZIB-2/14121079/Umfrage-Welches-Tier-ist-Sebastian-Kurz/15083150',
47 'info_dict': {
48 'id': '14121079',
49 'playlist_count': 1
50 },
51 'playlist': [{
52 'info_dict': {
53 'id': '15083150',
54 'ext': 'mp4',
55 'description': 'md5:7be1c485425f5f255a5e4e4815e77d04',
56 'thumbnail': 'https://api-tvthek.orf.at/uploads/media/segments/0130/59/824271ea35cd8931a0fb08ab316a5b0a1562342c.jpeg',
57 'title': 'Umfrage: Welches Tier ist Sebastian Kurz?',
58 }
59 }],
60 'playlist_count': 1,
61 'params': {'noplaylist': True, 'skip_download': 'm3u8'}
62 }, {
63 'url': 'http://tvthek.orf.at/program/Aufgetischt/2745173/Aufgetischt-Mit-der-Steirischen-Tafelrunde/8891389',
64 'playlist': [{
65 'md5': '2942210346ed779588f428a92db88712',
66 'info_dict': {
67 'id': '8896777',
68 'ext': 'mp4',
69 'title': 'Aufgetischt: Mit der Steirischen Tafelrunde',
70 'description': 'md5:c1272f0245537812d4e36419c207b67d',
71 'duration': 2668,
72 'upload_date': '20141208',
73 },
74 }],
75 'skip': 'Blocked outside of Austria / Germany',
76 }, {
77 'url': 'http://tvthek.orf.at/topic/Im-Wandel-der-Zeit/8002126/Best-of-Ingrid-Thurnher/7982256',
78 'info_dict': {
79 'id': '7982259',
80 'ext': 'mp4',
81 'title': 'Best of Ingrid Thurnher',
82 'upload_date': '20140527',
83 'description': 'Viele Jahre war Ingrid Thurnher das "Gesicht" der ZIB 2. Vor ihrem Wechsel zur ZIB 2 im Jahr 1995 moderierte sie unter anderem "Land und Leute", "Österreich-Bild" und "Niederösterreich heute".',
84 },
85 'params': {
86 'skip_download': True, # rtsp downloads
87 },
88 'skip': 'Blocked outside of Austria / Germany',
89 }, {
90 'url': 'http://tvthek.orf.at/topic/Fluechtlingskrise/10463081/Heimat-Fremde-Heimat/13879132/Senioren-betreuen-Migrantenkinder/13879141',
91 'only_matching': True,
92 }, {
93 'url': 'http://tvthek.orf.at/profile/Universum/35429',
94 'only_matching': True,
95 }]
96
97 def _pagefunc(self, url, data_jsb, n, *, image=None):
98 sd = data_jsb[n]
99 video_id, title = str(sd['id']), sd['title']
100 formats = []
101 for fd in sd['sources']:
102 src = url_or_none(fd.get('src'))
103 if not src:
104 continue
105 format_id = join_nonempty('delivery', 'quality', 'quality_string', from_dict=fd)
106 ext = determine_ext(src)
107 if ext == 'm3u8':
108 m3u8_formats = self._extract_m3u8_formats(
109 src, video_id, 'mp4', m3u8_id=format_id, fatal=False, note=f'Downloading {format_id} m3u8 manifest')
110 if any('/geoprotection' in f['url'] for f in m3u8_formats):
111 self.raise_geo_restricted()
112 formats.extend(m3u8_formats)
113 elif ext == 'f4m':
114 formats.extend(self._extract_f4m_formats(
115 src, video_id, f4m_id=format_id, fatal=False))
116 elif ext == 'mpd':
117 formats.extend(self._extract_mpd_formats(
118 src, video_id, mpd_id=format_id, fatal=False, note=f'Downloading {format_id} mpd manifest'))
119 else:
120 formats.append({
121 'format_id': format_id,
122 'url': src,
123 'protocol': fd.get('protocol'),
124 })
125
126 # Check for geoblocking.
127 # There is a property is_geoprotection, but that's always false
128 geo_str = sd.get('geoprotection_string')
129 http_url = next(
130 (f['url'] for f in formats if re.match(r'^https?://.*\.mp4$', f['url'])),
131 None) if geo_str else None
132 if http_url:
133 self._request_webpage(
134 HEADRequest(http_url), video_id, fatal=False, note='Testing for geoblocking',
135 errnote=f'This video seems to be blocked outside of {geo_str}. You may want to try the streaming-* formats')
136
137 subtitles = {}
138 for sub in sd.get('subtitles', []):
139 sub_src = sub.get('src')
140 if not sub_src:
141 continue
142 subtitles.setdefault(sub.get('lang', 'de-AT'), []).append({
143 'url': sub_src,
144 })
145
146 upload_date = unified_strdate(sd.get('created_date'))
147
148 thumbnails = []
149 preview = sd.get('preview_image_url')
150 if preview:
151 thumbnails.append({
152 'id': 'preview',
153 'url': preview,
154 'preference': 0,
155 })
156 image = sd.get('image_full_url') or image
157 if image:
158 thumbnails.append({
159 'id': 'full',
160 'url': image,
161 'preference': 1,
162 })
163
164 yield {
165 'id': video_id,
166 'title': title,
167 'webpage_url': smuggle_url(f'{url}/part/{video_id}', {'force_noplaylist': True}),
168 'formats': formats,
169 'subtitles': subtitles,
170 'description': sd.get('description'),
171 'duration': int_or_none(sd.get('duration_in_seconds')),
172 'upload_date': upload_date,
173 'thumbnails': thumbnails,
174 }
175
176 def _real_extract(self, url):
177 url, smuggled_data = unsmuggle_url(url)
178 playlist_id, video_id, base_url = self._match_valid_url(url).group('id', 'vid', 'url')
179 webpage = self._download_webpage(url, playlist_id)
180
181 data_jsb = self._parse_json(
182 self._search_regex(
183 r'<div[^>]+class=(["\']).*?VideoPlaylist.*?\1[^>]+data-jsb=(["\'])(?P<json>.+?)\2',
184 webpage, 'playlist', group='json'),
185 playlist_id, transform_source=unescapeHTML)['playlist']['videos']
186
187 if not self._yes_playlist(playlist_id, video_id, smuggled_data):
188 data_jsb = [sd for sd in data_jsb if str(sd.get('id')) == video_id]
189
190 playlist_count = len(data_jsb)
191 image = self._og_search_thumbnail(webpage) if playlist_count == 1 else None
192
193 page_func = functools.partial(self._pagefunc, base_url, data_jsb, image=image)
194 return {
195 '_type': 'playlist',
196 'entries': InAdvancePagedList(page_func, playlist_count, 1),
197 'id': playlist_id,
198 }
199
200
201 class ORFRadioIE(InfoExtractor):
202 IE_NAME = 'orf:radio'
203
204 STATION_INFO = {
205 'fm4': ('fm4', 'fm4', 'orffm4'),
206 'noe': ('noe', 'oe2n', 'orfnoe'),
207 'wien': ('wie', 'oe2w', 'orfwie'),
208 'burgenland': ('bgl', 'oe2b', 'orfbgl'),
209 'ooe': ('ooe', 'oe2o', 'orfooe'),
210 'steiermark': ('stm', 'oe2st', 'orfstm'),
211 'kaernten': ('ktn', 'oe2k', 'orfktn'),
212 'salzburg': ('sbg', 'oe2s', 'orfsbg'),
213 'tirol': ('tir', 'oe2t', 'orftir'),
214 'vorarlberg': ('vbg', 'oe2v', 'orfvbg'),
215 'oe3': ('oe3', 'oe3', 'orfoe3'),
216 'oe1': ('oe1', 'oe1', 'orfoe1'),
217 }
218 _STATION_RE = '|'.join(map(re.escape, STATION_INFO.keys()))
219
220 _VALID_URL = rf'''(?x)
221 https?://(?:
222 (?P<station>{_STATION_RE})\.orf\.at/player|
223 radiothek\.orf\.at/(?P<station2>{_STATION_RE})
224 )/(?P<date>[0-9]+)/(?P<show>\w+)'''
225
226 _TESTS = [{
227 'url': 'https://radiothek.orf.at/ooe/20220801/OGMO',
228 'info_dict': {
229 'id': 'OGMO',
230 'title': 'Guten Morgen OÖ',
231 'description': 'md5:a3f6083399ef92b8cbe2d421b180835a',
232 },
233 'playlist': [{
234 'md5': 'f33147d954a326e338ea52572c2810e8',
235 'info_dict': {
236 'id': '2022-08-01_0459_tl_66_7DaysMon1_319062',
237 'ext': 'mp3',
238 'title': 'Guten Morgen OÖ',
239 'upload_date': '20220801',
240 'duration': 18000,
241 'timestamp': 1659322789,
242 'description': 'md5:a3f6083399ef92b8cbe2d421b180835a',
243 }
244 }]
245 }, {
246 'url': 'https://ooe.orf.at/player/20220801/OGMO',
247 'info_dict': {
248 'id': 'OGMO',
249 'title': 'Guten Morgen OÖ',
250 'description': 'md5:a3f6083399ef92b8cbe2d421b180835a',
251 },
252 'playlist': [{
253 'md5': 'f33147d954a326e338ea52572c2810e8',
254 'info_dict': {
255 'id': '2022-08-01_0459_tl_66_7DaysMon1_319062',
256 'ext': 'mp3',
257 'title': 'Guten Morgen OÖ',
258 'upload_date': '20220801',
259 'duration': 18000,
260 'timestamp': 1659322789,
261 'description': 'md5:a3f6083399ef92b8cbe2d421b180835a',
262 }
263 }]
264 }, {
265 'url': 'http://fm4.orf.at/player/20170107/4CC',
266 'only_matching': True,
267 }, {
268 'url': 'https://noe.orf.at/player/20200423/NGM',
269 'only_matching': True,
270 }, {
271 'url': 'https://wien.orf.at/player/20200423/WGUM',
272 'only_matching': True,
273 }, {
274 'url': 'https://burgenland.orf.at/player/20200423/BGM',
275 'only_matching': True,
276 }, {
277 'url': 'https://steiermark.orf.at/player/20200423/STGMS',
278 'only_matching': True,
279 }, {
280 'url': 'https://kaernten.orf.at/player/20200423/KGUMO',
281 'only_matching': True,
282 }, {
283 'url': 'https://salzburg.orf.at/player/20200423/SGUM',
284 'only_matching': True,
285 }, {
286 'url': 'https://tirol.orf.at/player/20200423/TGUMO',
287 'only_matching': True,
288 }, {
289 'url': 'https://vorarlberg.orf.at/player/20200423/VGUM',
290 'only_matching': True,
291 }, {
292 'url': 'https://oe3.orf.at/player/20200424/3WEK',
293 'only_matching': True,
294 }, {
295 'url': 'http://oe1.orf.at/player/20170108/456544',
296 'md5': '34d8a6e67ea888293741c86a099b745b',
297 'info_dict': {
298 'id': '2017-01-08_0759_tl_51_7DaysSun6_256141',
299 'ext': 'mp3',
300 'title': 'Morgenjournal',
301 'duration': 609,
302 'timestamp': 1483858796,
303 'upload_date': '20170108',
304 },
305 'skip': 'Shows from ORF radios are only available for 7 days.'
306 }]
307
308 def _entries(self, data, station):
309 _, loop_station, old_ie = self.STATION_INFO[station]
310 for info in data['streams']:
311 item_id = info.get('loopStreamId')
312 if not item_id:
313 continue
314 video_id = item_id.replace('.mp3', '')
315 yield {
316 'id': video_id,
317 'ext': 'mp3',
318 'url': f'https://loopstream01.apa.at/?channel={loop_station}&id={item_id}',
319 '_old_archive_ids': [make_archive_id(old_ie, video_id)],
320 'title': data.get('title'),
321 'description': clean_html(data.get('subtitle')),
322 'duration': try_call(lambda: (info['end'] - info['start']) / 1000),
323 'timestamp': int_or_none(info.get('start'), scale=1000),
324 'series': data.get('programTitle'),
325 }
326
327 def _real_extract(self, url):
328 station, station2, show_date, show_id = self._match_valid_url(url).group('station', 'station2', 'date', 'show')
329 api_station, _, _ = self.STATION_INFO[station or station2]
330 data = self._download_json(
331 f'http://audioapi.orf.at/{api_station}/api/json/current/broadcast/{show_id}/{show_date}', show_id)
332
333 return self.playlist_result(
334 self._entries(data, station or station2), show_id, data.get('title'), clean_html(data.get('subtitle')))
335
336
337 class ORFIPTVIE(InfoExtractor):
338 IE_NAME = 'orf:iptv'
339 IE_DESC = 'iptv.ORF.at'
340 _VALID_URL = r'https?://iptv\.orf\.at/(?:#/)?stories/(?P<id>\d+)'
341
342 _TEST = {
343 'url': 'http://iptv.orf.at/stories/2275236/',
344 'md5': 'c8b22af4718a4b4af58342529453e3e5',
345 'info_dict': {
346 'id': '350612',
347 'ext': 'flv',
348 'title': 'Weitere Evakuierungen um Vulkan Calbuco',
349 'description': 'md5:d689c959bdbcf04efeddedbf2299d633',
350 'duration': 68.197,
351 'thumbnail': r're:^https?://.*\.jpg$',
352 'upload_date': '20150425',
353 },
354 }
355
356 def _real_extract(self, url):
357 story_id = self._match_id(url)
358
359 webpage = self._download_webpage(
360 'http://iptv.orf.at/stories/%s' % story_id, story_id)
361
362 video_id = self._search_regex(
363 r'data-video(?:id)?="(\d+)"', webpage, 'video id')
364
365 data = self._download_json(
366 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
367 video_id)[0]
368
369 duration = float_or_none(data['duration'], 1000)
370
371 video = data['sources']['default']
372 load_balancer_url = video['loadBalancerUrl']
373 abr = int_or_none(video.get('audioBitrate'))
374 vbr = int_or_none(video.get('bitrate'))
375 fps = int_or_none(video.get('videoFps'))
376 width = int_or_none(video.get('videoWidth'))
377 height = int_or_none(video.get('videoHeight'))
378 thumbnail = video.get('preview')
379
380 rendition = self._download_json(
381 load_balancer_url, video_id, transform_source=strip_jsonp)
382
383 f = {
384 'abr': abr,
385 'vbr': vbr,
386 'fps': fps,
387 'width': width,
388 'height': height,
389 }
390
391 formats = []
392 for format_id, format_url in rendition['redirect'].items():
393 if format_id == 'rtmp':
394 ff = f.copy()
395 ff.update({
396 'url': format_url,
397 'format_id': format_id,
398 })
399 formats.append(ff)
400 elif determine_ext(format_url) == 'f4m':
401 formats.extend(self._extract_f4m_formats(
402 format_url, video_id, f4m_id=format_id))
403 elif determine_ext(format_url) == 'm3u8':
404 formats.extend(self._extract_m3u8_formats(
405 format_url, video_id, 'mp4', m3u8_id=format_id))
406 else:
407 continue
408
409 title = remove_end(self._og_search_title(webpage), ' - iptv.ORF.at')
410 description = self._og_search_description(webpage)
411 upload_date = unified_strdate(self._html_search_meta(
412 'dc.date', webpage, 'upload date'))
413
414 return {
415 'id': video_id,
416 'title': title,
417 'description': description,
418 'duration': duration,
419 'thumbnail': thumbnail,
420 'upload_date': upload_date,
421 'formats': formats,
422 }
423
424
425 class ORFFM4StoryIE(InfoExtractor):
426 IE_NAME = 'orf:fm4:story'
427 IE_DESC = 'fm4.orf.at stories'
428 _VALID_URL = r'https?://fm4\.orf\.at/stories/(?P<id>\d+)'
429
430 _TEST = {
431 'url': 'http://fm4.orf.at/stories/2865738/',
432 'playlist': [{
433 'md5': 'e1c2c706c45c7b34cf478bbf409907ca',
434 'info_dict': {
435 'id': '547792',
436 'ext': 'flv',
437 'title': 'Manu Delago und Inner Tongue live',
438 'description': 'Manu Delago und Inner Tongue haben bei der FM4 Soundpark Session live alles gegeben. Hier gibt es Fotos und die gesamte Session als Video.',
439 'duration': 1748.52,
440 'thumbnail': r're:^https?://.*\.jpg$',
441 'upload_date': '20170913',
442 },
443 }, {
444 'md5': 'c6dd2179731f86f4f55a7b49899d515f',
445 'info_dict': {
446 'id': '547798',
447 'ext': 'flv',
448 'title': 'Manu Delago und Inner Tongue live (2)',
449 'duration': 1504.08,
450 'thumbnail': r're:^https?://.*\.jpg$',
451 'upload_date': '20170913',
452 'description': 'Manu Delago und Inner Tongue haben bei der FM4 Soundpark Session live alles gegeben. Hier gibt es Fotos und die gesamte Session als Video.',
453 },
454 }],
455 }
456
457 def _real_extract(self, url):
458 story_id = self._match_id(url)
459 webpage = self._download_webpage(url, story_id)
460
461 entries = []
462 all_ids = orderedSet(re.findall(r'data-video(?:id)?="(\d+)"', webpage))
463 for idx, video_id in enumerate(all_ids):
464 data = self._download_json(
465 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
466 video_id)[0]
467
468 duration = float_or_none(data['duration'], 1000)
469
470 video = data['sources']['q8c']
471 load_balancer_url = video['loadBalancerUrl']
472 abr = int_or_none(video.get('audioBitrate'))
473 vbr = int_or_none(video.get('bitrate'))
474 fps = int_or_none(video.get('videoFps'))
475 width = int_or_none(video.get('videoWidth'))
476 height = int_or_none(video.get('videoHeight'))
477 thumbnail = video.get('preview')
478
479 rendition = self._download_json(
480 load_balancer_url, video_id, transform_source=strip_jsonp)
481
482 f = {
483 'abr': abr,
484 'vbr': vbr,
485 'fps': fps,
486 'width': width,
487 'height': height,
488 }
489
490 formats = []
491 for format_id, format_url in rendition['redirect'].items():
492 if format_id == 'rtmp':
493 ff = f.copy()
494 ff.update({
495 'url': format_url,
496 'format_id': format_id,
497 })
498 formats.append(ff)
499 elif determine_ext(format_url) == 'f4m':
500 formats.extend(self._extract_f4m_formats(
501 format_url, video_id, f4m_id=format_id))
502 elif determine_ext(format_url) == 'm3u8':
503 formats.extend(self._extract_m3u8_formats(
504 format_url, video_id, 'mp4', m3u8_id=format_id))
505 else:
506 continue
507
508 title = remove_end(self._og_search_title(webpage), ' - fm4.ORF.at')
509 if idx >= 1:
510 # Titles are duplicates, make them unique
511 title += ' (' + str(idx + 1) + ')'
512 description = self._og_search_description(webpage)
513 upload_date = unified_strdate(self._html_search_meta(
514 'dc.date', webpage, 'upload date'))
515
516 entries.append({
517 'id': video_id,
518 'title': title,
519 'description': description,
520 'duration': duration,
521 'thumbnail': thumbnail,
522 'upload_date': upload_date,
523 'formats': formats,
524 })
525
526 return self.playlist_result(entries)