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