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|classic)\.)?ardmediathek\.de|mediathek\.(?:daserste|rbb-online)\.de|one\.ard\.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,
41 'url': 'https://one.ard.de/tv/Mord-mit-Aussicht/Mord-mit-Aussicht-6-39-T%C3%B6dliche-Nach/ONE/Video?bcastId=46384294&documentId=55586872',
42 'only_matching': True,
45 'url': 'http://www.ardmediathek.de/tv/WDR-H%C3%B6rspiel-Speicher/Tod-eines-Fu%C3%9Fballers/WDR-3/Audio-Podcast?documentId=28488308&bcastId=23074086',
46 'only_matching': True,
48 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
49 'only_matching': True,
52 'url': 'http://mediathek.rbb-online.de/radio/Hörspiel/Vor-dem-Fest/kulturradio/Audio?documentId=30796318&topRessort=radio&bcastId=9839158',
53 'only_matching': True,
55 'url': 'https://classic.ardmediathek.de/tv/Panda-Gorilla-Co/Panda-Gorilla-Co-Folge-274/Das-Erste/Video?bcastId=16355486&documentId=58234698',
56 'only_matching': True,
59 def _extract_media_info(self, media_info_url, webpage, video_id):
60 media_info = self._download_json(
61 media_info_url, video_id, 'Downloading media JSON')
63 formats = self._extract_formats(media_info, video_id)
66 if '"fsk"' in webpage:
68 'This video is only available after 20:00', expected=True)
69 elif media_info.get('_geoblocked'):
70 raise ExtractorError('This video is not available due to geo restriction', expected=True)
72 self._sort_formats(formats)
74 duration = int_or_none(media_info.get('_duration'))
75 thumbnail = media_info.get('_previewImage')
76 is_live = media_info.get('_isLive') is True
79 subtitle_url = media_info.get('_subtitleUrl')
89 'thumbnail': thumbnail,
92 'subtitles': subtitles,
95 def _extract_formats(self, media_info, video_id):
96 type_ = media_info.get('_type')
97 media_array = media_info.get('_mediaArray', [])
99 for num, media in enumerate(media_array):
100 for stream in media.get('_mediaStreamArray', []):
101 stream_urls = stream.get('_stream')
104 if not isinstance(stream_urls, list):
105 stream_urls = [stream_urls]
106 quality = stream.get('_quality')
107 server = stream.get('_server')
108 for stream_url in stream_urls:
109 if not url_or_none(stream_url):
111 ext = determine_ext(stream_url)
112 if quality != 'auto' and ext in ('f4m', 'm3u8'):
115 formats.extend(self._extract_f4m_formats(
116 update_url_query(stream_url, {
118 'plugin': 'aasp-3.1.1.69.124'
120 video_id, f4m_id='hds', fatal=False))
122 formats.extend(self._extract_m3u8_formats(
123 stream_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
125 if server and server.startswith('rtmp'):
128 'play_path': stream_url,
129 'format_id': 'a%s-rtmp-%s' % (num, quality),
134 'format_id': 'a%s-%s-%s' % (num, ext, quality)
136 m = re.search(r'_(?P<width>\d+)x(?P<height>\d+)\.mp4$', stream_url)
139 'width': int(m.group('width')),
140 'height': int(m.group('height')),
147 def _real_extract(self, url):
148 # determine video id from url
149 m = re.match(self._VALID_URL, url)
153 numid = re.search(r'documentId=([0-9]+)', url)
155 document_id = video_id = numid.group(1)
157 video_id = m.group('video_id')
159 webpage = self._download_webpage(url, video_id)
162 ('>Leider liegt eine Störung vor.', 'Video %s is unavailable'),
163 ('>Der gewünschte Beitrag ist nicht mehr verfügbar.<',
164 'Video %s is no longer available'),
167 for pattern, message in ERRORS:
168 if pattern in webpage:
169 raise ExtractorError(message % video_id, expected=True)
171 if re.search(r'[\?&]rss($|[=&])', url):
172 doc = compat_etree_fromstring(webpage.encode('utf-8'))
174 return GenericIE()._extract_rss(url, video_id, doc)
176 title = self._html_search_regex(
177 [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
178 r'<meta name="dcterms\.title" content="(.*?)"/>',
179 r'<h4 class="headline">(.*?)</h4>',
180 r'<title[^>]*>(.*?)</title>'],
182 description = self._html_search_meta(
183 'dcterms.abstract', webpage, 'description', default=None)
184 if description is None:
185 description = self._html_search_meta(
186 'description', webpage, 'meta description', default=None)
187 if description is None:
188 description = self._html_search_regex(
189 r'<p\s+class="teasertext">(.+?)</p>',
190 webpage, 'teaser text', default=None)
192 # Thumbnail is sometimes not present.
193 # It is in the mobile version, but that seems to use a different URL
194 # structure altogether.
195 thumbnail = self._og_search_thumbnail(webpage, default=None)
197 media_streams = re.findall(r'''(?x)
198 mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
199 "([^"]+)"''', webpage)
202 QUALITIES = qualities(['lo', 'hi', 'hq'])
204 for furl in set(media_streams):
205 if furl.endswith('.f4m'):
208 fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl)
209 fid = fid_m.group(1) if fid_m else None
211 'quality': QUALITIES(fid),
215 self._sort_formats(formats)
219 else: # request JSON file
221 video_id = self._search_regex(
222 r'/play/(?:config|media)/(\d+)', webpage, 'media id')
223 info = self._extract_media_info(
224 'http://www.ardmediathek.de/play/media/%s' % video_id,
229 'title': self._live_title(title) if info.get('is_live') else title,
230 'description': description,
231 'thumbnail': thumbnail,
237 class ARDIE(InfoExtractor):
238 _VALID_URL = r'(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html'
240 # available till 14.02.2019
241 'url': 'http://www.daserste.de/information/talk/maischberger/videos/das-groko-drama-zerlegen-sich-die-volksparteien-video-102.html',
242 'md5': '8e4ec85f31be7c7fc08a26cdbc5a1f49',
244 'display_id': 'das-groko-drama-zerlegen-sich-die-volksparteien-video',
248 'title': 'Das GroKo-Drama: Zerlegen sich die Volksparteien?',
249 'upload_date': '20180214',
250 'thumbnail': r're:^https?://.*\.jpg$',
253 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
254 'only_matching': True,
257 def _real_extract(self, url):
258 mobj = re.match(self._VALID_URL, url)
259 display_id = mobj.group('display_id')
261 player_url = mobj.group('mainurl') + '~playerXml.xml'
262 doc = self._download_xml(player_url, display_id)
263 video_node = doc.find('./video')
264 upload_date = unified_strdate(xpath_text(
265 video_node, './broadcastDate'))
266 thumbnail = xpath_text(video_node, './/teaserImage//variant/url')
269 for a in video_node.findall('.//asset'):
271 'format_id': a.attrib['type'],
272 'width': int_or_none(a.find('./frameWidth').text),
273 'height': int_or_none(a.find('./frameHeight').text),
274 'vbr': int_or_none(a.find('./bitrateVideo').text),
275 'abr': int_or_none(a.find('./bitrateAudio').text),
276 'vcodec': a.find('./codecVideo').text,
277 'tbr': int_or_none(a.find('./totalBitrate').text),
279 if a.find('./serverPrefix').text:
280 f['url'] = a.find('./serverPrefix').text
281 f['playpath'] = a.find('./fileName').text
283 f['url'] = a.find('./fileName').text
285 self._sort_formats(formats)
288 'id': mobj.group('id'),
290 'display_id': display_id,
291 'title': video_node.find('./title').text,
292 'duration': parse_duration(video_node.find('./duration').text),
293 'upload_date': upload_date,
294 'thumbnail': thumbnail,
298 class ARDBetaMediathekIE(InfoExtractor):
299 _VALID_URL = r'https://beta\.ardmediathek\.de/[a-z]+/player/(?P<video_id>[a-zA-Z0-9]+)/(?P<display_id>[^/?#]+)'
301 'url': 'https://beta.ardmediathek.de/ard/player/Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydC9mYmM4NGM1NC0xNzU4LTRmZGYtYWFhZS0wYzcyZTIxNGEyMDE/die-robuste-roswita',
302 'md5': '2d02d996156ea3c397cfc5036b5d7f8f',
304 'display_id': 'die-robuste-roswita',
305 'id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydC9mYmM4NGM1NC0xNzU4LTRmZGYtYWFhZS0wYzcyZTIxNGEyMDE',
306 'title': 'Tatort: Die robuste Roswita',
307 'description': r're:^Der Mord.*trüber ist als die Ilm.',
309 'thumbnail': 'https://img.ardmediathek.de/standard/00/55/43/59/34/-1774185891/16x9/960?mandant=ard',
310 'upload_date': '20180826',
315 def _real_extract(self, url):
316 mobj = re.match(self._VALID_URL, url)
317 video_id = mobj.group('video_id')
318 display_id = mobj.group('display_id')
320 webpage = self._download_webpage(url, display_id)
321 data_json = self._search_regex(r'window\.__APOLLO_STATE__\s*=\s*(\{.*);\n', webpage, 'json')
322 data = self._parse_json(data_json, display_id)
326 'display_id': display_id,
329 for widget in data.values():
330 if widget.get('_geoblocked'):
331 raise ExtractorError('This video is not available due to geoblocking', expected=True)
333 if '_duration' in widget:
334 res['duration'] = widget['_duration']
335 if 'clipTitle' in widget:
336 res['title'] = widget['clipTitle']
337 if '_previewImage' in widget:
338 res['thumbnail'] = widget['_previewImage']
339 if 'broadcastedOn' in widget:
340 res['upload_date'] = unified_strdate(widget['broadcastedOn'])
341 if 'synopsis' in widget:
342 res['description'] = widget['synopsis']
343 if '_subtitleUrl' in widget:
344 res['subtitles'] = {'de': [{
346 'url': widget['_subtitleUrl'],
348 if '_quality' in widget:
349 format_url = widget['_stream']['json'][0]
351 if format_url.endswith('.f4m'):
352 formats.extend(self._extract_f4m_formats(
353 format_url + '?hdcore=3.11.0',
354 video_id, f4m_id='hds', fatal=False))
355 elif format_url.endswith('m3u8'):
356 formats.extend(self._extract_m3u8_formats(
357 format_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
360 'format_id': 'http-' + widget['_quality'],
362 'preference': 10, # Plain HTTP, that's nice
365 self._sort_formats(formats)
366 res['formats'] = formats