]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/tvnow.py
Completely change project name to yt-dlp (#85)
[yt-dlp.git] / yt_dlp / extractor / tvnow.py
CommitLineData
23b6e230
RA
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
7from ..compat import compat_str
8from ..utils import (
9 ExtractorError,
0d0c9e82 10 get_element_by_id,
574e9db2 11 int_or_none,
23b6e230
RA
12 parse_iso8601,
13 parse_duration,
de0359c0 14 str_or_none,
0d0c9e82 15 try_get,
23b6e230 16 update_url_query,
de0359c0 17 urljoin,
23b6e230
RA
18)
19
20
21class TVNowBaseIE(InfoExtractor):
22 _VIDEO_FIELDS = (
23 'id', 'title', 'free', 'geoblocked', 'articleLong', 'articleShort',
574e9db2 24 'broadcastStartDate', 'isDrm', 'duration', 'season', 'episode',
8ba84e46
RA
25 'manifest.dashclear', 'manifest.hlsclear', 'manifest.smoothclear',
26 'format.title', 'format.defaultImage169Format', 'format.defaultImage169Logo')
23b6e230
RA
27
28 def _call_api(self, path, video_id, query):
29 return self._download_json(
de0359c0 30 'https://api.tvnow.de/v3/' + path, video_id, query=query)
23b6e230
RA
31
32 def _extract_video(self, info, display_id):
33 video_id = compat_str(info['id'])
34 title = info['title']
35
8ba84e46
RA
36 paths = []
37 for manifest_url in (info.get('manifest') or {}).values():
38 if not manifest_url:
39 continue
40 manifest_url = update_url_query(manifest_url, {'filter': ''})
41 path = self._search_regex(r'https?://[^/]+/(.+?)\.ism/', manifest_url, 'path')
42 if path in paths:
43 continue
44 paths.append(path)
45
46 def url_repl(proto, suffix):
47 return re.sub(
48 r'(?:hls|dash|hss)([.-])', proto + r'\1', re.sub(
49 r'\.ism/(?:[^.]*\.(?:m3u8|mpd)|[Mm]anifest)',
50 '.ism/' + suffix, manifest_url))
51
e75220b1
S
52 def make_urls(proto, suffix):
53 urls = [url_repl(proto, suffix)]
54 hd_url = urls[0].replace('/manifest/', '/ngvod/')
55 if hd_url != urls[0]:
56 urls.append(hd_url)
57 return urls
58
59 for man_url in make_urls('dash', '.mpd'):
60 formats = self._extract_mpd_formats(
61 man_url, video_id, mpd_id='dash', fatal=False)
62 for man_url in make_urls('hss', 'Manifest'):
63 formats.extend(self._extract_ism_formats(
64 man_url, video_id, ism_id='mss', fatal=False))
65 for man_url in make_urls('hls', '.m3u8'):
66 formats.extend(self._extract_m3u8_formats(
67 man_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls',
68 fatal=False))
8ba84e46
RA
69 if formats:
70 break
71 else:
63ad4d43 72 if not self._downloader.params.get('allow_unplayable_formats') and info.get('isDrm'):
23b6e230
RA
73 raise ExtractorError(
74 'Video %s is DRM protected' % video_id, expected=True)
75 if info.get('geoblocked'):
8ba84e46 76 raise self.raise_geo_restricted()
23b6e230
RA
77 if not info.get('free', True):
78 raise ExtractorError(
79 'Video %s is not available for free' % video_id, expected=True)
23b6e230
RA
80 self._sort_formats(formats)
81
82 description = info.get('articleLong') or info.get('articleShort')
83 timestamp = parse_iso8601(info.get('broadcastStartDate'), ' ')
84 duration = parse_duration(info.get('duration'))
85
86 f = info.get('format', {})
ea6679fb
S
87
88 thumbnails = [{
89 'url': 'https://aistvnow-a.akamaihd.net/tvnow/movie/%s' % video_id,
90 }]
91 thumbnail = f.get('defaultImage169Format') or f.get('defaultImage169Logo')
92 if thumbnail:
93 thumbnails.append({
94 'url': thumbnail,
95 })
23b6e230
RA
96
97 return {
98 'id': video_id,
99 'display_id': display_id,
100 'title': title,
101 'description': description,
ea6679fb 102 'thumbnails': thumbnails,
23b6e230
RA
103 'timestamp': timestamp,
104 'duration': duration,
574e9db2
S
105 'series': f.get('title'),
106 'season_number': int_or_none(info.get('season')),
107 'episode_number': int_or_none(info.get('episode')),
108 'episode': title,
23b6e230
RA
109 'formats': formats,
110 }
111
112
113class TVNowIE(TVNowBaseIE):
ea6679fb
S
114 _VALID_URL = r'''(?x)
115 https?://
8ba84e46 116 (?:www\.)?tvnow\.(?:de|at|ch)/(?P<station>[^/]+)/
ea6679fb
S
117 (?P<show_id>[^/]+)/
118 (?!(?:list|jahr)(?:/|$))(?P<id>[^/?\#&]+)
119 '''
23b6e230 120
de0359c0
S
121 @classmethod
122 def suitable(cls, url):
123 return (False if TVNowNewIE.suitable(url) or TVNowSeasonIE.suitable(url) or TVNowAnnualIE.suitable(url) or TVNowShowIE.suitable(url)
124 else super(TVNowIE, cls).suitable(url))
125
23b6e230 126 _TESTS = [{
574e9db2 127 'url': 'https://www.tvnow.de/rtl2/grip-das-motormagazin/der-neue-porsche-911-gt-3/player',
23b6e230 128 'info_dict': {
574e9db2
S
129 'id': '331082',
130 'display_id': 'grip-das-motormagazin/der-neue-porsche-911-gt-3',
23b6e230 131 'ext': 'mp4',
574e9db2
S
132 'title': 'Der neue Porsche 911 GT 3',
133 'description': 'md5:6143220c661f9b0aae73b245e5d898bb',
574e9db2
S
134 'timestamp': 1495994400,
135 'upload_date': '20170528',
136 'duration': 5283,
137 'series': 'GRIP - Das Motormagazin',
138 'season_number': 14,
139 'episode_number': 405,
140 'episode': 'Der neue Porsche 911 GT 3',
23b6e230
RA
141 },
142 }, {
143 # rtl2
144 'url': 'https://www.tvnow.de/rtl2/armes-deutschland/episode-0008/player',
ea6679fb 145 'only_matching': True,
23b6e230
RA
146 }, {
147 # rtlnitro
148 'url': 'https://www.tvnow.de/nitro/alarm-fuer-cobra-11-die-autobahnpolizei/auf-eigene-faust-pilot/player',
ea6679fb 149 'only_matching': True,
23b6e230
RA
150 }, {
151 # superrtl
152 'url': 'https://www.tvnow.de/superrtl/die-lustigsten-schlamassel-der-welt/u-a-ketchup-effekt/player',
ea6679fb 153 'only_matching': True,
23b6e230
RA
154 }, {
155 # ntv
156 'url': 'https://www.tvnow.de/ntv/startup-news/goetter-in-weiss/player',
ea6679fb 157 'only_matching': True,
23b6e230
RA
158 }, {
159 # vox
160 'url': 'https://www.tvnow.de/vox/auto-mobil/neues-vom-automobilmarkt-2017-11-19-17-00-00/player',
ea6679fb 161 'only_matching': True,
23b6e230
RA
162 }, {
163 # rtlplus
164 'url': 'https://www.tvnow.de/rtlplus/op-ruft-dr-bruckner/die-vernaehte-frau/player',
ea6679fb
S
165 'only_matching': True,
166 }, {
167 'url': 'https://www.tvnow.de/rtl2/grip-das-motormagazin/der-neue-porsche-911-gt-3',
168 'only_matching': True,
23b6e230
RA
169 }]
170
171 def _real_extract(self, url):
8ba84e46
RA
172 mobj = re.match(self._VALID_URL, url)
173 display_id = '%s/%s' % mobj.group(2, 3)
23b6e230
RA
174
175 info = self._call_api(
176 'movies/' + display_id, display_id, query={
177 'fields': ','.join(self._VIDEO_FIELDS),
178 })
179
180 return self._extract_video(info, display_id)
181
182
de0359c0
S
183class TVNowNewIE(InfoExtractor):
184 _VALID_URL = r'''(?x)
185 (?P<base_url>https?://
186 (?:www\.)?tvnow\.(?:de|at|ch)/
187 (?:shows|serien))/
188 (?P<show>[^/]+)-\d+/
189 [^/]+/
190 episode-\d+-(?P<episode>[^/?$&]+)-(?P<id>\d+)
ea6679fb
S
191 '''
192
de0359c0
S
193 _TESTS = [{
194 'url': 'https://www.tvnow.de/shows/grip-das-motormagazin-1669/2017-05/episode-405-der-neue-porsche-911-gt-3-331082',
195 'only_matching': True,
196 }]
23b6e230 197
de0359c0
S
198 def _real_extract(self, url):
199 mobj = re.match(self._VALID_URL, url)
200 base_url = re.sub(r'(?:shows|serien)', '_', mobj.group('base_url'))
201 show, episode = mobj.group('show', 'episode')
202 return self.url_result(
203 # Rewrite new URLs to the old format and use extraction via old API
204 # at api.tvnow.de as a loophole for bypassing premium content checks
205 '%s/%s/%s' % (base_url, show, episode),
206 ie=TVNowIE.ie_key(), video_id=mobj.group('id'))
207
208
0d0c9e82
T
209class TVNowFilmIE(TVNowBaseIE):
210 _VALID_URL = r'''(?x)
211 (?P<base_url>https?://
212 (?:www\.)?tvnow\.(?:de|at|ch)/
213 (?:filme))/
214 (?P<title>[^/?$&]+)-(?P<id>\d+)
215 '''
216 _TESTS = [{
217 'url': 'https://www.tvnow.de/filme/lord-of-war-haendler-des-todes-7959',
218 'info_dict': {
219 'id': '1426690',
220 'display_id': 'lord-of-war-haendler-des-todes',
221 'ext': 'mp4',
222 'title': 'Lord of War',
223 'description': 'md5:5eda15c0d5b8cb70dac724c8a0ff89a9',
224 'timestamp': 1550010000,
225 'upload_date': '20190212',
226 'duration': 7016,
227 },
228 }, {
229 'url': 'https://www.tvnow.de/filme/the-machinist-12157',
230 'info_dict': {
231 'id': '328160',
232 'display_id': 'the-machinist',
233 'ext': 'mp4',
234 'title': 'The Machinist',
235 'description': 'md5:9a0e363fdd74b3a9e1cdd9e21d0ecc28',
236 'timestamp': 1496469720,
237 'upload_date': '20170603',
238 'duration': 5836,
239 },
240 }, {
241 'url': 'https://www.tvnow.de/filme/horst-schlaemmer-isch-kandidiere-17777',
242 'only_matching': True, # DRM protected
243 }]
244
245 def _real_extract(self, url):
246 mobj = re.match(self._VALID_URL, url)
247 display_id = mobj.group('title')
248
249 webpage = self._download_webpage(url, display_id, fatal=False)
250 if not webpage:
251 raise ExtractorError('Cannot download "%s"' % url, expected=True)
252
253 json_text = get_element_by_id('now-web-state', webpage)
254 if not json_text:
255 raise ExtractorError('Cannot read video data', expected=True)
256
257 json_data = self._parse_json(
258 json_text,
259 display_id,
260 transform_source=lambda x: x.replace('&q;', '"'),
261 fatal=False)
262 if not json_data:
263 raise ExtractorError('Cannot read video data', expected=True)
264
265 player_key = next(
266 (key for key in json_data.keys() if 'module/player' in key),
267 None)
268 page_key = next(
269 (key for key in json_data.keys() if 'page/filme' in key),
270 None)
271 movie_id = try_get(
272 json_data,
273 [
274 lambda x: x[player_key]['body']['id'],
275 lambda x: x[page_key]['body']['modules'][0]['id'],
276 lambda x: x[page_key]['body']['modules'][1]['id']],
277 int)
278 if not movie_id:
279 raise ExtractorError('Cannot extract movie ID', expected=True)
280
281 info = self._call_api(
282 'movies/%d' % movie_id,
283 display_id,
284 query={'fields': ','.join(self._VIDEO_FIELDS)})
285
286 return self._extract_video(info, display_id)
287
288
de0359c0
S
289class TVNowNewBaseIE(InfoExtractor):
290 def _call_api(self, path, video_id, query={}):
291 result = self._download_json(
292 'https://apigw.tvnow.de/module/' + path, video_id, query=query)
293 error = result.get('error')
294 if error:
295 raise ExtractorError(
296 '%s said: %s' % (self.IE_NAME, error), expected=True)
297 return result
298
299
d23e8551 300r"""
de0359c0
S
301TODO: new apigw.tvnow.de based version of TVNowIE. Replace old TVNowIE with it
302when api.tvnow.de is shut down. This version can't bypass premium checks though.
303class TVNowIE(TVNowNewBaseIE):
304 _VALID_URL = r'''(?x)
305 https?://
306 (?:www\.)?tvnow\.(?:de|at|ch)/
307 (?:shows|serien)/[^/]+/
308 (?:[^/]+/)+
309 (?P<display_id>[^/?$&]+)-(?P<id>\d+)
310 '''
23b6e230
RA
311
312 _TESTS = [{
de0359c0
S
313 # episode with annual navigation
314 'url': 'https://www.tvnow.de/shows/grip-das-motormagazin-1669/2017-05/episode-405-der-neue-porsche-911-gt-3-331082',
23b6e230 315 'info_dict': {
de0359c0
S
316 'id': '331082',
317 'display_id': 'grip-das-motormagazin/der-neue-porsche-911-gt-3',
318 'ext': 'mp4',
319 'title': 'Der neue Porsche 911 GT 3',
320 'description': 'md5:6143220c661f9b0aae73b245e5d898bb',
321 'thumbnail': r're:^https?://.*\.jpg$',
322 'timestamp': 1495994400,
323 'upload_date': '20170528',
324 'duration': 5283,
325 'series': 'GRIP - Das Motormagazin',
326 'season_number': 14,
327 'episode_number': 405,
328 'episode': 'Der neue Porsche 911 GT 3',
23b6e230 329 },
ea6679fb 330 }, {
de0359c0
S
331 # rtl2, episode with season navigation
332 'url': 'https://www.tvnow.de/shows/armes-deutschland-11471/staffel-3/episode-14-bernd-steht-seit-der-trennung-von-seiner-frau-allein-da-526124',
ea6679fb
S
333 'only_matching': True,
334 }, {
de0359c0
S
335 # rtlnitro
336 'url': 'https://www.tvnow.de/serien/alarm-fuer-cobra-11-die-autobahnpolizei-1815/staffel-13/episode-5-auf-eigene-faust-pilot-366822',
337 'only_matching': True,
338 }, {
339 # superrtl
340 'url': 'https://www.tvnow.de/shows/die-lustigsten-schlamassel-der-welt-1221/staffel-2/episode-14-u-a-ketchup-effekt-364120',
341 'only_matching': True,
342 }, {
343 # ntv
344 'url': 'https://www.tvnow.de/shows/startup-news-10674/staffel-2/episode-39-goetter-in-weiss-387630',
345 'only_matching': True,
346 }, {
347 # vox
348 'url': 'https://www.tvnow.de/shows/auto-mobil-174/2017-11/episode-46-neues-vom-automobilmarkt-2017-11-19-17-00-00-380072',
349 'only_matching': True,
350 }, {
351 'url': 'https://www.tvnow.de/shows/grip-das-motormagazin-1669/2017-05/episode-405-der-neue-porsche-911-gt-3-331082',
ea6679fb 352 'only_matching': True,
23b6e230
RA
353 }]
354
de0359c0
S
355 def _extract_video(self, info, url, display_id):
356 config = info['config']
357 source = config['source']
ea6679fb 358
de0359c0
S
359 video_id = compat_str(info.get('id') or source['videoId'])
360 title = source['title'].strip()
23b6e230 361
de0359c0
S
362 paths = []
363 for manifest_url in (info.get('manifest') or {}).values():
364 if not manifest_url:
365 continue
366 manifest_url = update_url_query(manifest_url, {'filter': ''})
367 path = self._search_regex(r'https?://[^/]+/(.+?)\.ism/', manifest_url, 'path')
368 if path in paths:
369 continue
370 paths.append(path)
23b6e230 371
de0359c0
S
372 def url_repl(proto, suffix):
373 return re.sub(
374 r'(?:hls|dash|hss)([.-])', proto + r'\1', re.sub(
375 r'\.ism/(?:[^.]*\.(?:m3u8|mpd)|[Mm]anifest)',
376 '.ism/' + suffix, manifest_url))
23b6e230 377
de0359c0
S
378 formats = self._extract_mpd_formats(
379 url_repl('dash', '.mpd'), video_id,
380 mpd_id='dash', fatal=False)
381 formats.extend(self._extract_ism_formats(
382 url_repl('hss', 'Manifest'),
383 video_id, ism_id='mss', fatal=False))
384 formats.extend(self._extract_m3u8_formats(
385 url_repl('hls', '.m3u8'), video_id, 'mp4',
386 'm3u8_native', m3u8_id='hls', fatal=False))
387 if formats:
388 break
ea6679fb 389 else:
de0359c0
S
390 if try_get(info, lambda x: x['rights']['isDrm']):
391 raise ExtractorError(
392 'Video %s is DRM protected' % video_id, expected=True)
393 if try_get(config, lambda x: x['boards']['geoBlocking']['block']):
394 raise self.raise_geo_restricted()
395 if not info.get('free', True):
396 raise ExtractorError(
397 'Video %s is not available for free' % video_id, expected=True)
398 self._sort_formats(formats)
399
400 description = source.get('description')
401 thumbnail = url_or_none(source.get('poster'))
402 timestamp = unified_timestamp(source.get('previewStart'))
403 duration = parse_duration(source.get('length'))
404
405 series = source.get('format')
406 season_number = int_or_none(self._search_regex(
407 r'staffel-(\d+)', url, 'season number', default=None))
408 episode_number = int_or_none(self._search_regex(
409 r'episode-(\d+)', url, 'episode number', default=None))
410
411 return {
412 'id': video_id,
413 'display_id': display_id,
414 'title': title,
415 'description': description,
416 'thumbnail': thumbnail,
417 'timestamp': timestamp,
418 'duration': duration,
419 'series': series,
420 'season_number': season_number,
421 'episode_number': episode_number,
422 'episode': title,
423 'formats': formats,
424 }
425
426 def _real_extract(self, url):
427 display_id, video_id = re.match(self._VALID_URL, url).groups()
428 info = self._call_api('player/' + video_id, video_id)
429 return self._extract_video(info, video_id, display_id)
0d0c9e82
T
430
431
432class TVNowFilmIE(TVNowIE):
433 _VALID_URL = r'''(?x)
434 (?P<base_url>https?://
435 (?:www\.)?tvnow\.(?:de|at|ch)/
436 (?:filme))/
437 (?P<title>[^/?$&]+)-(?P<id>\d+)
438 '''
439 _TESTS = [{
440 'url': 'https://www.tvnow.de/filme/lord-of-war-haendler-des-todes-7959',
441 'info_dict': {
442 'id': '1426690',
443 'display_id': 'lord-of-war-haendler-des-todes',
444 'ext': 'mp4',
445 'title': 'Lord of War',
446 'description': 'md5:5eda15c0d5b8cb70dac724c8a0ff89a9',
447 'timestamp': 1550010000,
448 'upload_date': '20190212',
449 'duration': 7016,
450 },
451 }, {
452 'url': 'https://www.tvnow.de/filme/the-machinist-12157',
453 'info_dict': {
454 'id': '328160',
455 'display_id': 'the-machinist',
456 'ext': 'mp4',
457 'title': 'The Machinist',
458 'description': 'md5:9a0e363fdd74b3a9e1cdd9e21d0ecc28',
459 'timestamp': 1496469720,
460 'upload_date': '20170603',
461 'duration': 5836,
462 },
463 }, {
464 'url': 'https://www.tvnow.de/filme/horst-schlaemmer-isch-kandidiere-17777',
465 'only_matching': True, # DRM protected
466 }]
467
468 def _real_extract(self, url):
469 mobj = re.match(self._VALID_URL, url)
470 display_id = mobj.group('title')
471
472 webpage = self._download_webpage(url, display_id, fatal=False)
473 if not webpage:
474 raise ExtractorError('Cannot download "%s"' % url, expected=True)
475
476 json_text = get_element_by_id('now-web-state', webpage)
477 if not json_text:
478 raise ExtractorError('Cannot read video data', expected=True)
479
480 json_data = self._parse_json(
481 json_text,
482 display_id,
483 transform_source=lambda x: x.replace('&q;', '"'),
484 fatal=False)
485 if not json_data:
486 raise ExtractorError('Cannot read video data', expected=True)
487
488 player_key = next(
489 (key for key in json_data.keys() if 'module/player' in key),
490 None)
491 page_key = next(
492 (key for key in json_data.keys() if 'page/filme' in key),
493 None)
494 movie_id = try_get(
495 json_data,
496 [
497 lambda x: x[player_key]['body']['id'],
498 lambda x: x[page_key]['body']['modules'][0]['id'],
499 lambda x: x[page_key]['body']['modules'][1]['id']],
500 int)
501 if not movie_id:
502 raise ExtractorError('Cannot extract movie ID', expected=True)
503
504 info = self._call_api('player/%d' % movie_id, display_id)
505 return self._extract_video(info, url, display_id)
de0359c0
S
506"""
507
508
509class TVNowListBaseIE(TVNowNewBaseIE):
510 _SHOW_VALID_URL = r'''(?x)
511 (?P<base_url>
512 https?://
513 (?:www\.)?tvnow\.(?:de|at|ch)/(?:shows|serien)/
514 [^/?#&]+-(?P<show_id>\d+)
515 )
516 '''
517
518 @classmethod
519 def suitable(cls, url):
520 return (False if TVNowNewIE.suitable(url)
521 else super(TVNowListBaseIE, cls).suitable(url))
522
523 def _extract_items(self, url, show_id, list_id, query):
524 items = self._call_api(
525 'teaserrow/format/episode/' + show_id, list_id,
526 query=query)['items']
23b6e230
RA
527
528 entries = []
de0359c0
S
529 for item in items:
530 if not isinstance(item, dict):
531 continue
532 item_url = urljoin(url, item.get('url'))
533 if not item_url:
534 continue
535 video_id = str_or_none(item.get('id') or item.get('videoId'))
536 item_title = item.get('subheadline') or item.get('text')
537 entries.append(self.url_result(
538 item_url, ie=TVNowNewIE.ie_key(), video_id=video_id,
539 video_title=item_title))
23b6e230 540
de0359c0 541 return self.playlist_result(entries, '%s/%s' % (show_id, list_id))
3acae1e0
A
542
543
de0359c0
S
544class TVNowSeasonIE(TVNowListBaseIE):
545 _VALID_URL = r'%s/staffel-(?P<id>\d+)' % TVNowListBaseIE._SHOW_VALID_URL
546 _TESTS = [{
547 'url': 'https://www.tvnow.de/serien/alarm-fuer-cobra-11-die-autobahnpolizei-1815/staffel-13',
548 'info_dict': {
549 'id': '1815/13',
550 },
551 'playlist_mincount': 22,
552 }]
553
554 def _real_extract(self, url):
555 _, show_id, season_id = re.match(self._VALID_URL, url).groups()
556 return self._extract_items(
557 url, show_id, season_id, {'season': season_id})
3acae1e0 558
3acae1e0 559
de0359c0
S
560class TVNowAnnualIE(TVNowListBaseIE):
561 _VALID_URL = r'%s/(?P<year>\d{4})-(?P<month>\d{2})' % TVNowListBaseIE._SHOW_VALID_URL
3acae1e0 562 _TESTS = [{
de0359c0 563 'url': 'https://www.tvnow.de/shows/grip-das-motormagazin-1669/2017-05',
ea6679fb 564 'info_dict': {
de0359c0 565 'id': '1669/2017-05',
ea6679fb 566 },
de0359c0
S
567 'playlist_mincount': 2,
568 }]
569
570 def _real_extract(self, url):
571 _, show_id, year, month = re.match(self._VALID_URL, url).groups()
572 return self._extract_items(
573 url, show_id, '%s-%s' % (year, month), {
574 'year': int(year),
575 'month': int(month),
576 })
577
578
579class TVNowShowIE(TVNowListBaseIE):
580 _VALID_URL = TVNowListBaseIE._SHOW_VALID_URL
581 _TESTS = [{
582 # annual navigationType
583 'url': 'https://www.tvnow.de/shows/grip-das-motormagazin-1669',
584 'info_dict': {
585 'id': '1669',
586 },
587 'playlist_mincount': 73,
ea6679fb 588 }, {
de0359c0
S
589 # season navigationType
590 'url': 'https://www.tvnow.de/shows/armes-deutschland-11471',
591 'info_dict': {
592 'id': '11471',
593 },
594 'playlist_mincount': 3,
3acae1e0
A
595 }]
596
597 @classmethod
598 def suitable(cls, url):
de0359c0 599 return (False if TVNowNewIE.suitable(url) or TVNowSeasonIE.suitable(url) or TVNowAnnualIE.suitable(url)
ea6679fb 600 else super(TVNowShowIE, cls).suitable(url))
3acae1e0
A
601
602 def _real_extract(self, url):
603 base_url, show_id = re.match(self._VALID_URL, url).groups()
604
de0359c0
S
605 result = self._call_api(
606 'teaserrow/format/navigation/' + show_id, show_id)
607
608 items = result['items']
3acae1e0
A
609
610 entries = []
de0359c0
S
611 navigation = result.get('navigationType')
612 if navigation == 'annual':
613 for item in items:
614 if not isinstance(item, dict):
615 continue
616 year = int_or_none(item.get('year'))
617 if year is None:
618 continue
619 months = item.get('months')
620 if not isinstance(months, list):
621 continue
622 for month_dict in months:
623 if not isinstance(month_dict, dict) or not month_dict:
624 continue
625 month_number = int_or_none(list(month_dict.keys())[0])
626 if month_number is None:
627 continue
628 entries.append(self.url_result(
629 '%s/%04d-%02d' % (base_url, year, month_number),
630 ie=TVNowAnnualIE.ie_key()))
631 elif navigation == 'season':
632 for item in items:
633 if not isinstance(item, dict):
634 continue
635 season_number = int_or_none(item.get('season'))
636 if season_number is None:
637 continue
638 entries.append(self.url_result(
639 '%s/staffel-%d' % (base_url, season_number),
640 ie=TVNowSeasonIE.ie_key()))
641 else:
642 raise ExtractorError('Unknown navigationType')
3acae1e0 643
de0359c0 644 return self.playlist_result(entries, show_id)