2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from .generic import GenericIE
19 from ..compat import compat_etree_fromstring
22 class ARDMediathekIE(InfoExtractor):
23 IE_NAME = 'ARD:mediathek'
24 _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.(?:daserste|rbb-online)\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?'
27 # available till 26.07.2022
28 'url': 'http://www.ardmediathek.de/tv/S%C3%9CDLICHT/Was-ist-die-Kunst-der-Zukunft-liebe-Ann/BR-Fernsehen/Video?bcastId=34633636&documentId=44726822',
32 'title': 'Was ist die Kunst der Zukunft, liebe Anna McCarthy?',
33 'description': 'md5:4ada28b3e3b5df01647310e41f3a62f5',
38 'skip_download': True,
42 'url': 'http://www.ardmediathek.de/tv/WDR-H%C3%B6rspiel-Speicher/Tod-eines-Fu%C3%9Fballers/WDR-3/Audio-Podcast?documentId=28488308&bcastId=23074086',
43 'only_matching': True,
45 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
46 'only_matching': True,
49 'url': 'http://mediathek.rbb-online.de/radio/Hörspiel/Vor-dem-Fest/kulturradio/Audio?documentId=30796318&topRessort=radio&bcastId=9839158',
50 'only_matching': True,
53 def _extract_media_info(self, media_info_url, webpage, video_id):
54 media_info = self._download_json(
55 media_info_url, video_id, 'Downloading media JSON')
57 formats = self._extract_formats(media_info, video_id)
60 if '"fsk"' in webpage:
62 'This video is only available after 20:00', expected=True)
63 elif media_info.get('_geoblocked'):
64 raise ExtractorError('This video is not available due to geo restriction', expected=True)
66 self._sort_formats(formats)
68 duration = int_or_none(media_info.get('_duration'))
69 thumbnail = media_info.get('_previewImage')
70 is_live = media_info.get('_isLive') is True
73 subtitle_url = media_info.get('_subtitleUrl')
83 'thumbnail': thumbnail,
86 'subtitles': subtitles,
89 def _extract_formats(self, media_info, video_id):
90 type_ = media_info.get('_type')
91 media_array = media_info.get('_mediaArray', [])
93 for num, media in enumerate(media_array):
94 for stream in media.get('_mediaStreamArray', []):
95 stream_urls = stream.get('_stream')
98 if not isinstance(stream_urls, list):
99 stream_urls = [stream_urls]
100 quality = stream.get('_quality')
101 server = stream.get('_server')
102 for stream_url in stream_urls:
103 if not url_or_none(stream_url):
105 ext = determine_ext(stream_url)
106 if quality != 'auto' and ext in ('f4m', 'm3u8'):
109 formats.extend(self._extract_f4m_formats(
110 update_url_query(stream_url, {
112 'plugin': 'aasp-3.1.1.69.124'
114 video_id, f4m_id='hds', fatal=False))
116 formats.extend(self._extract_m3u8_formats(
117 stream_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
119 if server and server.startswith('rtmp'):
122 'play_path': stream_url,
123 'format_id': 'a%s-rtmp-%s' % (num, quality),
128 'format_id': 'a%s-%s-%s' % (num, ext, quality)
130 m = re.search(r'_(?P<width>\d+)x(?P<height>\d+)\.mp4$', stream_url)
133 'width': int(m.group('width')),
134 'height': int(m.group('height')),
141 def _real_extract(self, url):
142 # determine video id from url
143 m = re.match(self._VALID_URL, url)
147 numid = re.search(r'documentId=([0-9]+)', url)
149 document_id = video_id = numid.group(1)
151 video_id = m.group('video_id')
153 webpage = self._download_webpage(url, video_id)
156 ('>Leider liegt eine Störung vor.', 'Video %s is unavailable'),
157 ('>Der gewünschte Beitrag ist nicht mehr verfügbar.<',
158 'Video %s is no longer available'),
161 for pattern, message in ERRORS:
162 if pattern in webpage:
163 raise ExtractorError(message % video_id, expected=True)
165 if re.search(r'[\?&]rss($|[=&])', url):
166 doc = compat_etree_fromstring(webpage.encode('utf-8'))
168 return GenericIE()._extract_rss(url, video_id, doc)
170 title = self._html_search_regex(
171 [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
172 r'<meta name="dcterms\.title" content="(.*?)"/>',
173 r'<h4 class="headline">(.*?)</h4>'],
175 description = self._html_search_meta(
176 'dcterms.abstract', webpage, 'description', default=None)
177 if description is None:
178 description = self._html_search_meta(
179 'description', webpage, 'meta description')
181 # Thumbnail is sometimes not present.
182 # It is in the mobile version, but that seems to use a different URL
183 # structure altogether.
184 thumbnail = self._og_search_thumbnail(webpage, default=None)
186 media_streams = re.findall(r'''(?x)
187 mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
188 "([^"]+)"''', webpage)
191 QUALITIES = qualities(['lo', 'hi', 'hq'])
193 for furl in set(media_streams):
194 if furl.endswith('.f4m'):
197 fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl)
198 fid = fid_m.group(1) if fid_m else None
200 'quality': QUALITIES(fid),
204 self._sort_formats(formats)
208 else: # request JSON file
210 video_id = self._search_regex(
211 r'/play/(?:config|media)/(\d+)', webpage, 'media id')
212 info = self._extract_media_info(
213 'http://www.ardmediathek.de/play/media/%s' % video_id,
218 'title': self._live_title(title) if info.get('is_live') else title,
219 'description': description,
220 'thumbnail': thumbnail,
226 class ARDIE(InfoExtractor):
227 _VALID_URL = r'(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html'
229 # available till 14.02.2019
230 'url': 'http://www.daserste.de/information/talk/maischberger/videos/das-groko-drama-zerlegen-sich-die-volksparteien-video-102.html',
231 'md5': '8e4ec85f31be7c7fc08a26cdbc5a1f49',
233 'display_id': 'das-groko-drama-zerlegen-sich-die-volksparteien-video',
237 'title': 'Das GroKo-Drama: Zerlegen sich die Volksparteien?',
238 'upload_date': '20180214',
239 'thumbnail': r're:^https?://.*\.jpg$',
242 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
243 'only_matching': True,
246 def _real_extract(self, url):
247 mobj = re.match(self._VALID_URL, url)
248 display_id = mobj.group('display_id')
250 player_url = mobj.group('mainurl') + '~playerXml.xml'
251 doc = self._download_xml(player_url, display_id)
252 video_node = doc.find('./video')
253 upload_date = unified_strdate(xpath_text(
254 video_node, './broadcastDate'))
255 thumbnail = xpath_text(video_node, './/teaserImage//variant/url')
258 for a in video_node.findall('.//asset'):
260 'format_id': a.attrib['type'],
261 'width': int_or_none(a.find('./frameWidth').text),
262 'height': int_or_none(a.find('./frameHeight').text),
263 'vbr': int_or_none(a.find('./bitrateVideo').text),
264 'abr': int_or_none(a.find('./bitrateAudio').text),
265 'vcodec': a.find('./codecVideo').text,
266 'tbr': int_or_none(a.find('./totalBitrate').text),
268 if a.find('./serverPrefix').text:
269 f['url'] = a.find('./serverPrefix').text
270 f['playpath'] = a.find('./fileName').text
272 f['url'] = a.find('./fileName').text
274 self._sort_formats(formats)
277 'id': mobj.group('id'),
279 'display_id': display_id,
280 'title': video_node.find('./title').text,
281 'duration': parse_duration(video_node.find('./duration').text),
282 'upload_date': upload_date,
283 'thumbnail': thumbnail,
287 class ARDBetaMediathekIE(InfoExtractor):
288 _VALID_URL = r'https://beta\.ardmediathek\.de/[a-z]+/player/(?P<video_id>[a-zA-Z0-9]+)/(?P<display_id>[^/?#]+)'
290 'url': 'https://beta.ardmediathek.de/ard/player/Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydC9mYmM4NGM1NC0xNzU4LTRmZGYtYWFhZS0wYzcyZTIxNGEyMDE/die-robuste-roswita',
291 'md5': '2d02d996156ea3c397cfc5036b5d7f8f',
293 'display_id': 'die-robuste-roswita',
294 'id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydC9mYmM4NGM1NC0xNzU4LTRmZGYtYWFhZS0wYzcyZTIxNGEyMDE',
295 'title': 'Tatort: Die robuste Roswita',
296 'description': r're:^Der Mord.*trüber ist als die Ilm.',
298 'thumbnail': 'https://img.ardmediathek.de/standard/00/55/43/59/34/-1774185891/16x9/960?mandant=ard',
299 'upload_date': '20180826',
304 def _real_extract(self, url):
305 mobj = re.match(self._VALID_URL, url)
306 video_id = mobj.group('video_id')
307 display_id = mobj.group('display_id')
309 webpage = self._download_webpage(url, display_id)
310 data_json = self._search_regex(r'window\.__APOLLO_STATE__\s*=\s*(\{.*);\n', webpage, 'json')
311 data = self._parse_json(data_json, display_id)
315 'display_id': display_id,
318 for widget in data.values():
319 if widget.get('_geoblocked'):
320 raise ExtractorError('This video is not available due to geoblocking', expected=True)
322 if '_duration' in widget:
323 res['duration'] = widget['_duration']
324 if 'clipTitle' in widget:
325 res['title'] = widget['clipTitle']
326 if '_previewImage' in widget:
327 res['thumbnail'] = widget['_previewImage']
328 if 'broadcastedOn' in widget:
329 res['upload_date'] = unified_strdate(widget['broadcastedOn'])
330 if 'synopsis' in widget:
331 res['description'] = widget['synopsis']
332 if '_subtitleUrl' in widget:
333 res['subtitles'] = {'de': [{
335 'url': widget['_subtitleUrl'],
337 if '_quality' in widget:
338 format_url = widget['_stream']['json'][0]
340 if format_url.endswith('.f4m'):
341 # Skip f4m - these URLs just return a 403
343 'format_id': 'f4m-' + widget['_quality'],
347 elif format_url.endswith('m3u8'):
348 formats.extend(self._extract_m3u8_formats(
349 format_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
352 'format_id': 'http-' + widget['_quality'],
354 'preference': 10, # Plain HTTP, that's nice
357 self._sort_formats(formats)
358 res['formats'] = formats