]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/wdr.py
[wrzuta] Remove extractor (closes #20684) (#20801)
[yt-dlp.git] / youtube_dl / extractor / wdr.py
CommitLineData
dcdb292f 1# coding: utf-8
b461641f
S
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
54e8f62e
S
7from ..compat import (
8 compat_str,
9 compat_urlparse,
10)
1cc79574 11from ..utils import (
bec2c14f 12 determine_ext,
1594a493 13 ExtractorError,
33a1ff71 14 js_to_json,
37f97295 15 strip_jsonp,
54e8f62e 16 try_get,
cd7481a3 17 unified_strdate,
6869d634 18 update_url_query,
50918c4e 19 urlhandle_detect_ext,
b461641f
S
20)
21
22
54e8f62e
S
23class WDRIE(InfoExtractor):
24 _VALID_URL = r'https?://deviceids-medp\.wdr\.de/ondemand/\d+/(?P<id>\d+)\.js'
1915662d 25 _GEO_COUNTRIES = ['DE']
54e8f62e
S
26 _TEST = {
27 'url': 'http://deviceids-medp.wdr.de/ondemand/155/1557833.js',
28 'info_dict': {
0ce39bc5 29 'id': 'mdb-1557833',
54e8f62e 30 'ext': 'mp4',
0ce39bc5
S
31 'title': 'Biathlon-Staffel verpasst Podest bei Olympia-Generalprobe',
32 'upload_date': '20180112',
54e8f62e 33 },
54e8f62e 34 }
6d0d4fc2 35
54e8f62e
S
36 def _real_extract(self, url):
37 video_id = self._match_id(url)
6d0d4fc2
YCH
38
39 metadata = self._download_json(
54e8f62e 40 url, video_id, transform_source=strip_jsonp)
6d0d4fc2 41
54e8f62e
S
42 is_live = metadata.get('mediaType') == 'live'
43
44 tracker_data = metadata['trackerData']
45 media_resource = metadata['mediaResource']
6d0d4fc2
YCH
46
47 formats = []
48
49 # check if the metadata contains a direct URL to a file
54e8f62e 50 for kind, media_resource in media_resource.items():
6d0d4fc2
YCH
51 if kind not in ('dflt', 'alt'):
52 continue
53
54 for tag_name, medium_url in media_resource.items():
55 if tag_name not in ('videoURL', 'audioURL'):
56 continue
57
58 ext = determine_ext(medium_url)
59 if ext == 'm3u8':
60 formats.extend(self._extract_m3u8_formats(
54e8f62e 61 medium_url, video_id, 'mp4', 'm3u8_native',
6d0d4fc2
YCH
62 m3u8_id='hls'))
63 elif ext == 'f4m':
64 manifest_url = update_url_query(
65 medium_url, {'hdcore': '3.2.0', 'plugin': 'aasp-3.2.0.77.18'})
66 formats.extend(self._extract_f4m_formats(
54e8f62e 67 manifest_url, video_id, f4m_id='hds', fatal=False))
6d0d4fc2
YCH
68 elif ext == 'smil':
69 formats.extend(self._extract_smil_formats(
70 medium_url, 'stream', fatal=False))
71 else:
72 a_format = {
73 'url': medium_url
74 }
75 if ext == 'unknown_video':
76 urlh = self._request_webpage(
54e8f62e 77 medium_url, video_id, note='Determining extension')
6d0d4fc2
YCH
78 ext = urlhandle_detect_ext(urlh)
79 a_format['ext'] = ext
80 formats.append(a_format)
81
82 self._sort_formats(formats)
83
84 subtitles = {}
54e8f62e 85 caption_url = media_resource.get('captionURL')
6d0d4fc2
YCH
86 if caption_url:
87 subtitles['de'] = [{
88 'url': caption_url,
89 'ext': 'ttml',
90 }]
91
54e8f62e 92 title = tracker_data['trackerClipTitle']
6d0d4fc2
YCH
93
94 return {
54e8f62e
S
95 'id': tracker_data.get('trackerClipId', video_id),
96 'title': self._live_title(title) if is_live else title,
97 'alt_title': tracker_data.get('trackerClipSubcategory'),
6d0d4fc2
YCH
98 'formats': formats,
99 'subtitles': subtitles,
54e8f62e
S
100 'upload_date': unified_strdate(tracker_data.get('trackerClipAirTime')),
101 'is_live': is_live,
6d0d4fc2
YCH
102 }
103
104
54e8f62e 105class WDRPageIE(InfoExtractor):
949fc42e 106 _CURRENT_MAUS_URL = r'https?://(?:www\.)wdrmaus.de/(?:[^/]+/){1,2}[^/?#]+\.php5'
54e8f62e
S
107 _PAGE_REGEX = r'/(?:mediathek/)?(?:[^/]+/)*(?P<display_id>[^/]+)\.html'
108 _VALID_URL = r'https?://(?:www\d?\.)?(?:wdr\d?|sportschau)\.de' + _PAGE_REGEX + '|' + _CURRENT_MAUS_URL
c0837a12 109
b461641f
S
110 _TESTS = [
111 {
c0837a12 112 'url': 'http://www1.wdr.de/mediathek/video/sendungen/doku-am-freitag/video-geheimnis-aachener-dom-100.html',
a4a8201c 113 # HDS download, MD5 is unstable
b461641f 114 'info_dict': {
c0837a12 115 'id': 'mdb-1058683',
b461641f 116 'ext': 'flv',
c0837a12
BW
117 'display_id': 'doku-am-freitag/video-geheimnis-aachener-dom-100',
118 'title': 'Geheimnis Aachener Dom',
119 'alt_title': 'Doku am Freitag',
120 'upload_date': '20160304',
121 'description': 'md5:87be8ff14d8dfd7a7ee46f0299b52318',
122 'is_live': False,
123 'subtitles': {'de': [{
bc7e7adf
YCH
124 'url': 'http://ondemand-ww.wdr.de/medp/fsk0/105/1058683/1058683_12220974.xml',
125 'ext': 'ttml',
c0837a12 126 }]},
b461641f 127 },
54e8f62e 128 'skip': 'HTTP Error 404: Not Found',
b461641f
S
129 },
130 {
c0837a12
BW
131 'url': 'http://www1.wdr.de/mediathek/audio/wdr3/wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100.html',
132 'md5': 'f4c1f96d01cf285240f53ea4309663d8',
b461641f 133 'info_dict': {
c0837a12 134 'id': 'mdb-1072000',
b461641f 135 'ext': 'mp3',
c0837a12
BW
136 'display_id': 'wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100',
137 'title': 'Schriftstellerin Juli Zeh',
138 'alt_title': 'WDR 3 Gespräch am Samstag',
139 'upload_date': '20160312',
140 'description': 'md5:e127d320bc2b1f149be697ce044a3dd7',
141 'is_live': False,
142 'subtitles': {}
b461641f 143 },
54e8f62e 144 'skip': 'HTTP Error 404: Not Found',
b461641f 145 },
176cf9e0 146 {
c0837a12 147 'url': 'http://www1.wdr.de/mediathek/video/live/index.html',
dd8982f1 148 'info_dict': {
54e8f62e 149 'id': 'mdb-1406149',
bec2c14f 150 'ext': 'mp4',
54e8f62e 151 'title': r're:^WDR Fernsehen im Livestream \(nur in Deutschland erreichbar\) [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
c0837a12 152 'alt_title': 'WDR Fernsehen Live',
54e8f62e 153 'upload_date': '20150101',
c0837a12 154 'is_live': True,
bec2c14f
BW
155 },
156 'params': {
157 'skip_download': True, # m3u8 download
158 },
b8988b63
AA
159 },
160 {
c0837a12 161 'url': 'http://www1.wdr.de/mediathek/video/sendungen/aktuelle-stunde/aktuelle-stunde-120.html',
54e8f62e 162 'playlist_mincount': 7,
b8988b63 163 'info_dict': {
54e8f62e 164 'id': 'aktuelle-stunde-120',
b8988b63 165 },
14f7a2b8
BW
166 },
167 {
168 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
169 'info_dict': {
54e8f62e 170 'id': 'mdb-1552552',
f802c486 171 'ext': 'mp4',
14f7a2b8
BW
172 'upload_date': 're:^[0-9]{8}$',
173 'title': 're:^Die Sendung mit der Maus vom [0-9.]{10}$',
14f7a2b8
BW
174 },
175 'skip': 'The id changes from week to week because of the new episode'
176 },
949fc42e 177 {
f802c486 178 'url': 'http://www.wdrmaus.de/filme/sachgeschichten/achterbahn.php5',
6d0d4fc2 179 'md5': '803138901f6368ee497b4d195bb164f2',
949fc42e
BW
180 'info_dict': {
181 'id': 'mdb-186083',
6d0d4fc2 182 'ext': 'mp4',
949fc42e
BW
183 'upload_date': '20130919',
184 'title': 'Sachgeschichte - Achterbahn ',
949fc42e 185 },
949fc42e 186 },
50918c4e
YCH
187 {
188 'url': 'http://www1.wdr.de/radio/player/radioplayer116~_layout-popupVersion.html',
6869d634 189 # Live stream, MD5 unstable
50918c4e
YCH
190 'info_dict': {
191 'id': 'mdb-869971',
54e8f62e
S
192 'ext': 'mp4',
193 'title': r're:^COSMO Livestream [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
50918c4e
YCH
194 'upload_date': '20160101',
195 },
54e8f62e
S
196 'params': {
197 'skip_download': True, # m3u8 download
198 }
199 },
200 {
201 'url': 'http://www.sportschau.de/handballem2018/handball-nationalmannschaft-em-stolperstein-vorrunde-100.html',
202 'info_dict': {
203 'id': 'mdb-1556012',
204 'ext': 'mp4',
205 'title': 'DHB-Vizepräsident Bob Hanning - "Die Weltspitze ist extrem breit"',
206 'upload_date': '20180111',
207 },
208 'params': {
209 'skip_download': True,
210 },
211 },
212 {
213 'url': 'http://www.sportschau.de/handballem2018/audio-vorschau---die-handball-em-startet-mit-grossem-favoritenfeld-100.html',
214 'only_matching': True,
50918c4e 215 }
b461641f
S
216 ]
217
218 def _real_extract(self, url):
219 mobj = re.match(self._VALID_URL, url)
c0837a12
BW
220 display_id = mobj.group('display_id')
221 webpage = self._download_webpage(url, display_id)
b461641f 222
54e8f62e 223 entries = []
b8988b63 224
54e8f62e 225 # Article with several videos
b461641f 226
54e8f62e
S
227 # for wdr.de the data-extension is in a tag with the class "mediaLink"
228 # for wdr.de radio players, in a tag with the class "wdrrPlayerPlayBtn"
229 # for wdrmaus, in a tag with the class "videoButton" (previously a link
230 # to the page in a multiline "videoLink"-tag)
231 for mobj in re.finditer(
232 r'''(?sx)class=
233 (?:
234 (["\'])(?:mediaLink|wdrrPlayerPlayBtn|videoButton)\b.*?\1[^>]+|
235 (["\'])videoLink\b.*?\2[\s]*>\n[^\n]*
236 )data-extension=(["\'])(?P<data>(?:(?!\3).)+)\3
237 ''', webpage):
238 media_link_obj = self._parse_json(
239 mobj.group('data'), display_id, transform_source=js_to_json,
240 fatal=False)
241 if not media_link_obj:
242 continue
243 jsonp_url = try_get(
244 media_link_obj, lambda x: x['mediaObj']['url'], compat_str)
245 if jsonp_url:
246 entries.append(self.url_result(jsonp_url, ie=WDRIE.ie_key()))
6d0d4fc2 247
54e8f62e
S
248 # Playlist (e.g. https://www1.wdr.de/mediathek/video/sendungen/aktuelle-stunde/aktuelle-stunde-120.html)
249 if not entries:
250 entries = [
251 self.url_result(
252 compat_urlparse.urljoin(url, mobj.group('href')),
253 ie=WDRPageIE.ie_key())
254 for mobj in re.finditer(
255 r'<a[^>]+\bhref=(["\'])(?P<href>(?:(?!\1).)+)\1[^>]+\bdata-extension=',
256 webpage) if re.match(self._PAGE_REGEX, mobj.group('href'))
257 ]
cd7481a3 258
54e8f62e 259 return self.playlist_result(entries, playlist_id=display_id)
cd7481a3 260
2d8bb80c 261
54e8f62e
S
262class WDRElefantIE(InfoExtractor):
263 _VALID_URL = r'https?://(?:www\.)wdrmaus\.de/elefantenseite/#(?P<id>.+)'
264 _TEST = {
265 'url': 'http://www.wdrmaus.de/elefantenseite/#folge_ostern_2015',
266 'info_dict': {
267 'title': 'Folge Oster-Spezial 2015',
268 'id': 'mdb-1088195',
269 'ext': 'mp4',
270 'age_limit': None,
271 'upload_date': '20150406'
2d8bb80c 272 },
54e8f62e
S
273 'params': {
274 'skip_download': True,
275 },
276 }
2d8bb80c
SL
277
278 def _real_extract(self, url):
54e8f62e 279 display_id = self._match_id(url)
2d8bb80c
SL
280
281 # Table of Contents seems to always be at this address, so fetch it directly.
282 # The website fetches configurationJS.php5, which links to tableOfContentsJS.php5.
283 table_of_contents = self._download_json(
54e8f62e
S
284 'https://www.wdrmaus.de/elefantenseite/data/tableOfContentsJS.php5',
285 display_id)
2d8bb80c
SL
286 if display_id not in table_of_contents:
287 raise ExtractorError(
288 'No entry in site\'s table of contents for this URL. '
289 'Is the fragment part of the URL (after the #) correct?',
290 expected=True)
291 xml_metadata_path = table_of_contents[display_id]['xmlPath']
292 xml_metadata = self._download_xml(
54e8f62e
S
293 'https://www.wdrmaus.de/elefantenseite/' + xml_metadata_path,
294 display_id)
2d8bb80c
SL
295 zmdb_url_element = xml_metadata.find('./movie/zmdb_url')
296 if zmdb_url_element is None:
297 raise ExtractorError(
54e8f62e
S
298 '%s is not a video' % display_id, expected=True)
299 return self.url_result(zmdb_url_element.text, ie=WDRIE.ie_key())
2d8bb80c
SL
300
301
e4cbb5f3
PH
302class WDRMobileIE(InfoExtractor):
303 _VALID_URL = r'''(?x)
304 https?://mobile-ondemand\.wdr\.de/
305 .*?/fsk(?P<age_limit>[0-9]+)
306 /[0-9]+/[0-9]+/
307 (?P<id>[0-9]+)_(?P<title>[0-9]+)'''
308 IE_NAME = 'wdr:mobile'
309 _TEST = {
310 'url': 'http://mobile-ondemand.wdr.de/CMS2010/mdb/ondemand/weltweit/fsk0/42/421735/421735_4283021.mp4',
311 'info_dict': {
312 'title': '4283021',
313 'id': '421735',
7807ee66 314 'ext': 'mp4',
e4cbb5f3
PH
315 'age_limit': 0,
316 },
7807ee66 317 'skip': 'Problems with loading data.'
e4cbb5f3
PH
318 }
319
320 def _real_extract(self, url):
321 mobj = re.match(self._VALID_URL, url)
322 return {
323 'id': mobj.group('id'),
324 'title': mobj.group('title'),
325 'age_limit': int(mobj.group('age_limit')),
326 'url': url,
e1554a40
JMF
327 'http_headers': {
328 'User-Agent': 'mobile',
329 },
e4cbb5f3 330 }