5 from .common
import InfoExtractor
21 class TVPIE(InfoExtractor
):
23 IE_DESC
= 'Telewizja Polska'
24 _VALID_URL
= r
'https?://(?:[^/]+\.)?(?:tvp(?:parlament)?\.(?:pl|info)|tvpworld\.com|swipeto\.pl)/(?:(?!\d+/)[^/]+/)*(?P<id>\d+)'
27 # TVPlayer 2 in js wrapper
28 'url': 'https://swipeto.pl/64095316/uliczny-foxtrot-wypozyczalnia-kaset-kto-pamieta-dvdvideo',
32 'title': 'Uliczny Foxtrot — Wypożyczalnia kaset. Kto pamięta DVD-Video?',
35 'thumbnail': r
're:https://.+',
37 'expected_warnings': [
38 'Failed to download ISM manifest: HTTP Error 404: Not Found',
39 'Failed to download m3u8 information: HTTP Error 404: Not Found',
43 'url': 'https://www.tvp.pl/polska-press-video-uploader/wideo/62042351',
48 'description': 'Wideo Kamera',
51 'thumbnail': r
're:https://.+',
54 # TVPlayer 2 in iframe
55 'url': 'https://wiadomosci.tvp.pl/50725617/dzieci-na-sprzedaz-dla-homoseksualistow',
59 'title': 'Dzieci na sprzedaż dla homoseksualistów',
60 'description': 'md5:7d318eef04e55ddd9f87a8488ac7d590',
63 'thumbnail': r
're:https://.+',
66 # TVPlayer 2 in client-side rendered website (regional; window.__newsData)
67 'url': 'https://warszawa.tvp.pl/25804446/studio-yayo',
71 'title': 'Studio Yayo',
72 'upload_date': '20160616',
73 'timestamp': 1466075700,
76 'thumbnail': r
're:https://.+',
78 'skip': 'Geo-blocked outside PL',
80 # TVPlayer 2 in client-side rendered website (tvp.info; window.__videoData)
81 'url': 'https://www.tvp.info/52880236/09042021-0800',
85 'title': '09.04.2021, 08:00',
87 'thumbnail': r
're:https://.+',
89 'skip': 'Geo-blocked outside PL',
91 # client-side rendered (regional) program (playlist) page
92 'url': 'https://opole.tvp.pl/9660819/rozmowa-dnia',
95 'description': 'Od poniedziałku do piątku o 18:55',
96 'title': 'Rozmowa dnia',
98 'playlist_mincount': 1800,
100 'skip_download': True,
103 # ABC-specific video embeding
104 # moved to https://bajkowakraina.tvp.pl/wideo/50981130,teleranek,51027049,zubr,51116450
105 'url': 'https://abc.tvp.pl/48636269/zubry-odc-124',
109 'title': 'Teleranek, Żubr',
111 'skip': 'unavailable',
113 # yet another vue page
114 'url': 'https://jp2.tvp.pl/46925618/filmy',
119 'playlist_mincount': 19,
121 'url': 'http://vod.tvp.pl/seriale/obyczajowe/na-sygnale/sezon-2-27-/odc-39/17834272',
122 'only_matching': True,
124 'url': 'http://wiadomosci.tvp.pl/25169746/24052016-1200',
125 'only_matching': True,
127 'url': 'http://krakow.tvp.pl/25511623/25lecie-mck-wyjatkowe-miejsce-na-mapie-krakowa',
128 'only_matching': True,
130 'url': 'http://teleexpress.tvp.pl/25522307/wierni-wzieli-udzial-w-procesjach',
131 'only_matching': True,
133 'url': 'http://sport.tvp.pl/25522165/krychowiak-uspokaja-w-sprawie-kontuzji-dwa-tygodnie-to-maksimum',
134 'only_matching': True,
136 'url': 'http://www.tvp.info/25511919/trwa-rewolucja-wladza-zdecydowala-sie-na-pogwalcenie-konstytucji',
137 'only_matching': True,
139 'url': 'https://tvp.info/49193823/teczowe-flagi-na-pomnikach-prokuratura-wszczela-postepowanie-wieszwiecej',
140 'only_matching': True,
142 'url': 'https://www.tvpparlament.pl/retransmisje-vod/inne/wizyta-premiera-mateusza-morawieckiego-w-firmie-berotu-sp-z-oo/48857277',
143 'only_matching': True,
145 'url': 'https://tvpworld.com/48583640/tescos-polish-business-bought-by-danish-chain-netto',
146 'only_matching': True,
149 def _parse_vue_website_data(self
, webpage
, page_id
):
150 website_data
= self
._search
_regex
([
151 # website - regiony, tvp.info
152 # directory - jp2.tvp.pl
153 r
'window\.__(?:website|directory)Data\s*=\s*({(?:.|\s)+?});',
154 ], webpage
, 'website data')
157 return self
._parse
_json
(website_data
, page_id
, transform_source
=js_to_json
)
159 def _extract_vue_video(self
, video_data
, page_id
=None):
160 if isinstance(video_data
, str):
161 video_data
= self
._parse
_json
(video_data
, page_id
, transform_source
=js_to_json
)
163 image
= video_data
.get('image')
165 for thumb
in (image
if isinstance(image
, list) else [image
]):
166 thmb_url
= str_or_none(thumb
.get('url'))
171 is_website
= video_data
.get('type') == 'website'
173 url
= video_data
['url']
175 url
= 'tvp:' + str_or_none(video_data
.get('_id') or page_id
)
177 '_type': 'url_transparent',
178 'id': str_or_none(video_data
.get('_id') or page_id
),
180 'ie_key': (TVPIE
if is_website
else TVPEmbedIE
).ie_key(),
181 'title': str_or_none(video_data
.get('title')),
182 'description': str_or_none(video_data
.get('lead')),
183 'timestamp': int_or_none(video_data
.get('release_date_long')),
184 'duration': int_or_none(video_data
.get('duration')),
185 'thumbnails': thumbnails
,
188 def _handle_vuejs_page(self
, url
, webpage
, page_id
):
189 # vue client-side rendered sites (all regional pages + tvp.info)
190 video_data
= self
._search
_regex
([
191 r
'window\.__(?:news|video)Data\s*=\s*({(?:.|\s)+?})\s*;',
192 ], webpage
, 'video data', default
=None)
194 return self
._extract
_vue
_video
(video_data
, page_id
=page_id
)
196 website_data
= self
._parse
_vue
_website
_data
(webpage
, page_id
)
198 entries
= self
._vuejs
_entries
(url
, website_data
, page_id
)
203 'title': str_or_none(website_data
.get('title')),
204 'description': str_or_none(website_data
.get('lead')),
207 raise ExtractorError('Could not extract video/website data')
209 def _vuejs_entries(self
, url
, website_data
, page_id
):
211 def extract_videos(wd
):
212 if wd
.get('latestVideo'):
213 yield self
._extract
_vue
_video
(wd
['latestVideo'])
214 for video
in wd
.get('videos') or []:
215 yield self
._extract
_vue
_video
(video
)
216 for video
in wd
.get('items') or []:
217 yield self
._extract
_vue
_video
(video
)
219 yield from extract_videos(website_data
)
221 if website_data
.get('items_total_count') > website_data
.get('items_per_page'):
222 for page
in itertools
.count(2):
223 page_website_data
= self
._parse
_vue
_website
_data
(
224 self
._download
_webpage
(url
, page_id
, note
='Downloading page #%d' % page
,
225 query
={'page': page}
),
227 if not page_website_data
.get('videos') and not page_website_data
.get('items'):
229 yield from extract_videos(page_website_data
)
231 def _real_extract(self
, url
):
232 page_id
= self
._match
_id
(url
)
233 webpage
, urlh
= self
._download
_webpage
_handle
(url
, page_id
)
235 # The URL may redirect to a VOD
236 # example: https://vod.tvp.pl/48463890/wadowickie-spotkania-z-janem-pawlem-ii
237 for ie_cls
in (TVPVODSeriesIE
, TVPVODVideoIE
):
238 if ie_cls
.suitable(urlh
.url
):
239 return self
.url_result(urlh
.url
, ie
=ie_cls
.ie_key(), video_id
=page_id
)
242 r
'window\.__(?:video|news|website|directory)Data\s*=',
244 return self
._handle
_vuejs
_page
(url
, webpage
, page_id
)
246 # classic server-side rendered sites
247 video_id
= self
._search
_regex
([
248 r
'<iframe[^>]+src="[^"]*?embed\.php\?(?:[^&]+&)*ID=(\d+)',
249 r
'<iframe[^>]+src="[^"]*?object_id=(\d+)',
250 r
"object_id\s*:\s*'(\d+)'",
251 r
'data-video-id="(\d+)"',
253 # abc.tvp.pl - somehow there are more than one video IDs that seem to be the same video?
254 # the first one is referenced to as "copyid", and seems to be unused by the website
255 r
'<script>\s*tvpabc\.video\.init\(\s*\d+,\s*(\d+)\s*\)\s*</script>',
256 ], webpage
, 'video id', default
=page_id
)
258 '_type': 'url_transparent',
259 'url': 'tvp:' + video_id
,
260 'description': self
._og
_search
_description
(
261 webpage
, default
=None) or (self
._html
_search
_meta
(
262 'description', webpage
, default
=None)
263 if '//s.tvp.pl/files/portal/v' in webpage
else None),
264 'thumbnail': self
._og
_search
_thumbnail
(webpage
, default
=None),
265 'ie_key': 'TVPEmbed',
269 class TVPStreamIE(InfoExtractor
):
270 IE_NAME
= 'tvp:stream'
271 _VALID_URL
= r
'(?:tvpstream:|https?://tvpstream\.vod\.tvp\.pl/(?:\?(?:[^&]+[&;])*channel_id=)?)(?P<id>\d*)'
273 # untestable as "video" id changes many times across a day
274 'url': 'https://tvpstream.vod.tvp.pl/?channel_id=1455',
275 'only_matching': True,
277 'url': 'tvpstream:39821455',
278 'only_matching': True,
280 # the default stream when you provide no channel_id, most probably TVP Info
282 'only_matching': True,
284 'url': 'https://tvpstream.vod.tvp.pl/',
285 'only_matching': True,
288 _PLAYER_BOX_RE
= r
'<div\s[^>]*id\s*=\s*["\']?tvp_player_box
["\']?[^>]+data-%s-id\s*=\s*["\']?
(\d
+)'
289 _BUTTON_RE = r'<div\s
[^
>]*data
-channel
-id=["\']?%s["\']?
[^
>]*\sdata
-title
=(?
:"([^"]*)"|\'([^\']*)\')[^>]*\sdata-stationname=(?:"([^
"]*)"|
\'([^
\']*)\')'
291 def _real_extract(self, url):
292 channel_id = self._match_id(url)
293 channel_url = self._proto_relative_url('//tvpstream
.vod
.tvp
.pl
/?channel_id
=%s' % channel_id or 'default
')
294 webpage = self._download_webpage(channel_url, channel_id, 'Downloading channel webpage
')
296 channel_id = self._search_regex(self._PLAYER_BOX_RE % 'channel
',
297 webpage, 'default channel
id')
298 video_id = self._search_regex(self._PLAYER_BOX_RE % 'video
',
300 audition_title, station_name = self._search_regex(
301 self._BUTTON_RE % (re.escape(channel_id)), webpage,
302 'audition title
and station name
',
305 '_type
': 'url_transparent
',
307 'url
': 'tvp
:%s' % video_id,
308 'title
': audition_title,
309 'alt_title
': station_name,
311 'ie_key
': 'TVPEmbed
',
315 class TVPEmbedIE(InfoExtractor):
316 IE_NAME = 'tvp
:embed
'
317 IE_DESC = 'Telewizja Polska
'
319 _VALID_URL = r'''(?x)
324 (?:tvp(?:parlament)?\.pl|tvp\.info|tvpworld\.com|swipeto\.pl)/
326 (?:tvplayer\.php\?.*?object_id
327 |TVPlayer2/(?:embed|api)\.php\?.*[Ii][Dd])
328 |shared/details\.php\?.*?object_id)
332 _EMBED_REGEX = [rf'(?x
)<iframe
[^
>]+?src
=(["\'])(?P<url>{_VALID_URL[4:]})']
339 'title': 'Czas honoru, odc. 13 – Władek',
340 'description': 'md5:76649d2014f65c99477be17f23a4dead',
343 'series': 'Czas honoru',
344 'episode': 'Episode 13',
345 'episode_number': 13,
347 'thumbnail': r're:https://.+',
350 'url': 'https://www.tvp.pl/sess/tvplayer.php?object_id=51247504&autoplay=false',
354 'title': 'Razmova 091220',
357 'thumbnail': r're:https://.+',
360 # TVPlayer2 embed URL
361 'url': 'https://tvp.info/sess/TVPlayer2/embed.php?ID=50595757',
362 'only_matching': True,
364 'url': 'https://wiadomosci.tvp.pl/sess/TVPlayer2/api.php?id=51233452',
365 'only_matching': True,
367 # pulsembed on dziennik.pl
368 'url': 'https://www.tvp.pl/shared/details.php?copy_id=52205981&object_id=52204505&autoplay=false&is_muted=false&allowfullscreen=true&template=external-embed/video/iframe-video.html',
369 'only_matching': True,
372 def _real_extract(self, url):
373 video_id = self._match_id(url)
375 # it could be anything that is a valid JS function name
376 callback = random.choice((
381 'sasin_przejebal_70_milionow_PLN',
382 'tvp_is_a_state_propaganda_service',
385 webpage = self._download_webpage(
386 ('https://www.tvp.pl/sess/TVPlayer2/api.php?id=%s'
387 + '&@method=getTvpConfig&@callback=%s') % (video_id, callback), video_id)
389 # stripping JSONP padding
390 datastr = webpage[15 + len(callback):-3]
391 if datastr.startswith('null,'):
392 error = self._parse_json(datastr[5:], video_id, fatal=False)
393 error_desc = traverse_obj(error, (0, 'desc'))
395 if error_desc == 'Obiekt wymaga płatności':
396 raise ExtractorError('Video requires payment and log-in, but log-in is not implemented')
398 raise ExtractorError(error_desc or 'unexpected JSON error')
400 content = self._parse_json(datastr, video_id)['content']
401 info = content['info']
402 is_live = try_get(info, lambda x: x['isLive'], bool)
404 if info.get('isGeoBlocked'):
405 # actual country list is not provided, we just assume it's always available in PL
406 self.raise_geo_restricted(countries=['PL'])
409 for file in content['files']:
410 video_url = url_or_none(file.get('url'))
413 ext = determine_ext(video_url, None)
415 formats.extend(self._extract_m3u8_formats(video_url, video_id, m3u8_id='hls', fatal=False, live=is_live))
418 # doesn't work with either ffmpeg or native downloader
420 formats.extend(self._extract_mpd_formats(video_url, video_id, mpd_id='dash', fatal=False))
422 formats.extend(self._extract_f4m_formats(video_url, video_id, f4m_id='hds', fatal=False))
423 elif video_url.endswith('.ism/manifest'):
424 formats.extend(self._extract_ism_formats(video_url, video_id, ism_id='mss', fatal=False))
427 'format_id': 'direct',
429 'ext': ext or file.get('type'),
430 'fps': int_or_none(traverse_obj(file, ('quality', 'fps'))),
431 'tbr': int_or_none(traverse_obj(file, ('quality', 'bitrate')), scale=1000),
432 'width': int_or_none(traverse_obj(file, ('quality', 'width'))),
433 'height': int_or_none(traverse_obj(file, ('quality', 'height'))),
436 title = dict_get(info, ('subtitle', 'title', 'seoTitle'))
437 description = dict_get(info, ('description', 'seoDescription'))
439 for thumb in content.get('posters') or ():
440 thumb_url = thumb.get('src')
441 if not thumb_url or '{width}' in thumb_url or '{height}' in thumb_url:
444 'url': thumb.get('src'),
445 'width': thumb.get('width'),
446 'height': thumb.get('height'),
448 age_limit = try_get(info, lambda x: x['ageGroup']['minAge'], int)
451 duration = try_get(info, lambda x: x['duration'], int) if not is_live else None
454 for sub in content.get('subtitles') or []:
455 if not sub.get('url'):
457 subtitles.setdefault(sub['lang'], []).append({
459 'ext': sub.get('type'),
465 'description': description,
466 'thumbnails': thumbnails,
467 'age_limit': age_limit,
469 'duration': duration,
471 'subtitles': subtitles,
475 if info.get('vortalName') == 'vod':
477 'title': '%s, %s' % (info.get('title'), info.get('subtitle')),
478 'series': info.get('title'),
479 'season': info.get('season'),
480 'episode_number': info.get('episode'),
486 class TVPVODBaseIE(InfoExtractor):
487 _API_BASE_URL = 'https://vod.tvp.pl/api/products'
489 def _call_api(self, resource, video_id, **kwargs):
490 return self._download_json(
491 f'{self._API_BASE_URL}/{resource}', video_id,
492 query={'lang': 'pl', 'platform': 'BROWSER'}, **kwargs)
494 def _parse_video(self, video):
497 'url': 'tvp:' + video['externalUid'],
498 'ie_key': TVPEmbedIE.ie_key(),
499 'title': video.get('title'),
500 'description': traverse_obj(video, ('lead', 'description')),
501 'age_limit': int_or_none(video.get('rating')),
502 'duration': int_or_none(video.get('duration')),
506 class TVPVODVideoIE(TVPVODBaseIE):
508 _VALID_URL = r'https?://vod\.tvp\.pl/[a-z\d-]+,\d+/[a-z\d-]+(?<!-odcinki)(?:-odcinki,\d+/odcinek-\d+,S\d+E\d+)?,(?P<id>\d+)(?:\?[^#]+)?(?:#.+)?$'
511 'url': 'https://vod.tvp.pl/dla-dzieci,24/laboratorium-alchemika-odcinki,309338/odcinek-24,S01E24,311357',
515 'title': 'Laboratorium alchemika, Tusze termiczne. Jak zobaczyć niewidoczne. Odcinek 24',
516 'description': 'md5:1d4098d3e537092ccbac1abf49b7cd4c',
518 'episode_number': 24,
519 'episode': 'Episode 24',
521 'series': 'Laboratorium alchemika',
522 'thumbnail': 're:https://.+',
525 'url': 'https://vod.tvp.pl/filmy-dokumentalne,163/ukrainski-sluga-narodu,339667',
529 'title': 'Ukraiński sługa narodu, Ukraiński sługa narodu',
530 'series': 'Ukraiński sługa narodu',
531 'description': 'md5:b7940c0a8e439b0c81653a986f544ef3',
533 'episode': 'Episode 0',
536 'thumbnail': 're:https://.+',
540 def _real_extract(self, url):
541 video_id = self._match_id(url)
543 return self._parse_video(self._call_api(f'vods/{video_id}', video_id))
546 class TVPVODSeriesIE(TVPVODBaseIE):
547 IE_NAME = 'tvp:vod:series'
548 _VALID_URL = r'https?://vod\.tvp\.pl/[a-z\d-]+,\d+/[a-z\d-]+-odcinki,(?P<id>\d+)(?:\?[^#]+)?(?:#.+)?$'
551 'url': 'https://vod.tvp.pl/seriale,18/ranczo-odcinki,316445',
556 'categories': ['seriale'],
558 'playlist_count': 129,
560 'url': 'https://vod.tvp.pl/programy,88/rolnik-szuka-zony-odcinki,284514',
561 'only_matching': True,
563 'url': 'https://vod.tvp.pl/dla-dzieci,24/laboratorium-alchemika-odcinki,309338',
564 'only_matching': True,
567 def _entries(self, seasons, playlist_id):
568 for season in seasons:
569 episodes = self._call_api(
570 f'vods/serials/{playlist_id}/seasons/{season["id"]}/episodes', playlist_id,
571 note=f'Downloading episode list for {season["title"]}')
572 yield from map(self._parse_video, episodes)
574 def _real_extract(self, url):
575 playlist_id = self._match_id(url)
576 metadata = self._call_api(
577 f'vods/serials/{playlist_id}', playlist_id,
578 note='Downloading serial metadata')
579 seasons = self._call_api(
580 f'vods/serials/{playlist_id}/seasons', playlist_id,
581 note='Downloading season list')
582 return self.playlist_result(
583 self._entries(seasons, playlist_id), playlist_id, strip_or_none(metadata.get('title')),
584 clean_html(traverse_obj(metadata, ('description', 'lead'), expected_type=strip_or_none)),
585 categories=[traverse_obj(metadata, ('mainCategory', 'name'))],
586 age_limit=int_or_none(metadata.get('rating')),