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