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