1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
6 from .common import InfoExtractor
18 class WDRIE(InfoExtractor):
19 _CURRENT_MAUS_URL = r'https?://(?:www\.)wdrmaus.de/(?:[^/]+/){1,2}[^/?#]+\.php5'
20 _PAGE_REGEX = r'/(?:mediathek/)?[^/]+/(?P<type>[^/]+)/(?P<display_id>.+)\.html'
21 _VALID_URL = r'(?P<page_url>https?://(?:www\d\.)?wdr\d?\.de)' + _PAGE_REGEX + '|' + _CURRENT_MAUS_URL
25 'url': 'http://www1.wdr.de/mediathek/video/sendungen/doku-am-freitag/video-geheimnis-aachener-dom-100.html',
26 # HDS download, MD5 is unstable
30 'display_id': 'doku-am-freitag/video-geheimnis-aachener-dom-100',
31 'title': 'Geheimnis Aachener Dom',
32 'alt_title': 'Doku am Freitag',
33 'upload_date': '20160304',
34 'description': 'md5:87be8ff14d8dfd7a7ee46f0299b52318',
36 'subtitles': {'de': [{
37 'url': 'http://ondemand-ww.wdr.de/medp/fsk0/105/1058683/1058683_12220974.xml',
43 'url': 'http://www1.wdr.de/mediathek/audio/wdr3/wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100.html',
44 'md5': 'f4c1f96d01cf285240f53ea4309663d8',
48 'display_id': 'wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100',
49 'title': 'Schriftstellerin Juli Zeh',
50 'alt_title': 'WDR 3 Gespräch am Samstag',
51 'upload_date': '20160312',
52 'description': 'md5:e127d320bc2b1f149be697ce044a3dd7',
58 'url': 'http://www1.wdr.de/mediathek/video/live/index.html',
62 'display_id': 'index',
63 'title': r're:^WDR Fernsehen im Livestream [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
64 'alt_title': 'WDR Fernsehen Live',
66 'description': 'md5:ae2ff888510623bf8d4b115f95a9b7c9',
71 'skip_download': True, # m3u8 download
75 'url': 'http://www1.wdr.de/mediathek/video/sendungen/aktuelle-stunde/aktuelle-stunde-120.html',
76 'playlist_mincount': 8,
78 'id': 'aktuelle-stunde/aktuelle-stunde-120',
82 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
86 'upload_date': 're:^[0-9]{8}$',
87 'title': 're:^Die Sendung mit der Maus vom [0-9.]{10}$',
88 'description': '- Die Sendung mit der Maus -',
90 'skip': 'The id changes from week to week because of the new episode'
93 'url': 'http://www.wdrmaus.de/sachgeschichten/sachgeschichten/achterbahn.php5',
94 # HDS download, MD5 is unstable
98 'upload_date': '20130919',
99 'title': 'Sachgeschichte - Achterbahn ',
100 'description': '- Die Sendung mit der Maus -',
104 'url': 'http://www1.wdr.de/radio/player/radioplayer116~_layout-popupVersion.html',
105 # Live stream, MD5 unstable
109 'title': 'Funkhaus Europa Livestream',
110 'description': 'md5:2309992a6716c347891c045be50992e4',
111 'upload_date': '20160101',
116 def _real_extract(self, url):
117 mobj = re.match(self._VALID_URL, url)
118 url_type = mobj.group('type')
119 page_url = mobj.group('page_url')
120 display_id = mobj.group('display_id')
121 webpage = self._download_webpage(url, display_id)
123 # for wdr.de the data-extension is in a tag with the class "mediaLink"
124 # for wdr.de radio players, in a tag with the class "wdrrPlayerPlayBtn"
125 # for wdrmaus its in a link to the page in a multiline "videoLink"-tag
126 json_metadata = self._html_search_regex(
127 r'class=(?:"(?:mediaLink|wdrrPlayerPlayBtn)\b[^"]*"[^>]+|"videoLink\b[^"]*"[\s]*>\n[^\n]*)data-extension="([^"]+)"',
128 webpage, 'media link', default=None, flags=re.MULTILINE)
130 if not json_metadata:
132 self.url_result(page_url + href[0], 'WDR')
133 for href in re.findall(
134 r'<a href="(%s)"[^>]+data-extension=' % self._PAGE_REGEX,
138 if entries: # Playlist page
139 return self.playlist_result(entries, playlist_id=display_id)
141 raise ExtractorError('No downloadable streams found', expected=True)
143 media_link_obj = self._parse_json(json_metadata, display_id,
144 transform_source=js_to_json)
145 jsonp_url = media_link_obj['mediaObj']['url']
147 metadata = self._download_json(
148 jsonp_url, 'metadata', transform_source=strip_jsonp)
150 metadata_tracker_data = metadata['trackerData']
151 metadata_media_resource = metadata['mediaResource']
155 # check if the metadata contains a direct URL to a file
156 for kind, media_resource in metadata_media_resource.items():
157 if kind not in ('dflt', 'alt'):
160 for tag_name, medium_url in media_resource.items():
161 if tag_name not in ('videoURL', 'audioURL'):
164 ext = determine_ext(medium_url)
166 formats.extend(self._extract_m3u8_formats(
167 medium_url, display_id, 'mp4', 'm3u8_native',
170 manifest_url = update_url_query(
171 medium_url, {'hdcore': '3.2.0', 'plugin': 'aasp-3.2.0.77.18'})
172 formats.extend(self._extract_f4m_formats(
173 manifest_url, display_id, f4m_id='hds', fatal=False))
175 formats.extend(self._extract_smil_formats(
176 medium_url, 'stream', fatal=False))
181 if ext == 'unknown_video':
182 urlh = self._request_webpage(
183 medium_url, display_id, note='Determining extension')
184 ext = urlhandle_detect_ext(urlh)
185 a_format['ext'] = ext
186 formats.append(a_format)
188 self._sort_formats(formats)
191 caption_url = metadata_media_resource.get('captionURL')
198 title = metadata_tracker_data.get('trackerClipTitle')
199 is_live = url_type == 'live'
202 title = self._live_title(title)
204 elif 'trackerClipAirTime' in metadata_tracker_data:
205 upload_date = metadata_tracker_data['trackerClipAirTime']
207 upload_date = self._html_search_meta('DC.Date', webpage, 'upload date')
210 upload_date = unified_strdate(upload_date)
213 'id': metadata_tracker_data.get('trackerClipId', display_id),
214 'display_id': display_id,
216 'alt_title': metadata_tracker_data.get('trackerClipSubcategory'),
218 'upload_date': upload_date,
219 'description': self._html_search_meta('Description', webpage),
221 'subtitles': subtitles,
225 class WDRMobileIE(InfoExtractor):
226 _VALID_URL = r'''(?x)
227 https?://mobile-ondemand\.wdr\.de/
228 .*?/fsk(?P<age_limit>[0-9]+)
230 (?P<id>[0-9]+)_(?P<title>[0-9]+)'''
231 IE_NAME = 'wdr:mobile'
233 'url': 'http://mobile-ondemand.wdr.de/CMS2010/mdb/ondemand/weltweit/fsk0/42/421735/421735_4283021.mp4',
240 'skip': 'Problems with loading data.'
243 def _real_extract(self, url):
244 mobj = re.match(self._VALID_URL, url)
246 'id': mobj.group('id'),
247 'title': mobj.group('title'),
248 'age_limit': int(mobj.group('age_limit')),
251 'User-Agent': 'mobile',