]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/wdr.py
[wdr] Misc changes
[yt-dlp.git] / youtube_dl / extractor / wdr.py
CommitLineData
7807ee66 1# -*- coding: utf-8 -*-
b461641f
S
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
1cc79574 7from ..utils import (
bec2c14f 8 determine_ext,
1594a493 9 ExtractorError,
33a1ff71 10 js_to_json,
37f97295 11 strip_jsonp,
cd7481a3 12 unified_strdate,
6869d634 13 update_url_query,
50918c4e 14 urlhandle_detect_ext,
b461641f
S
15)
16
17
18class WDRIE(InfoExtractor):
949fc42e 19 _CURRENT_MAUS_URL = r'https?://(?:www\.)wdrmaus.de/(?:[^/]+/){1,2}[^/?#]+\.php5'
1594a493 20 _PAGE_REGEX = r'/(?:mediathek/)?[^/]+/(?P<type>[^/]+)/(?P<display_id>.+)\.html'
3874e6ea 21 _VALID_URL = r'(?P<page_url>https?://(?:www\d\.)?wdr\d?\.de)' + _PAGE_REGEX + '|' + _CURRENT_MAUS_URL
c0837a12 22
b461641f
S
23 _TESTS = [
24 {
c0837a12 25 'url': 'http://www1.wdr.de/mediathek/video/sendungen/doku-am-freitag/video-geheimnis-aachener-dom-100.html',
a4a8201c 26 # HDS download, MD5 is unstable
b461641f 27 'info_dict': {
c0837a12 28 'id': 'mdb-1058683',
b461641f 29 'ext': 'flv',
c0837a12
BW
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',
35 'is_live': False,
36 'subtitles': {'de': [{
37 'url': 'http://ondemand-ww.wdr.de/medp/fsk0/105/1058683/1058683_12220974.xml'
38 }]},
b461641f
S
39 },
40 },
41 {
c0837a12
BW
42 'url': 'http://www1.wdr.de/mediathek/audio/wdr3/wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100.html',
43 'md5': 'f4c1f96d01cf285240f53ea4309663d8',
b461641f 44 'info_dict': {
c0837a12 45 'id': 'mdb-1072000',
b461641f 46 'ext': 'mp3',
c0837a12
BW
47 'display_id': 'wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100',
48 'title': 'Schriftstellerin Juli Zeh',
49 'alt_title': 'WDR 3 Gespräch am Samstag',
50 'upload_date': '20160312',
51 'description': 'md5:e127d320bc2b1f149be697ce044a3dd7',
52 'is_live': False,
53 'subtitles': {}
b461641f
S
54 },
55 },
176cf9e0 56 {
c0837a12 57 'url': 'http://www1.wdr.de/mediathek/video/live/index.html',
dd8982f1 58 'info_dict': {
c0837a12 59 'id': 'mdb-103364',
bec2c14f 60 'ext': 'mp4',
c0837a12
BW
61 'display_id': 'index',
62 'title': r're:^WDR Fernsehen im Livestream [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
63 'alt_title': 'WDR Fernsehen Live',
64 'upload_date': None,
65 'description': 'md5:ae2ff888510623bf8d4b115f95a9b7c9',
66 'is_live': True,
67 'subtitles': {}
bec2c14f
BW
68 },
69 'params': {
70 'skip_download': True, # m3u8 download
71 },
b8988b63
AA
72 },
73 {
c0837a12 74 'url': 'http://www1.wdr.de/mediathek/video/sendungen/aktuelle-stunde/aktuelle-stunde-120.html',
3a686853 75 'playlist_mincount': 8,
b8988b63 76 'info_dict': {
c0837a12 77 'id': 'aktuelle-stunde/aktuelle-stunde-120',
b8988b63 78 },
14f7a2b8
BW
79 },
80 {
81 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
82 'info_dict': {
83 'id': 'mdb-1096487',
84 'ext': 'flv',
85 'upload_date': 're:^[0-9]{8}$',
86 'title': 're:^Die Sendung mit der Maus vom [0-9.]{10}$',
87 'description': '- Die Sendung mit der Maus -',
88 },
89 'skip': 'The id changes from week to week because of the new episode'
90 },
949fc42e
BW
91 {
92 'url': 'http://www.wdrmaus.de/sachgeschichten/sachgeschichten/achterbahn.php5',
a4a8201c 93 # HDS download, MD5 is unstable
949fc42e
BW
94 'info_dict': {
95 'id': 'mdb-186083',
96 'ext': 'flv',
97 'upload_date': '20130919',
98 'title': 'Sachgeschichte - Achterbahn ',
99 'description': '- Die Sendung mit der Maus -',
100 },
949fc42e 101 },
50918c4e
YCH
102 {
103 'url': 'http://www1.wdr.de/radio/player/radioplayer116~_layout-popupVersion.html',
6869d634 104 # Live stream, MD5 unstable
50918c4e
YCH
105 'info_dict': {
106 'id': 'mdb-869971',
6869d634 107 'ext': 'flv',
50918c4e
YCH
108 'title': 'Funkhaus Europa Livestream',
109 'description': 'md5:2309992a6716c347891c045be50992e4',
110 'upload_date': '20160101',
111 },
112 }
b461641f
S
113 ]
114
115 def _real_extract(self, url):
116 mobj = re.match(self._VALID_URL, url)
c0837a12
BW
117 url_type = mobj.group('type')
118 page_url = mobj.group('page_url')
119 display_id = mobj.group('display_id')
120 webpage = self._download_webpage(url, display_id)
b461641f 121
33a1ff71 122 # for wdr.de the data-extension is in a tag with the class "mediaLink"
50918c4e 123 # for wdr.de radio players, in a tag with the class "wdrrPlayerPlayBtn"
33a1ff71
BW
124 # for wdrmaus its in a link to the page in a multiline "videoLink"-tag
125 json_metadata = self._html_search_regex(
50918c4e 126 r'class=(?:"(?:mediaLink|wdrrPlayerPlayBtn)\b[^"]*"[^>]+|"videoLink\b[^"]*"[\s]*>\n[^\n]*)data-extension="([^"]+)"',
33a1ff71 127 webpage, 'media link', default=None, flags=re.MULTILINE)
b461641f 128
33a1ff71 129 if not json_metadata:
b461641f 130 entries = [
c0837a12 131 self.url_result(page_url + href[0], 'WDR')
03681819 132 for href in re.findall(
3a686853 133 r'<a href="(%s)"[^>]+data-extension=' % self._PAGE_REGEX,
03681819 134 webpage)
b461641f 135 ]
176cf9e0
PH
136
137 if entries: # Playlist page
c0837a12 138 return self.playlist_result(entries, playlist_id=display_id)
176cf9e0 139
c0837a12
BW
140 raise ExtractorError('No downloadable streams found', expected=True)
141
33a1ff71
BW
142 media_link_obj = self._parse_json(json_metadata, display_id,
143 transform_source=js_to_json)
144 jsonp_url = media_link_obj['mediaObj']['url']
145
37f97295 146 metadata = self._download_json(
33a1ff71 147 jsonp_url, 'metadata', transform_source=strip_jsonp)
c0837a12 148
3874e6ea
BW
149 metadata_tracker_data = metadata['trackerData']
150 metadata_media_resource = metadata['mediaResource']
c0837a12
BW
151
152 formats = []
153
154 # check if the metadata contains a direct URL to a file
6869d634
YCH
155 for kind, media_resource in metadata_media_resource.items():
156 if kind not in ('dflt', 'alt'):
157 continue
158
159 for tag_name, medium_url in media_resource.items():
160 if tag_name not in ('videoURL', 'audioURL'):
161 continue
162
163 ext = determine_ext(medium_url)
164 if ext == 'm3u8':
1594a493 165 formats.extend(self._extract_m3u8_formats(
6869d634 166 medium_url, display_id, 'mp4', 'm3u8_native',
1594a493 167 m3u8_id='hls'))
6869d634
YCH
168 elif ext == 'f4m':
169 manifest_url = update_url_query(
170 medium_url, {'hdcore': '3.2.0', 'plugin': 'aasp-3.2.0.77.18'})
171 formats.extend(self._extract_f4m_formats(
172 manifest_url, display_id, f4m_id='hds', fatal=False))
173 elif ext == 'smil':
174 formats.extend(self._extract_smil_formats(
175 medium_url, 'stream', fatal=False))
176 else:
177 a_format = {
178 'url': medium_url
179 }
180 if ext == 'unknown_video':
181 urlh = self._request_webpage(
182 medium_url, display_id, note='Determining extension')
183 ext = urlhandle_detect_ext(urlh)
184 a_format['ext'] = ext
185 formats.append(a_format)
c0837a12 186
1594a493
YCH
187 self._sort_formats(formats)
188
c0837a12 189 subtitles = {}
3874e6ea 190 caption_url = metadata_media_resource.get('captionURL')
c0837a12
BW
191 if caption_url:
192 subtitles['de'] = [{
193 'url': caption_url
194 }]
195
3874e6ea 196 title = metadata_tracker_data.get('trackerClipTitle')
c0837a12 197 is_live = url_type == 'live'
b8988b63
AA
198
199 if is_live:
200 title = self._live_title(title)
c0837a12
BW
201 upload_date = None
202 elif 'trackerClipAirTime' in metadata_tracker_data:
203 upload_date = metadata_tracker_data['trackerClipAirTime']
b461641f 204 else:
c0837a12 205 upload_date = self._html_search_meta('DC.Date', webpage, 'upload date')
b461641f
S
206
207 if upload_date:
208 upload_date = unified_strdate(upload_date)
209
b461641f 210 return {
3874e6ea 211 'id': metadata_tracker_data.get('trackerClipId', display_id),
c0837a12 212 'display_id': display_id,
b461641f 213 'title': title,
3874e6ea 214 'alt_title': metadata_tracker_data.get('trackerClipSubcategory'),
c0837a12 215 'formats': formats,
b461641f 216 'upload_date': upload_date,
3874e6ea 217 'description': self._html_search_meta('Description', webpage),
c0837a12
BW
218 'is_live': is_live,
219 'subtitles': subtitles,
cd7481a3
PH
220 }
221
222
e4cbb5f3
PH
223class WDRMobileIE(InfoExtractor):
224 _VALID_URL = r'''(?x)
225 https?://mobile-ondemand\.wdr\.de/
226 .*?/fsk(?P<age_limit>[0-9]+)
227 /[0-9]+/[0-9]+/
228 (?P<id>[0-9]+)_(?P<title>[0-9]+)'''
229 IE_NAME = 'wdr:mobile'
230 _TEST = {
231 'url': 'http://mobile-ondemand.wdr.de/CMS2010/mdb/ondemand/weltweit/fsk0/42/421735/421735_4283021.mp4',
232 'info_dict': {
233 'title': '4283021',
234 'id': '421735',
7807ee66 235 'ext': 'mp4',
e4cbb5f3
PH
236 'age_limit': 0,
237 },
7807ee66 238 'skip': 'Problems with loading data.'
e4cbb5f3
PH
239 }
240
241 def _real_extract(self, url):
242 mobj = re.match(self._VALID_URL, url)
243 return {
244 'id': mobj.group('id'),
245 'title': mobj.group('title'),
246 'age_limit': int(mobj.group('age_limit')),
247 'url': url,
e1554a40
JMF
248 'http_headers': {
249 'User-Agent': 'mobile',
250 },
e4cbb5f3 251 }