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