]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/swrmediathek.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / swrmediathek.py
1 from .common import InfoExtractor
2 from ..utils import (
3 parse_duration,
4 int_or_none,
5 determine_protocol,
6 )
7
8
9 class SWRMediathekIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?swrmediathek\.de/(?:content/)?player\.htm\?show=(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
11
12 _TESTS = [{
13 'url': 'http://swrmediathek.de/player.htm?show=849790d0-dab8-11e3-a953-0026b975f2e6',
14 'md5': '8c5f6f0172753368547ca8413a7768ac',
15 'info_dict': {
16 'id': '849790d0-dab8-11e3-a953-0026b975f2e6',
17 'ext': 'mp4',
18 'title': 'SWR odysso',
19 'description': 'md5:2012e31baad36162e97ce9eb3f157b8a',
20 'thumbnail': r're:^http:.*\.jpg$',
21 'duration': 2602,
22 'upload_date': '20140515',
23 'uploader': 'SWR Fernsehen',
24 'uploader_id': '990030',
25 },
26 }, {
27 'url': 'http://swrmediathek.de/player.htm?show=0e1a8510-ddf2-11e3-9be3-0026b975f2e6',
28 'md5': 'b10ab854f912eecc5a6b55cd6fc1f545',
29 'info_dict': {
30 'id': '0e1a8510-ddf2-11e3-9be3-0026b975f2e6',
31 'ext': 'mp4',
32 'title': 'Nachtcafé - Alltagsdroge Alkohol - zwischen Sektempfang und Komasaufen',
33 'description': 'md5:e0a3adc17e47db2c23aab9ebc36dbee2',
34 'thumbnail': r're:http://.*\.jpg',
35 'duration': 5305,
36 'upload_date': '20140516',
37 'uploader': 'SWR Fernsehen',
38 'uploader_id': '990030',
39 },
40 'skip': 'redirect to http://swrmediathek.de/index.htm?hinweis=swrlink',
41 }, {
42 'url': 'http://swrmediathek.de/player.htm?show=bba23e10-cb93-11e3-bf7f-0026b975f2e6',
43 'md5': '4382e4ef2c9d7ce6852535fa867a0dd3',
44 'info_dict': {
45 'id': 'bba23e10-cb93-11e3-bf7f-0026b975f2e6',
46 'ext': 'mp3',
47 'title': 'Saša Stanišic: Vor dem Fest',
48 'description': 'md5:5b792387dc3fbb171eb709060654e8c9',
49 'thumbnail': r're:http://.*\.jpg',
50 'duration': 3366,
51 'upload_date': '20140520',
52 'uploader': 'SWR 2',
53 'uploader_id': '284670',
54 },
55 'skip': 'redirect to http://swrmediathek.de/index.htm?hinweis=swrlink',
56 }]
57
58 def _real_extract(self, url):
59 video_id = self._match_id(url)
60
61 video = self._download_json(
62 'http://swrmediathek.de/AjaxEntry?ekey=%s' % video_id,
63 video_id, 'Downloading video JSON')
64
65 attr = video['attr']
66 title = attr['entry_title']
67 media_type = attr.get('entry_etype')
68
69 formats = []
70 for entry in video.get('sub', []):
71 if entry.get('name') != 'entry_media':
72 continue
73
74 entry_attr = entry.get('attr', {})
75 f_url = entry_attr.get('val2')
76 if not f_url:
77 continue
78 codec = entry_attr.get('val0')
79 if codec == 'm3u8':
80 formats.extend(self._extract_m3u8_formats(
81 f_url, video_id, 'mp4', 'm3u8_native',
82 m3u8_id='hls', fatal=False))
83 elif codec == 'f4m':
84 formats.extend(self._extract_f4m_formats(
85 f_url + '?hdcore=3.7.0', video_id,
86 f4m_id='hds', fatal=False))
87 else:
88 formats.append({
89 'format_id': determine_protocol({'url': f_url}),
90 'url': f_url,
91 'quality': int_or_none(entry_attr.get('val1')),
92 'vcodec': codec if media_type == 'Video' else 'none',
93 'acodec': codec if media_type == 'Audio' else None,
94 })
95
96 upload_date = None
97 entry_pdatet = attr.get('entry_pdatet')
98 if entry_pdatet:
99 upload_date = entry_pdatet[:-4]
100
101 return {
102 'id': video_id,
103 'title': title,
104 'description': attr.get('entry_descl'),
105 'thumbnail': attr.get('entry_image_16_9'),
106 'duration': parse_duration(attr.get('entry_durat')),
107 'upload_date': upload_date,
108 'uploader': attr.get('channel_title'),
109 'uploader_id': attr.get('channel_idkey'),
110 'formats': formats,
111 }