# coding: utf-8 from __future__ import unicode_literals import re from .common import InfoExtractor from ..utils import ( clean_html, extract_attributes, int_or_none, NO_DEFAULT, unescapeHTML, ) from ..playwright import PlaywrightHelper class TVN24IE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?(?P(?:(?:[^/]+)\.)?tvn24\.pl)/(?:[^/]+/)*[^/?#\s]+[,-](?P\d+)(?:\.html)?' _TESTS = [{ 'url': 'https://tvn24.pl/polska/edyta-gorniak-napisala-o-statystach-w-szpitalach-udajacych-chorych-na-covid-19-jerzy-polaczek-i-marek-posobkiewicz-odpowiadaja-zapraszamy-4747899', 'info_dict': { 'id': '4744453', 'ext': 'm3u8', 'title': '"Nie wszyscy \'statyści\' wychodzą na własnych nogach". Chorzy na COVID-19 odpowiadają Edycie Górniak', 'description': 'md5:aa98c393df243a69203cfb6769b8db51', } }, { # different layout 'url': 'https://tvnmeteo.tvn24.pl/magazyny/maja-w-ogrodzie,13/odcinki-online,1,4,1,0/pnacza-ptaki-i-iglaki-odc-691-hgtv-odc-29,1771763.html', 'info_dict': { 'id': '1771763', 'ext': 'mp4', 'title': 'Pnącza, ptaki i iglaki (odc. 691 /HGTV odc. 29)', 'thumbnail': 're:https?://.*', }, 'params': { 'skip_download': True, }, }, { 'url': 'https://tvn24.pl/magazyn-tvn24/zrobimy-z-ciebie-mezczyzne,242,4189', 'info_dict': { 'id': '4189', 'title': 'Zrobimy z ciebie mężczyznę', 'description': 'Milo nie miało myśli erotycznych. Tak boleśnie myślało o własnym ciele, że nie potrafiło myśleć o nim w towarzystwie innych ciał. Ale żeby zmienić ciało, m...', }, 'playlist_count': 2, }, { 'url': 'http://fakty.tvn24.pl/ogladaj-online,60/53-konferencja-bezpieczenstwa-w-monachium,716431.html', 'only_matching': True, }, { 'url': 'http://sport.tvn24.pl/pilka-nozna,105/ligue-1-kamil-glik-rozcial-glowe-monaco-tylko-remisuje-z-bastia,716522.html', 'only_matching': True, }, { 'url': 'https://www.tvn24.pl/magazyn-tvn24/angie-w-jednej-czwartej-polka-od-szarej-myszki-do-cesarzowej-europy,119,2158', 'only_matching': True, }] _REQUIRES_PLAYWRIGHT = True def _real_extract(self, url): mobj = re.match(self._VALID_URL, url) domain, display_id = mobj.group('domain', 'id') if '/magazyn-tvn24/' in url: return self._handle_magazine_frontend(url, display_id) elif domain in ('tvn24.pl', ): return self._handle_nextjs_frontend(url, display_id) else: return self._handle_old_frontend(url, display_id) def _handle_old_frontend(self, url, display_id): webpage = self._download_webpage(url, display_id) title = self._og_search_title( webpage, default=None) or self._search_regex( r']+class=["\']magazineItemHeader[^>]+>(.+?)(?!\1).+?)\1' % attr, webpage, name, group='json', default=default, fatal=fatal) or '{}', display_id, transform_source=unescapeHTML, fatal=fatal) quality_data = extract_json('data-quality', 'formats') formats = [] for format_id, url in quality_data.items(): formats.append({ 'url': url, 'format_id': format_id, 'height': int_or_none(format_id.rstrip('p')), }) self._sort_formats(formats) description = self._og_search_description(webpage, default=None) thumbnail = self._og_search_thumbnail( webpage, default=None) or self._html_search_regex( r'\bdata-poster=(["\'])(?P(?!\1).+?)\1', webpage, 'thumbnail', group='url') video_id = None share_params = extract_json( 'data-share-params', 'share params', default=None) if isinstance(share_params, dict): video_id = share_params.get('id') if not video_id: video_id = self._search_regex( r'data-vid-id=["\'](\d+)', webpage, 'video id', default=None) or self._search_regex( r',(\d+)\.html', url, 'video id', default=display_id) return { 'id': video_id, 'title': title, 'description': description, 'thumbnail': thumbnail, 'formats': formats, } def _handle_magazine_frontend(self, url, display_id): webpage = self._download_webpage(url, display_id) entries = [] for vid_el in re.finditer(r'(?P