]>
Commit | Line | Data |
---|---|---|
f9b85496 PH |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
c968f738 | 4 | import json |
d5822b96 PH |
5 | import re |
6 | ||
7 | from .common import InfoExtractor | |
3741302a | 8 | from .generic import GenericIE |
d5822b96 | 9 | from ..utils import ( |
f9b85496 | 10 | determine_ext, |
d5822b96 | 11 | ExtractorError, |
6d3d3fc0 PH |
12 | int_or_none, |
13 | parse_duration, | |
75258218 S |
14 | qualities, |
15 | str_or_none, | |
16 | try_get, | |
6d3d3fc0 | 17 | unified_strdate, |
75258218 | 18 | unified_timestamp, |
31eeab9f | 19 | update_url_query, |
3052a30d | 20 | url_or_none, |
75258218 | 21 | xpath_text, |
d5822b96 | 22 | ) |
f7854627 | 23 | from ..compat import compat_etree_fromstring |
d5822b96 | 24 | |
f9b85496 | 25 | |
c968f738 RA |
26 | class ARDMediathekBaseIE(InfoExtractor): |
27 | _GEO_COUNTRIES = ['DE'] | |
1c821227 | 28 | |
e37c92ec S |
29 | def _extract_media_info(self, media_info_url, webpage, video_id): |
30 | media_info = self._download_json( | |
31 | media_info_url, video_id, 'Downloading media JSON') | |
c968f738 | 32 | return self._parse_media_info(media_info, video_id, '"fsk"' in webpage) |
e37c92ec | 33 | |
c968f738 | 34 | def _parse_media_info(self, media_info, video_id, fsk): |
e37c92ec S |
35 | formats = self._extract_formats(media_info, video_id) |
36 | ||
37 | if not formats: | |
c968f738 | 38 | if fsk: |
b7da73eb | 39 | self.raise_no_formats( |
e37c92ec S |
40 | 'This video is only available after 20:00', expected=True) |
41 | elif media_info.get('_geoblocked'): | |
c968f738 RA |
42 | self.raise_geo_restricted( |
43 | 'This video is not available due to geoblocking', | |
b7da73eb | 44 | countries=self._GEO_COUNTRIES, metadata_available=True) |
e37c92ec S |
45 | |
46 | self._sort_formats(formats) | |
47 | ||
e37c92ec S |
48 | subtitles = {} |
49 | subtitle_url = media_info.get('_subtitleUrl') | |
50 | if subtitle_url: | |
51 | subtitles['de'] = [{ | |
ffa2cecf | 52 | 'ext': 'ttml', |
e37c92ec S |
53 | 'url': subtitle_url, |
54 | }] | |
55 | ||
56 | return { | |
57 | 'id': video_id, | |
c968f738 RA |
58 | 'duration': int_or_none(media_info.get('_duration')), |
59 | 'thumbnail': media_info.get('_previewImage'), | |
60 | 'is_live': media_info.get('_isLive') is True, | |
e37c92ec S |
61 | 'formats': formats, |
62 | 'subtitles': subtitles, | |
63 | } | |
64 | ||
e6e5d98c | 65 | def _ARD_extract_episode_info(self, title): |
66 | """Try to extract season/episode data from the title.""" | |
67 | res = {} | |
68 | if not title: | |
69 | return res | |
70 | ||
71 | for pattern in [ | |
72 | # Pattern for title like "Homo sapiens (S06/E07) - Originalversion" | |
73 | # from: https://www.ardmediathek.de/one/sendung/doctor-who/Y3JpZDovL3dkci5kZS9vbmUvZG9jdG9yIHdobw | |
74 | r'.*(?P<ep_info> \(S(?P<season_number>\d+)/E(?P<episode_number>\d+)\)).*', | |
75 | # E.g.: title="Fritjof aus Norwegen (2) (AD)" | |
76 | # from: https://www.ardmediathek.de/ard/sammlung/der-krieg-und-ich/68cMkqJdllm639Skj4c7sS/ | |
77 | r'.*(?P<ep_info> \((?:Folge |Teil )?(?P<episode_number>\d+)(?:/\d+)?\)).*', | |
78 | r'.*(?P<ep_info>Folge (?P<episode_number>\d+)(?:\:| -|) )\"(?P<episode>.+)\".*', | |
79 | # E.g.: title="Folge 25/42: Symmetrie" | |
80 | # from: https://www.ardmediathek.de/ard/video/grips-mathe/folge-25-42-symmetrie/ard-alpha/Y3JpZDovL2JyLmRlL3ZpZGVvLzMyYzI0ZjczLWQ1N2MtNDAxNC05ZmZhLTFjYzRkZDA5NDU5OQ/ | |
81 | # E.g.: title="Folge 1063 - Vertrauen" | |
82 | # from: https://www.ardmediathek.de/ard/sendung/die-fallers/Y3JpZDovL3N3ci5kZS8yMzAyMDQ4/ | |
83 | r'.*(?P<ep_info>Folge (?P<episode_number>\d+)(?:/\d+)?(?:\:| -|) ).*', | |
84 | ]: | |
85 | m = re.match(pattern, title) | |
86 | if m: | |
87 | groupdict = m.groupdict() | |
88 | res['season_number'] = int_or_none(groupdict.get('season_number')) | |
89 | res['episode_number'] = int_or_none(groupdict.get('episode_number')) | |
90 | res['episode'] = str_or_none(groupdict.get('episode')) | |
91 | # Build the episode title by removing numeric episode information: | |
92 | if groupdict.get('ep_info') and not res['episode']: | |
93 | res['episode'] = str_or_none( | |
94 | title.replace(groupdict.get('ep_info'), '')) | |
95 | if res['episode']: | |
96 | res['episode'] = res['episode'].strip() | |
97 | break | |
98 | ||
99 | # As a fallback use the whole title as the episode name: | |
100 | if not res.get('episode'): | |
101 | res['episode'] = title.strip() | |
102 | return res | |
103 | ||
e37c92ec S |
104 | def _extract_formats(self, media_info, video_id): |
105 | type_ = media_info.get('_type') | |
106 | media_array = media_info.get('_mediaArray', []) | |
107 | formats = [] | |
108 | for num, media in enumerate(media_array): | |
109 | for stream in media.get('_mediaStreamArray', []): | |
110 | stream_urls = stream.get('_stream') | |
111 | if not stream_urls: | |
112 | continue | |
113 | if not isinstance(stream_urls, list): | |
114 | stream_urls = [stream_urls] | |
115 | quality = stream.get('_quality') | |
116 | server = stream.get('_server') | |
117 | for stream_url in stream_urls: | |
3052a30d | 118 | if not url_or_none(stream_url): |
91328f26 | 119 | continue |
e37c92ec | 120 | ext = determine_ext(stream_url) |
1fc0b47f | 121 | if quality != 'auto' and ext in ('f4m', 'm3u8'): |
122 | continue | |
e37c92ec | 123 | if ext == 'f4m': |
7e5edcfd | 124 | formats.extend(self._extract_f4m_formats( |
31eeab9f RA |
125 | update_url_query(stream_url, { |
126 | 'hdcore': '3.1.1', | |
127 | 'plugin': 'aasp-3.1.1.69.124' | |
c968f738 | 128 | }), video_id, f4m_id='hds', fatal=False)) |
e37c92ec | 129 | elif ext == 'm3u8': |
7e5edcfd | 130 | formats.extend(self._extract_m3u8_formats( |
c968f738 RA |
131 | stream_url, video_id, 'mp4', 'm3u8_native', |
132 | m3u8_id='hls', fatal=False)) | |
e37c92ec S |
133 | else: |
134 | if server and server.startswith('rtmp'): | |
135 | f = { | |
136 | 'url': server, | |
137 | 'play_path': stream_url, | |
138 | 'format_id': 'a%s-rtmp-%s' % (num, quality), | |
139 | } | |
91328f26 | 140 | else: |
e37c92ec S |
141 | f = { |
142 | 'url': stream_url, | |
143 | 'format_id': 'a%s-%s-%s' % (num, ext, quality) | |
144 | } | |
c968f738 RA |
145 | m = re.search( |
146 | r'_(?P<width>\d+)x(?P<height>\d+)\.mp4$', | |
147 | stream_url) | |
e37c92ec S |
148 | if m: |
149 | f.update({ | |
150 | 'width': int(m.group('width')), | |
151 | 'height': int(m.group('height')), | |
152 | }) | |
153 | if type_ == 'audio': | |
154 | f['vcodec'] = 'none' | |
155 | formats.append(f) | |
156 | return formats | |
157 | ||
c968f738 RA |
158 | |
159 | class ARDMediathekIE(ARDMediathekBaseIE): | |
160 | IE_NAME = 'ARD:mediathek' | |
161 | _VALID_URL = r'^https?://(?:(?:(?:www|classic)\.)?ardmediathek\.de|mediathek\.(?:daserste|rbb-online)\.de|one\.ard\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?' | |
162 | ||
163 | _TESTS = [{ | |
164 | # available till 26.07.2022 | |
165 | 'url': 'http://www.ardmediathek.de/tv/S%C3%9CDLICHT/Was-ist-die-Kunst-der-Zukunft-liebe-Ann/BR-Fernsehen/Video?bcastId=34633636&documentId=44726822', | |
166 | 'info_dict': { | |
167 | 'id': '44726822', | |
168 | 'ext': 'mp4', | |
169 | 'title': 'Was ist die Kunst der Zukunft, liebe Anna McCarthy?', | |
170 | 'description': 'md5:4ada28b3e3b5df01647310e41f3a62f5', | |
171 | 'duration': 1740, | |
172 | }, | |
173 | 'params': { | |
174 | # m3u8 download | |
175 | 'skip_download': True, | |
176 | } | |
177 | }, { | |
178 | 'url': 'https://one.ard.de/tv/Mord-mit-Aussicht/Mord-mit-Aussicht-6-39-T%C3%B6dliche-Nach/ONE/Video?bcastId=46384294&documentId=55586872', | |
179 | 'only_matching': True, | |
180 | }, { | |
181 | # audio | |
182 | 'url': 'http://www.ardmediathek.de/tv/WDR-H%C3%B6rspiel-Speicher/Tod-eines-Fu%C3%9Fballers/WDR-3/Audio-Podcast?documentId=28488308&bcastId=23074086', | |
183 | 'only_matching': True, | |
184 | }, { | |
185 | 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht', | |
186 | 'only_matching': True, | |
187 | }, { | |
188 | # audio | |
189 | 'url': 'http://mediathek.rbb-online.de/radio/Hörspiel/Vor-dem-Fest/kulturradio/Audio?documentId=30796318&topRessort=radio&bcastId=9839158', | |
190 | 'only_matching': True, | |
191 | }, { | |
192 | 'url': 'https://classic.ardmediathek.de/tv/Panda-Gorilla-Co/Panda-Gorilla-Co-Folge-274/Das-Erste/Video?bcastId=16355486&documentId=58234698', | |
193 | 'only_matching': True, | |
194 | }] | |
195 | ||
196 | @classmethod | |
197 | def suitable(cls, url): | |
198 | return False if ARDBetaMediathekIE.suitable(url) else super(ARDMediathekIE, cls).suitable(url) | |
199 | ||
d5822b96 PH |
200 | def _real_extract(self, url): |
201 | # determine video id from url | |
5ad28e7f | 202 | m = self._match_valid_url(url) |
d5822b96 | 203 | |
ca127ab2 S |
204 | document_id = None |
205 | ||
d5822b96 PH |
206 | numid = re.search(r'documentId=([0-9]+)', url) |
207 | if numid: | |
ca127ab2 | 208 | document_id = video_id = numid.group(1) |
d5822b96 PH |
209 | else: |
210 | video_id = m.group('video_id') | |
211 | ||
5622f29a | 212 | webpage = self._download_webpage(url, video_id) |
f9b85496 | 213 | |
3791d84a S |
214 | ERRORS = ( |
215 | ('>Leider liegt eine Störung vor.', 'Video %s is unavailable'), | |
216 | ('>Der gewünschte Beitrag ist nicht mehr verfügbar.<', | |
217 | 'Video %s is no longer available'), | |
3791d84a S |
218 | ) |
219 | ||
220 | for pattern, message in ERRORS: | |
221 | if pattern in webpage: | |
222 | raise ExtractorError(message % video_id, expected=True) | |
39aa42ff | 223 | |
bfd91588 | 224 | if re.search(r'[\?&]rss($|[=&])', url): |
f7854627 | 225 | doc = compat_etree_fromstring(webpage.encode('utf-8')) |
3741302a OE |
226 | if doc.tag == 'rss': |
227 | return GenericIE()._extract_rss(url, video_id, doc) | |
228 | ||
a820dc72 | 229 | title = self._og_search_title(webpage, default=None) or self._html_search_regex( |
0f97c9a0 | 230 | [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>', |
197224b7 | 231 | r'<meta name="dcterms\.title" content="(.*?)"/>', |
8c587971 AS |
232 | r'<h4 class="headline">(.*?)</h4>', |
233 | r'<title[^>]*>(.*?)</title>'], | |
0f97c9a0 | 234 | webpage, 'title') |
a820dc72 | 235 | description = self._og_search_description(webpage, default=None) or self._html_search_meta( |
29546b34 PH |
236 | 'dcterms.abstract', webpage, 'description', default=None) |
237 | if description is None: | |
238 | description = self._html_search_meta( | |
8c587971 AS |
239 | 'description', webpage, 'meta description', default=None) |
240 | if description is None: | |
241 | description = self._html_search_regex( | |
242 | r'<p\s+class="teasertext">(.+?)</p>', | |
243 | webpage, 'teaser text', default=None) | |
29546b34 PH |
244 | |
245 | # Thumbnail is sometimes not present. | |
246 | # It is in the mobile version, but that seems to use a different URL | |
247 | # structure altogether. | |
248 | thumbnail = self._og_search_thumbnail(webpage, default=None) | |
249 | ||
250 | media_streams = re.findall(r'''(?x) | |
251 | mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s* | |
252 | "([^"]+)"''', webpage) | |
253 | ||
254 | if media_streams: | |
255 | QUALITIES = qualities(['lo', 'hi', 'hq']) | |
256 | formats = [] | |
257 | for furl in set(media_streams): | |
258 | if furl.endswith('.f4m'): | |
259 | fid = 'f4m' | |
260 | else: | |
261 | fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl) | |
262 | fid = fid_m.group(1) if fid_m else None | |
263 | formats.append({ | |
264 | 'quality': QUALITIES(fid), | |
265 | 'format_id': fid, | |
266 | 'url': furl, | |
267 | }) | |
e37c92ec S |
268 | self._sort_formats(formats) |
269 | info = { | |
270 | 'formats': formats, | |
271 | } | |
29546b34 | 272 | else: # request JSON file |
ca127ab2 S |
273 | if not document_id: |
274 | video_id = self._search_regex( | |
3f6a90eb | 275 | (r'/play/(?:config|media|sola)/(\d+)', r'contentId["\']\s*:\s*(\d+)'), |
276 | webpage, 'media id', default=None) | |
e37c92ec | 277 | info = self._extract_media_info( |
ca127ab2 S |
278 | 'http://www.ardmediathek.de/play/media/%s' % video_id, |
279 | webpage, video_id) | |
f9b85496 | 280 | |
e37c92ec | 281 | info.update({ |
f9b85496 | 282 | 'id': video_id, |
ca127ab2 | 283 | 'title': self._live_title(title) if info.get('is_live') else title, |
f9b85496 | 284 | 'description': description, |
f9b85496 | 285 | 'thumbnail': thumbnail, |
e37c92ec | 286 | }) |
e6e5d98c | 287 | info.update(self._ARD_extract_episode_info(info['title'])) |
e37c92ec S |
288 | |
289 | return info | |
6d3d3fc0 PH |
290 | |
291 | ||
292 | class ARDIE(InfoExtractor): | |
14eb1ee1 | 293 | _VALID_URL = r'(?P<mainurl>https?://(?:www\.)?daserste\.de/(?:[^/?#&]+/)+(?P<id>[^/?#&]+))\.html' |
ad29ef04 | 294 | _TESTS = [{ |
a820dc72 RA |
295 | # available till 7.01.2022 |
296 | 'url': 'https://www.daserste.de/information/talk/maischberger/videos/maischberger-die-woche-video100.html', | |
297 | 'md5': '867d8aa39eeaf6d76407c5ad1bb0d4c1', | |
ad29ef04 | 298 | 'info_dict': { |
14eb1ee1 | 299 | 'id': 'maischberger-die-woche-video100', |
300 | 'display_id': 'maischberger-die-woche-video100', | |
ad29ef04 | 301 | 'ext': 'mp4', |
a820dc72 RA |
302 | 'duration': 3687.0, |
303 | 'title': 'maischberger. die woche vom 7. Januar 2021', | |
304 | 'upload_date': '20210107', | |
ad29ef04 W |
305 | 'thumbnail': r're:^https?://.*\.jpg$', |
306 | }, | |
a54c5f83 | 307 | }, { |
14eb1ee1 | 308 | 'url': 'https://www.daserste.de/information/politik-weltgeschehen/morgenmagazin/videosextern/dominik-kahun-aus-der-nhl-direkt-zur-weltmeisterschaft-100.html', |
309 | 'only_matching': True, | |
310 | }, { | |
311 | 'url': 'https://www.daserste.de/information/nachrichten-wetter/tagesthemen/videosextern/tagesthemen-17736.html', | |
a54c5f83 | 312 | 'only_matching': True, |
f17c7022 OF |
313 | }, { |
314 | 'url': 'https://www.daserste.de/unterhaltung/serie/in-aller-freundschaft-die-jungen-aerzte/videos/diversity-tag-sanam-afrashteh100.html', | |
315 | 'only_matching': True, | |
d6a03502 | 316 | }, { |
6d3d3fc0 | 317 | 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html', |
d6a03502 | 318 | 'only_matching': True, |
14eb1ee1 | 319 | }, { |
320 | 'url': 'https://www.daserste.de/unterhaltung/serie/in-aller-freundschaft-die-jungen-aerzte/Drehpause-100.html', | |
321 | 'only_matching': True, | |
322 | }, { | |
323 | 'url': 'https://www.daserste.de/unterhaltung/film/filmmittwoch-im-ersten/videos/making-ofwendezeit-video-100.html', | |
324 | 'only_matching': True, | |
ad29ef04 | 325 | }] |
6d3d3fc0 PH |
326 | |
327 | def _real_extract(self, url): | |
5ad28e7f | 328 | mobj = self._match_valid_url(url) |
14eb1ee1 | 329 | display_id = mobj.group('id') |
6d3d3fc0 PH |
330 | |
331 | player_url = mobj.group('mainurl') + '~playerXml.xml' | |
332 | doc = self._download_xml(player_url, display_id) | |
333 | video_node = doc.find('./video') | |
bf0ff932 PH |
334 | upload_date = unified_strdate(xpath_text( |
335 | video_node, './broadcastDate')) | |
336 | thumbnail = xpath_text(video_node, './/teaserImage//variant/url') | |
6d3d3fc0 PH |
337 | |
338 | formats = [] | |
339 | for a in video_node.findall('.//asset'): | |
bc2ca1bb | 340 | file_name = xpath_text(a, './fileName', default=None) |
341 | if not file_name: | |
342 | continue | |
343 | format_type = a.attrib.get('type') | |
344 | format_url = url_or_none(file_name) | |
345 | if format_url: | |
346 | ext = determine_ext(file_name) | |
347 | if ext == 'm3u8': | |
348 | formats.extend(self._extract_m3u8_formats( | |
349 | format_url, display_id, 'mp4', entry_protocol='m3u8_native', | |
350 | m3u8_id=format_type or 'hls', fatal=False)) | |
351 | continue | |
352 | elif ext == 'f4m': | |
353 | formats.extend(self._extract_f4m_formats( | |
354 | update_url_query(format_url, {'hdcore': '3.7.0'}), | |
355 | display_id, f4m_id=format_type or 'hds', fatal=False)) | |
356 | continue | |
6d3d3fc0 | 357 | f = { |
bc2ca1bb | 358 | 'format_id': format_type, |
359 | 'width': int_or_none(xpath_text(a, './frameWidth')), | |
360 | 'height': int_or_none(xpath_text(a, './frameHeight')), | |
361 | 'vbr': int_or_none(xpath_text(a, './bitrateVideo')), | |
362 | 'abr': int_or_none(xpath_text(a, './bitrateAudio')), | |
363 | 'vcodec': xpath_text(a, './codecVideo'), | |
364 | 'tbr': int_or_none(xpath_text(a, './totalBitrate')), | |
6d3d3fc0 | 365 | } |
bc2ca1bb | 366 | server_prefix = xpath_text(a, './serverPrefix', default=None) |
367 | if server_prefix: | |
368 | f.update({ | |
369 | 'url': server_prefix, | |
370 | 'playpath': file_name, | |
371 | }) | |
6d3d3fc0 | 372 | else: |
bc2ca1bb | 373 | if not format_url: |
374 | continue | |
375 | f['url'] = format_url | |
6d3d3fc0 PH |
376 | formats.append(f) |
377 | self._sort_formats(formats) | |
378 | ||
379 | return { | |
14eb1ee1 | 380 | 'id': xpath_text(video_node, './videoId', default=display_id), |
6d3d3fc0 PH |
381 | 'formats': formats, |
382 | 'display_id': display_id, | |
383 | 'title': video_node.find('./title').text, | |
384 | 'duration': parse_duration(video_node.find('./duration').text), | |
385 | 'upload_date': upload_date, | |
386 | 'thumbnail': thumbnail, | |
387 | } | |
c1a37eb2 PH |
388 | |
389 | ||
c968f738 | 390 | class ARDBetaMediathekIE(ARDMediathekBaseIE): |
e6e5d98c | 391 | _VALID_URL = r'https://(?:(?:beta|www)\.)?ardmediathek\.de/(?P<client>[^/]+)/(?P<mode>player|live|video|sendung|sammlung)/(?P<display_id>(?:[^/]+/)*)(?P<video_id>[a-zA-Z0-9]+)' |
c1a37eb2 | 392 | _TESTS = [{ |
a820dc72 RA |
393 | 'url': 'https://www.ardmediathek.de/mdr/video/die-robuste-roswita/Y3JpZDovL21kci5kZS9iZWl0cmFnL2Ntcy84MWMxN2MzZC0wMjkxLTRmMzUtODk4ZS0wYzhlOWQxODE2NGI/', |
394 | 'md5': 'a1dc75a39c61601b980648f7c9f9f71d', | |
c1a37eb2 PH |
395 | 'info_dict': { |
396 | 'display_id': 'die-robuste-roswita', | |
a820dc72 | 397 | 'id': '78566716', |
c968f738 | 398 | 'title': 'Die robuste Roswita', |
a820dc72 | 399 | 'description': r're:^Der Mord.*totgeglaubte Ehefrau Roswita', |
c1a37eb2 | 400 | 'duration': 5316, |
a820dc72 RA |
401 | 'thumbnail': 'https://img.ardmediathek.de/standard/00/78/56/67/84/575672121/16x9/960?mandant=ard', |
402 | 'timestamp': 1596658200, | |
403 | 'upload_date': '20200805', | |
c1a37eb2 PH |
404 | 'ext': 'mp4', |
405 | }, | |
fe515e5c S |
406 | }, { |
407 | 'url': 'https://beta.ardmediathek.de/ard/video/Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydC9mYmM4NGM1NC0xNzU4LTRmZGYtYWFhZS0wYzcyZTIxNGEyMDE', | |
408 | 'only_matching': True, | |
409 | }, { | |
410 | 'url': 'https://ardmediathek.de/ard/video/saartalk/saartalk-gesellschaftsgift-haltung-gegen-hass/sr-fernsehen/Y3JpZDovL3NyLW9ubGluZS5kZS9TVF84MTY4MA/', | |
411 | 'only_matching': True, | |
412 | }, { | |
413 | 'url': 'https://www.ardmediathek.de/ard/video/trailer/private-eyes-s01-e01/one/Y3JpZDovL3dkci5kZS9CZWl0cmFnLTE1MTgwYzczLWNiMTEtNGNkMS1iMjUyLTg5MGYzOWQxZmQ1YQ/', | |
414 | 'only_matching': True, | |
1c821227 S |
415 | }, { |
416 | 'url': 'https://www.ardmediathek.de/ard/player/Y3JpZDovL3N3ci5kZS9hZXgvbzEwNzE5MTU/', | |
417 | 'only_matching': True, | |
418 | }, { | |
419 | 'url': 'https://www.ardmediathek.de/swr/live/Y3JpZDovL3N3ci5kZS8xMzQ4MTA0Mg', | |
420 | 'only_matching': True, | |
e6e5d98c | 421 | }, { |
422 | # playlist of type 'sendung' | |
423 | 'url': 'https://www.ardmediathek.de/ard/sendung/doctor-who/Y3JpZDovL3dkci5kZS9vbmUvZG9jdG9yIHdobw/', | |
424 | 'only_matching': True, | |
425 | }, { | |
426 | # playlist of type 'sammlung' | |
427 | 'url': 'https://www.ardmediathek.de/ard/sammlung/team-muenster/5JpTzLSbWUAK8184IOvEir/', | |
428 | 'only_matching': True, | |
c1a37eb2 PH |
429 | }] |
430 | ||
e6e5d98c | 431 | def _ARD_load_playlist_snipped(self, playlist_id, display_id, client, mode, pageNumber): |
432 | """ Query the ARD server for playlist information | |
433 | and returns the data in "raw" format """ | |
434 | if mode == 'sendung': | |
435 | graphQL = json.dumps({ | |
436 | 'query': '''{ | |
437 | showPage( | |
438 | client: "%s" | |
439 | showId: "%s" | |
440 | pageNumber: %d | |
441 | ) { | |
442 | pagination { | |
443 | pageSize | |
444 | totalElements | |
445 | } | |
446 | teasers { # Array | |
447 | mediumTitle | |
448 | links { target { id href title } } | |
449 | type | |
450 | } | |
451 | }}''' % (client, playlist_id, pageNumber), | |
452 | }).encode() | |
453 | else: # mode == 'sammlung' | |
454 | graphQL = json.dumps({ | |
455 | 'query': '''{ | |
456 | morePage( | |
457 | client: "%s" | |
458 | compilationId: "%s" | |
459 | pageNumber: %d | |
460 | ) { | |
461 | widget { | |
462 | pagination { | |
463 | pageSize | |
464 | totalElements | |
465 | } | |
466 | teasers { # Array | |
467 | mediumTitle | |
468 | links { target { id href title } } | |
469 | type | |
470 | } | |
471 | } | |
472 | }}''' % (client, playlist_id, pageNumber), | |
473 | }).encode() | |
474 | # Ressources for ARD graphQL debugging: | |
475 | # https://api-test.ardmediathek.de/public-gateway | |
476 | show_page = self._download_json( | |
477 | 'https://api.ardmediathek.de/public-gateway', | |
478 | '[Playlist] %s' % display_id, | |
479 | data=graphQL, | |
480 | headers={'Content-Type': 'application/json'})['data'] | |
481 | # align the structure of the returned data: | |
482 | if mode == 'sendung': | |
483 | show_page = show_page['showPage'] | |
484 | else: # mode == 'sammlung' | |
485 | show_page = show_page['morePage']['widget'] | |
486 | return show_page | |
487 | ||
488 | def _ARD_extract_playlist(self, url, playlist_id, display_id, client, mode): | |
489 | """ Collects all playlist entries and returns them as info dict. | |
490 | Supports playlists of mode 'sendung' and 'sammlung', and also nested | |
491 | playlists. """ | |
492 | entries = [] | |
493 | pageNumber = 0 | |
494 | while True: # iterate by pageNumber | |
495 | show_page = self._ARD_load_playlist_snipped( | |
496 | playlist_id, display_id, client, mode, pageNumber) | |
497 | for teaser in show_page['teasers']: # process playlist items | |
498 | if '/compilation/' in teaser['links']['target']['href']: | |
499 | # alternativ cond.: teaser['type'] == "compilation" | |
500 | # => This is an nested compilation, e.g. like: | |
501 | # https://www.ardmediathek.de/ard/sammlung/die-kirche-bleibt-im-dorf/5eOHzt8XB2sqeFXbIoJlg2/ | |
502 | link_mode = 'sammlung' | |
503 | else: | |
504 | link_mode = 'video' | |
505 | ||
506 | item_url = 'https://www.ardmediathek.de/%s/%s/%s/%s/%s' % ( | |
507 | client, link_mode, display_id, | |
508 | # perform HTLM quoting of episode title similar to ARD: | |
509 | re.sub('^-|-$', '', # remove '-' from begin/end | |
510 | re.sub('[^a-zA-Z0-9]+', '-', # replace special chars by - | |
511 | teaser['links']['target']['title'].lower() | |
512 | .replace('ä', 'ae').replace('ö', 'oe') | |
513 | .replace('ü', 'ue').replace('ß', 'ss'))), | |
514 | teaser['links']['target']['id']) | |
515 | entries.append(self.url_result( | |
516 | item_url, | |
517 | ie=ARDBetaMediathekIE.ie_key())) | |
518 | ||
519 | if (show_page['pagination']['pageSize'] * (pageNumber + 1) | |
520 | >= show_page['pagination']['totalElements']): | |
521 | # we've processed enough pages to get all playlist entries | |
522 | break | |
523 | pageNumber = pageNumber + 1 | |
524 | ||
525 | return self.playlist_result(entries, playlist_title=display_id) | |
526 | ||
c1a37eb2 | 527 | def _real_extract(self, url): |
5ad28e7f | 528 | mobj = self._match_valid_url(url) |
b704fc1a | 529 | video_id = mobj.group('video_id') |
530 | display_id = mobj.group('display_id') | |
531 | if display_id: | |
532 | display_id = display_id.rstrip('/') | |
533 | if not display_id: | |
534 | display_id = video_id | |
c1a37eb2 | 535 | |
e6e5d98c | 536 | if mobj.group('mode') in ('sendung', 'sammlung'): |
537 | # this is a playlist-URL | |
538 | return self._ARD_extract_playlist( | |
539 | url, video_id, display_id, | |
540 | mobj.group('client'), | |
541 | mobj.group('mode')) | |
542 | ||
c968f738 RA |
543 | player_page = self._download_json( |
544 | 'https://api.ardmediathek.de/public-gateway', | |
b704fc1a | 545 | display_id, data=json.dumps({ |
c968f738 | 546 | 'query': '''{ |
b704fc1a | 547 | playerPage(client:"%s", clipId: "%s") { |
c968f738 RA |
548 | blockedByFsk |
549 | broadcastedOn | |
550 | maturityContentRating | |
551 | mediaCollection { | |
552 | _duration | |
553 | _geoblocked | |
554 | _isLive | |
555 | _mediaArray { | |
556 | _mediaStreamArray { | |
557 | _quality | |
558 | _server | |
559 | _stream | |
c1a37eb2 | 560 | } |
c968f738 RA |
561 | } |
562 | _previewImage | |
563 | _subtitleUrl | |
564 | _type | |
565 | } | |
566 | show { | |
567 | title | |
568 | } | |
569 | synopsis | |
570 | title | |
571 | tracking { | |
572 | atiCustomVars { | |
573 | contentId | |
574 | } | |
575 | } | |
576 | } | |
b704fc1a | 577 | }''' % (mobj.group('client'), video_id), |
c968f738 RA |
578 | }).encode(), headers={ |
579 | 'Content-Type': 'application/json' | |
580 | })['data']['playerPage'] | |
581 | title = player_page['title'] | |
582 | content_id = str_or_none(try_get( | |
583 | player_page, lambda x: x['tracking']['atiCustomVars']['contentId'])) | |
584 | media_collection = player_page.get('mediaCollection') or {} | |
585 | if not media_collection and content_id: | |
586 | media_collection = self._download_json( | |
587 | 'https://www.ardmediathek.de/play/media/' + content_id, | |
588 | content_id, fatal=False) or {} | |
589 | info = self._parse_media_info( | |
590 | media_collection, content_id or video_id, | |
591 | player_page.get('blockedByFsk')) | |
592 | age_limit = None | |
593 | description = player_page.get('synopsis') | |
594 | maturity_content_rating = player_page.get('maturityContentRating') | |
595 | if maturity_content_rating: | |
596 | age_limit = int_or_none(maturity_content_rating.lstrip('FSK')) | |
f4a18db7 RA |
597 | if not age_limit and description: |
598 | age_limit = int_or_none(self._search_regex( | |
599 | r'\(FSK\s*(\d+)\)\s*$', description, 'age limit', default=None)) | |
c968f738 RA |
600 | info.update({ |
601 | 'age_limit': age_limit, | |
b704fc1a | 602 | 'display_id': display_id, |
c968f738 RA |
603 | 'title': title, |
604 | 'description': description, | |
605 | 'timestamp': unified_timestamp(player_page.get('broadcastedOn')), | |
606 | 'series': try_get(player_page, lambda x: x['show']['title']), | |
75258218 | 607 | }) |
e6e5d98c | 608 | info.update(self._ARD_extract_episode_info(info['title'])) |
c968f738 | 609 | return info |