tvp.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. import itertools
  2. import random
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. clean_html,
  8. determine_ext,
  9. dict_get,
  10. int_or_none,
  11. js_to_json,
  12. str_or_none,
  13. strip_or_none,
  14. traverse_obj,
  15. try_get,
  16. url_or_none,
  17. )
  18. class TVPIE(InfoExtractor):
  19. IE_NAME = 'tvp'
  20. IE_DESC = 'Telewizja Polska'
  21. _VALID_URL = r'https?://(?:[^/]+\.)?(?:tvp(?:parlament)?\.(?:pl|info)|tvpworld\.com|swipeto\.pl)/(?:(?!\d+/)[^/]+/)*(?P<id>\d+)(?:[/?#]|$)'
  22. _TESTS = [{
  23. # TVPlayer 2 in js wrapper
  24. 'url': 'https://swipeto.pl/64095316/uliczny-foxtrot-wypozyczalnia-kaset-kto-pamieta-dvdvideo',
  25. 'info_dict': {
  26. 'id': '64095316',
  27. 'ext': 'mp4',
  28. 'title': 'Uliczny Foxtrot — Wypożyczalnia kaset. Kto pamięta DVD-Video?',
  29. 'age_limit': 0,
  30. 'duration': 374,
  31. 'thumbnail': r're:https://.+',
  32. },
  33. 'expected_warnings': [
  34. 'Failed to download ISM manifest: HTTP Error 404: Not Found',
  35. 'Failed to download m3u8 information: HTTP Error 404: Not Found',
  36. ],
  37. }, {
  38. # TVPlayer legacy
  39. 'url': 'https://www.tvp.pl/polska-press-video-uploader/wideo/62042351',
  40. 'info_dict': {
  41. 'id': '62042351',
  42. 'ext': 'mp4',
  43. 'title': 'Wideo',
  44. 'description': 'Wideo Kamera',
  45. 'duration': 24,
  46. 'age_limit': 0,
  47. 'thumbnail': r're:https://.+',
  48. },
  49. }, {
  50. # TVPlayer 2 in iframe
  51. 'url': 'https://wiadomosci.tvp.pl/50725617/dzieci-na-sprzedaz-dla-homoseksualistow',
  52. 'info_dict': {
  53. 'id': '50725617',
  54. 'ext': 'mp4',
  55. 'title': 'Dzieci na sprzedaż dla homoseksualistów',
  56. 'description': 'md5:7d318eef04e55ddd9f87a8488ac7d590',
  57. 'age_limit': 12,
  58. 'duration': 259,
  59. 'thumbnail': r're:https://.+',
  60. },
  61. }, {
  62. # TVPlayer 2 in client-side rendered website (regional; window.__newsData)
  63. 'url': 'https://warszawa.tvp.pl/25804446/studio-yayo',
  64. 'info_dict': {
  65. 'id': '25804446',
  66. 'ext': 'mp4',
  67. 'title': 'Studio Yayo',
  68. 'upload_date': '20160616',
  69. 'timestamp': 1466075700,
  70. 'age_limit': 0,
  71. 'duration': 20,
  72. 'thumbnail': r're:https://.+',
  73. },
  74. 'skip': 'Geo-blocked outside PL',
  75. }, {
  76. # TVPlayer 2 in client-side rendered website (tvp.info; window.__videoData)
  77. 'url': 'https://www.tvp.info/52880236/09042021-0800',
  78. 'info_dict': {
  79. 'id': '52880236',
  80. 'ext': 'mp4',
  81. 'title': '09.04.2021, 08:00',
  82. 'age_limit': 0,
  83. 'thumbnail': r're:https://.+',
  84. },
  85. 'skip': 'Geo-blocked outside PL',
  86. }, {
  87. # client-side rendered (regional) program (playlist) page
  88. 'url': 'https://opole.tvp.pl/9660819/rozmowa-dnia',
  89. 'info_dict': {
  90. 'id': '9660819',
  91. 'description': 'Od poniedziałku do piątku o 18:55',
  92. 'title': 'Rozmowa dnia',
  93. },
  94. 'playlist_mincount': 1800,
  95. 'params': {
  96. 'skip_download': True,
  97. },
  98. }, {
  99. # ABC-specific video embeding
  100. # moved to https://bajkowakraina.tvp.pl/wideo/50981130,teleranek,51027049,zubr,51116450
  101. 'url': 'https://abc.tvp.pl/48636269/zubry-odc-124',
  102. 'info_dict': {
  103. 'id': '48320456',
  104. 'ext': 'mp4',
  105. 'title': 'Teleranek, Żubr',
  106. },
  107. 'skip': 'unavailable',
  108. }, {
  109. # yet another vue page
  110. 'url': 'https://jp2.tvp.pl/46925618/filmy',
  111. 'info_dict': {
  112. 'id': '46925618',
  113. 'title': 'Filmy',
  114. },
  115. 'playlist_mincount': 19,
  116. }, {
  117. 'url': 'http://vod.tvp.pl/seriale/obyczajowe/na-sygnale/sezon-2-27-/odc-39/17834272',
  118. 'only_matching': True,
  119. }, {
  120. 'url': 'http://wiadomosci.tvp.pl/25169746/24052016-1200',
  121. 'only_matching': True,
  122. }, {
  123. 'url': 'http://krakow.tvp.pl/25511623/25lecie-mck-wyjatkowe-miejsce-na-mapie-krakowa',
  124. 'only_matching': True,
  125. }, {
  126. 'url': 'http://teleexpress.tvp.pl/25522307/wierni-wzieli-udzial-w-procesjach',
  127. 'only_matching': True,
  128. }, {
  129. 'url': 'http://sport.tvp.pl/25522165/krychowiak-uspokaja-w-sprawie-kontuzji-dwa-tygodnie-to-maksimum',
  130. 'only_matching': True,
  131. }, {
  132. 'url': 'http://www.tvp.info/25511919/trwa-rewolucja-wladza-zdecydowala-sie-na-pogwalcenie-konstytucji',
  133. 'only_matching': True,
  134. }, {
  135. 'url': 'https://tvp.info/49193823/teczowe-flagi-na-pomnikach-prokuratura-wszczela-postepowanie-wieszwiecej',
  136. 'only_matching': True,
  137. }, {
  138. 'url': 'https://www.tvpparlament.pl/retransmisje-vod/inne/wizyta-premiera-mateusza-morawieckiego-w-firmie-berotu-sp-z-oo/48857277',
  139. 'only_matching': True,
  140. }, {
  141. 'url': 'https://tvpworld.com/48583640/tescos-polish-business-bought-by-danish-chain-netto',
  142. 'only_matching': True,
  143. }]
  144. def _parse_vue_website_data(self, webpage, page_id):
  145. website_data = self._search_regex([
  146. # website - regiony, tvp.info
  147. # directory - jp2.tvp.pl
  148. r'window\.__(?:website|directory)Data\s*=\s*({(?:.|\s)+?});',
  149. ], webpage, 'website data')
  150. if not website_data:
  151. return None
  152. return self._parse_json(website_data, page_id, transform_source=js_to_json)
  153. def _extract_vue_video(self, video_data, page_id=None):
  154. if isinstance(video_data, str):
  155. video_data = self._parse_json(video_data, page_id, transform_source=js_to_json)
  156. thumbnails = []
  157. image = video_data.get('image')
  158. if image:
  159. for thumb in (image if isinstance(image, list) else [image]):
  160. thmb_url = str_or_none(thumb.get('url'))
  161. if thmb_url:
  162. thumbnails.append({
  163. 'url': thmb_url,
  164. })
  165. is_website = video_data.get('type') == 'website'
  166. if is_website:
  167. url = video_data['url']
  168. else:
  169. url = 'tvp:' + str_or_none(video_data.get('_id') or page_id)
  170. return {
  171. '_type': 'url_transparent',
  172. 'id': str_or_none(video_data.get('_id') or page_id),
  173. 'url': url,
  174. 'ie_key': (TVPIE if is_website else TVPEmbedIE).ie_key(),
  175. 'title': str_or_none(video_data.get('title')),
  176. 'description': str_or_none(video_data.get('lead')),
  177. 'timestamp': int_or_none(video_data.get('release_date_long')),
  178. 'duration': int_or_none(video_data.get('duration')),
  179. 'thumbnails': thumbnails,
  180. }
  181. def _handle_vuejs_page(self, url, webpage, page_id):
  182. # vue client-side rendered sites (all regional pages + tvp.info)
  183. video_data = self._search_regex([
  184. r'window\.__(?:news|video)Data\s*=\s*({(?:.|\s)+?})\s*;',
  185. ], webpage, 'video data', default=None)
  186. if video_data:
  187. return self._extract_vue_video(video_data, page_id=page_id)
  188. # paged playlists
  189. website_data = self._parse_vue_website_data(webpage, page_id)
  190. if website_data:
  191. entries = self._vuejs_entries(url, website_data, page_id)
  192. return {
  193. '_type': 'playlist',
  194. 'id': page_id,
  195. 'title': str_or_none(website_data.get('title')),
  196. 'description': str_or_none(website_data.get('lead')),
  197. 'entries': entries,
  198. }
  199. raise ExtractorError('Could not extract video/website data')
  200. def _vuejs_entries(self, url, website_data, page_id):
  201. def extract_videos(wd):
  202. if wd.get('latestVideo'):
  203. yield self._extract_vue_video(wd['latestVideo'])
  204. for video in wd.get('videos') or []:
  205. yield self._extract_vue_video(video)
  206. for video in wd.get('items') or []:
  207. yield self._extract_vue_video(video)
  208. yield from extract_videos(website_data)
  209. if website_data.get('items_total_count') > website_data.get('items_per_page'):
  210. for page in itertools.count(2):
  211. page_website_data = self._parse_vue_website_data(
  212. self._download_webpage(url, page_id, note=f'Downloading page #{page}',
  213. query={'page': page}),
  214. page_id)
  215. if not page_website_data.get('videos') and not page_website_data.get('items'):
  216. break
  217. yield from extract_videos(page_website_data)
  218. def _real_extract(self, url):
  219. page_id = self._match_id(url)
  220. webpage, urlh = self._download_webpage_handle(url, page_id)
  221. # The URL may redirect to a VOD
  222. # example: https://vod.tvp.pl/48463890/wadowickie-spotkania-z-janem-pawlem-ii
  223. for ie_cls in (TVPVODSeriesIE, TVPVODVideoIE):
  224. if ie_cls.suitable(urlh.url):
  225. return self.url_result(urlh.url, ie=ie_cls.ie_key(), video_id=page_id)
  226. if re.search(
  227. r'window\.__(?:video|news|website|directory)Data\s*=',
  228. webpage):
  229. return self._handle_vuejs_page(url, webpage, page_id)
  230. # classic server-side rendered sites
  231. video_id = self._search_regex([
  232. r'<iframe[^>]+src="[^"]*?embed\.php\?(?:[^&]+&)*ID=(\d+)',
  233. r'<iframe[^>]+src="[^"]*?object_id=(\d+)',
  234. r"object_id\s*:\s*'(\d+)'",
  235. r'data-video-id="(\d+)"',
  236. # abc.tvp.pl - somehow there are more than one video IDs that seem to be the same video?
  237. # the first one is referenced to as "copyid", and seems to be unused by the website
  238. r'<script>\s*tvpabc\.video\.init\(\s*\d+,\s*(\d+)\s*\)\s*</script>',
  239. ], webpage, 'video id', default=page_id)
  240. return {
  241. '_type': 'url_transparent',
  242. 'url': 'tvp:' + video_id,
  243. 'description': self._og_search_description(
  244. webpage, default=None) or (self._html_search_meta(
  245. 'description', webpage, default=None)
  246. if '//s.tvp.pl/files/portal/v' in webpage else None),
  247. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  248. 'ie_key': 'TVPEmbed',
  249. }
  250. class TVPStreamIE(InfoExtractor):
  251. IE_NAME = 'tvp:stream'
  252. _VALID_URL = r'(?:tvpstream:|https?://(?:tvpstream\.vod|stream)\.tvp\.pl/(?:\?(?:[^&]+[&;])*channel_id=)?)(?P<id>\d*)'
  253. _TESTS = [{
  254. 'url': 'https://stream.tvp.pl/?channel_id=56969941',
  255. 'only_matching': True,
  256. }, {
  257. # untestable as "video" id changes many times across a day
  258. 'url': 'https://tvpstream.vod.tvp.pl/?channel_id=1455',
  259. 'only_matching': True,
  260. }, {
  261. 'url': 'tvpstream:39821455',
  262. 'only_matching': True,
  263. }, {
  264. # the default stream when you provide no channel_id, most probably TVP Info
  265. 'url': 'tvpstream:',
  266. 'only_matching': True,
  267. }, {
  268. 'url': 'https://tvpstream.vod.tvp.pl/',
  269. 'only_matching': True,
  270. }]
  271. def _real_extract(self, url):
  272. channel_id = self._match_id(url)
  273. channel_url = self._proto_relative_url(f'//stream.tvp.pl/?channel_id={channel_id}' or 'default')
  274. webpage = self._download_webpage(channel_url, channel_id or 'default', 'Downloading channel webpage')
  275. channels = self._search_json(
  276. r'window\.__channels\s*=', webpage, 'channel list', channel_id,
  277. contains_pattern=r'\[\s*{(?s:.+)}\s*]')
  278. channel = traverse_obj(channels, (lambda _, v: channel_id == str(v['id'])), get_all=False) if channel_id else channels[0]
  279. audition = traverse_obj(channel, ('items', lambda _, v: v['is_live'] is True), get_all=False)
  280. return {
  281. '_type': 'url_transparent',
  282. 'id': channel_id or channel['id'],
  283. 'url': 'tvp:{}'.format(audition['video_id']),
  284. 'title': audition.get('title'),
  285. 'alt_title': channel.get('title'),
  286. 'is_live': True,
  287. 'ie_key': 'TVPEmbed',
  288. }
  289. class TVPEmbedIE(InfoExtractor):
  290. IE_NAME = 'tvp:embed'
  291. IE_DESC = 'Telewizja Polska'
  292. _GEO_BYPASS = False
  293. _VALID_URL = r'''(?x)
  294. (?:
  295. tvp:
  296. |https?://
  297. (?:[^/]+\.)?
  298. (?:tvp(?:parlament)?\.pl|tvp\.info|tvpworld\.com|swipeto\.pl)/
  299. (?:sess/
  300. (?:tvplayer\.php\?.*?object_id
  301. |TVPlayer2/(?:embed|api)\.php\?.*[Ii][Dd])
  302. |shared/details\.php\?.*?object_id)
  303. =)
  304. (?P<id>\d+)
  305. '''
  306. _EMBED_REGEX = [rf'(?x)<iframe[^>]+?src=(["\'])(?P<url>{_VALID_URL[4:]})']
  307. _TESTS = [{
  308. 'url': 'tvp:194536',
  309. 'info_dict': {
  310. 'id': '194536',
  311. 'ext': 'mp4',
  312. 'title': 'Czas honoru, odc. 13 – Władek',
  313. 'description': 'md5:76649d2014f65c99477be17f23a4dead',
  314. 'age_limit': 12,
  315. 'duration': 2652,
  316. 'series': 'Czas honoru',
  317. 'episode': 'Episode 13',
  318. 'episode_number': 13,
  319. 'season': 'sezon 1',
  320. 'thumbnail': r're:https://.+',
  321. },
  322. }, {
  323. 'url': 'https://www.tvp.pl/sess/tvplayer.php?object_id=51247504&amp;autoplay=false',
  324. 'info_dict': {
  325. 'id': '51247504',
  326. 'ext': 'mp4',
  327. 'title': 'Razmova 091220',
  328. 'duration': 876,
  329. 'age_limit': 0,
  330. 'thumbnail': r're:https://.+',
  331. },
  332. }, {
  333. # TVPlayer2 embed URL
  334. 'url': 'https://tvp.info/sess/TVPlayer2/embed.php?ID=50595757',
  335. 'only_matching': True,
  336. }, {
  337. 'url': 'https://wiadomosci.tvp.pl/sess/TVPlayer2/api.php?id=51233452',
  338. 'only_matching': True,
  339. }, {
  340. # pulsembed on dziennik.pl
  341. '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',
  342. 'only_matching': True,
  343. }]
  344. def _real_extract(self, url):
  345. video_id = self._match_id(url)
  346. # it could be anything that is a valid JS function name
  347. callback = random.choice((
  348. 'jebac_pis',
  349. 'jebacpis',
  350. 'ziobro',
  351. 'sasin70',
  352. 'sasin_przejebal_70_milionow_PLN',
  353. 'tvp_is_a_state_propaganda_service',
  354. ))
  355. webpage = self._download_webpage(
  356. f'https://www.tvp.pl/sess/TVPlayer2/api.php?id={video_id}&@method=getTvpConfig&@callback={callback}', video_id)
  357. # stripping JSONP padding
  358. datastr = webpage[15 + len(callback):-3]
  359. if datastr.startswith('null,'):
  360. error = self._parse_json(datastr[5:], video_id, fatal=False)
  361. error_desc = traverse_obj(error, (0, 'desc'))
  362. if error_desc == 'Obiekt wymaga płatności':
  363. raise ExtractorError('Video requires payment and log-in, but log-in is not implemented')
  364. raise ExtractorError(error_desc or 'unexpected JSON error')
  365. content = self._parse_json(datastr, video_id)['content']
  366. info = content['info']
  367. is_live = try_get(info, lambda x: x['isLive'], bool)
  368. if info.get('isGeoBlocked'):
  369. # actual country list is not provided, we just assume it's always available in PL
  370. self.raise_geo_restricted(countries=['PL'])
  371. formats = []
  372. for file in content['files']:
  373. video_url = url_or_none(file.get('url'))
  374. if not video_url:
  375. continue
  376. ext = determine_ext(video_url, None)
  377. if ext == 'm3u8':
  378. formats.extend(self._extract_m3u8_formats(video_url, video_id, m3u8_id='hls', fatal=False, live=is_live))
  379. elif ext == 'mpd':
  380. if is_live:
  381. # doesn't work with either ffmpeg or native downloader
  382. continue
  383. formats.extend(self._extract_mpd_formats(video_url, video_id, mpd_id='dash', fatal=False))
  384. elif ext == 'f4m':
  385. formats.extend(self._extract_f4m_formats(video_url, video_id, f4m_id='hds', fatal=False))
  386. elif video_url.endswith('.ism/manifest'):
  387. formats.extend(self._extract_ism_formats(video_url, video_id, ism_id='mss', fatal=False))
  388. else:
  389. formats.append({
  390. 'format_id': 'direct',
  391. 'url': video_url,
  392. 'ext': ext or file.get('type'),
  393. 'fps': int_or_none(traverse_obj(file, ('quality', 'fps'))),
  394. 'tbr': int_or_none(traverse_obj(file, ('quality', 'bitrate')), scale=1000),
  395. 'width': int_or_none(traverse_obj(file, ('quality', 'width'))),
  396. 'height': int_or_none(traverse_obj(file, ('quality', 'height'))),
  397. })
  398. title = dict_get(info, ('subtitle', 'title', 'seoTitle'))
  399. description = dict_get(info, ('description', 'seoDescription'))
  400. thumbnails = []
  401. for thumb in content.get('posters') or ():
  402. thumb_url = thumb.get('src')
  403. if not thumb_url or '{width}' in thumb_url or '{height}' in thumb_url:
  404. continue
  405. thumbnails.append({
  406. 'url': thumb.get('src'),
  407. 'width': thumb.get('width'),
  408. 'height': thumb.get('height'),
  409. })
  410. age_limit = try_get(info, lambda x: x['ageGroup']['minAge'], int)
  411. if age_limit == 1:
  412. age_limit = 0
  413. duration = try_get(info, lambda x: x['duration'], int) if not is_live else None
  414. subtitles = {}
  415. for sub in content.get('subtitles') or []:
  416. if not sub.get('url'):
  417. continue
  418. subtitles.setdefault(sub['lang'], []).append({
  419. 'url': sub['url'],
  420. 'ext': sub.get('type'),
  421. })
  422. info_dict = {
  423. 'id': video_id,
  424. 'title': title,
  425. 'description': description,
  426. 'thumbnails': thumbnails,
  427. 'age_limit': age_limit,
  428. 'is_live': is_live,
  429. 'duration': duration,
  430. 'formats': formats,
  431. 'subtitles': subtitles,
  432. }
  433. # vod.tvp.pl
  434. if info.get('vortalName') == 'vod':
  435. info_dict.update({
  436. 'title': '{}, {}'.format(info.get('title'), info.get('subtitle')),
  437. 'series': info.get('title'),
  438. 'season': info.get('season'),
  439. 'episode_number': info.get('episode'),
  440. })
  441. return info_dict
  442. class TVPVODBaseIE(InfoExtractor):
  443. _API_BASE_URL = 'https://vod.tvp.pl/api/products'
  444. def _call_api(self, resource, video_id, query={}, **kwargs):
  445. is_valid = lambda x: 200 <= x < 300
  446. document, urlh = self._download_json_handle(
  447. f'{self._API_BASE_URL}/{resource}', video_id,
  448. query={'lang': 'pl', 'platform': 'BROWSER', **query},
  449. expected_status=lambda x: is_valid(x) or 400 <= x < 500, **kwargs)
  450. if is_valid(urlh.status):
  451. return document
  452. raise ExtractorError(f'Woronicza said: {document.get("code")} (HTTP {urlh.status})')
  453. def _parse_video(self, video, with_url=True):
  454. info_dict = traverse_obj(video, {
  455. 'id': ('id', {str_or_none}),
  456. 'title': 'title',
  457. 'age_limit': ('rating', {int_or_none}),
  458. 'duration': ('duration', {int_or_none}),
  459. 'episode_number': ('number', {int_or_none}),
  460. 'series': ('season', 'serial', 'title', {str_or_none}),
  461. 'thumbnails': ('images', ..., ..., {'url': ('url', {url_or_none})}),
  462. })
  463. info_dict['description'] = clean_html(dict_get(video, ('lead', 'description')))
  464. if with_url:
  465. info_dict.update({
  466. '_type': 'url',
  467. 'url': video['webUrl'],
  468. 'ie_key': TVPVODVideoIE.ie_key(),
  469. })
  470. return info_dict
  471. class TVPVODVideoIE(TVPVODBaseIE):
  472. IE_NAME = 'tvp:vod'
  473. _VALID_URL = r'https?://vod\.tvp\.pl/(?P<category>[a-z\d-]+,\d+)/[a-z\d-]+(?<!-odcinki)(?:-odcinki,\d+/odcinek-\d+,S\d+E\d+)?,(?P<id>\d+)/?(?:[?#]|$)'
  474. _TESTS = [{
  475. 'url': 'https://vod.tvp.pl/dla-dzieci,24/laboratorium-alchemika-odcinki,309338/odcinek-24,S01E24,311357',
  476. 'info_dict': {
  477. 'id': '311357',
  478. 'ext': 'mp4',
  479. 'title': 'Tusze termiczne. Jak zobaczyć niewidoczne. Odcinek 24',
  480. 'description': 'md5:1d4098d3e537092ccbac1abf49b7cd4c',
  481. 'duration': 300,
  482. 'episode_number': 24,
  483. 'episode': 'Episode 24',
  484. 'age_limit': 0,
  485. 'series': 'Laboratorium alchemika',
  486. 'thumbnail': 're:https?://.+',
  487. },
  488. 'params': {'skip_download': 'm3u8'},
  489. }, {
  490. 'url': 'https://vod.tvp.pl/filmy-dokumentalne,163/ukrainski-sluga-narodu,339667',
  491. 'info_dict': {
  492. 'id': '339667',
  493. 'ext': 'mp4',
  494. 'title': 'Ukraiński sługa narodu',
  495. 'description': 'md5:b7940c0a8e439b0c81653a986f544ef3',
  496. 'age_limit': 12,
  497. 'duration': 3051,
  498. 'thumbnail': 're:https?://.+',
  499. 'subtitles': 'count:2',
  500. },
  501. 'params': {'skip_download': 'm3u8'},
  502. }, {
  503. 'note': 'embed fails with "payment required"',
  504. 'url': 'https://vod.tvp.pl/seriale,18/polowanie-na-cmy-odcinki,390116/odcinek-7,S01E07,398869',
  505. 'info_dict': {
  506. 'id': '398869',
  507. 'ext': 'mp4',
  508. 'title': 'odc. 7',
  509. 'description': 'md5:dd2bb33f023dc5c2fbaddfbe4cb5dba0',
  510. 'duration': 2750,
  511. 'age_limit': 16,
  512. 'series': 'Polowanie na ćmy',
  513. 'episode_number': 7,
  514. 'episode': 'Episode 7',
  515. 'thumbnail': 're:https?://.+',
  516. },
  517. 'params': {'skip_download': 'm3u8'},
  518. }, {
  519. 'url': 'https://vod.tvp.pl/live,1/tvp-world,399731',
  520. 'info_dict': {
  521. 'id': '399731',
  522. 'ext': 'mp4',
  523. 'title': r're:TVP WORLD \d{4}-\d{2}-\d{2} \d{2}:\d{2}',
  524. 'live_status': 'is_live',
  525. 'thumbnail': 're:https?://.+',
  526. },
  527. }]
  528. def _real_extract(self, url):
  529. category, video_id = self._match_valid_url(url).group('category', 'id')
  530. is_live = category == 'live,1'
  531. entity = 'lives' if is_live else 'vods'
  532. info_dict = self._parse_video(self._call_api(f'{entity}/{video_id}', video_id), with_url=False)
  533. playlist = self._call_api(f'{video_id}/videos/playlist', video_id, query={'videoType': 'MOVIE'})
  534. info_dict['formats'] = []
  535. for manifest_url in traverse_obj(playlist, ('sources', 'HLS', ..., 'src')):
  536. info_dict['formats'].extend(self._extract_m3u8_formats(manifest_url, video_id, fatal=False))
  537. for manifest_url in traverse_obj(playlist, ('sources', 'DASH', ..., 'src')):
  538. info_dict['formats'].extend(self._extract_mpd_formats(manifest_url, video_id, fatal=False))
  539. info_dict['subtitles'] = {}
  540. for sub in playlist.get('subtitles') or []:
  541. info_dict['subtitles'].setdefault(sub.get('language') or 'und', []).append({
  542. 'url': sub['url'],
  543. 'ext': 'ttml',
  544. })
  545. info_dict['is_live'] = is_live
  546. return info_dict
  547. class TVPVODSeriesIE(TVPVODBaseIE):
  548. IE_NAME = 'tvp:vod:series'
  549. _VALID_URL = r'https?://vod\.tvp\.pl/[a-z\d-]+,\d+/[a-z\d-]+-odcinki,(?P<id>\d+)(?:\?[^#]+)?(?:#.+)?$'
  550. _TESTS = [{
  551. 'url': 'https://vod.tvp.pl/seriale,18/ranczo-odcinki,316445',
  552. 'info_dict': {
  553. 'id': '316445',
  554. 'title': 'Ranczo',
  555. 'age_limit': 12,
  556. 'categories': ['seriale'],
  557. },
  558. 'playlist_count': 130,
  559. }, {
  560. 'url': 'https://vod.tvp.pl/programy,88/rolnik-szuka-zony-odcinki,284514',
  561. 'only_matching': True,
  562. }, {
  563. 'url': 'https://vod.tvp.pl/dla-dzieci,24/laboratorium-alchemika-odcinki,309338',
  564. 'only_matching': True,
  565. }]
  566. def _entries(self, seasons, playlist_id):
  567. for season in seasons:
  568. episodes = self._call_api(
  569. f'vods/serials/{playlist_id}/seasons/{season["id"]}/episodes', playlist_id,
  570. note=f'Downloading episode list for {season["title"]}')
  571. yield from map(self._parse_video, episodes)
  572. def _real_extract(self, url):
  573. playlist_id = self._match_id(url)
  574. metadata = self._call_api(
  575. f'vods/serials/{playlist_id}', playlist_id,
  576. note='Downloading serial metadata')
  577. seasons = self._call_api(
  578. f'vods/serials/{playlist_id}/seasons', playlist_id,
  579. note='Downloading season list')
  580. return self.playlist_result(
  581. self._entries(seasons, playlist_id), playlist_id, strip_or_none(metadata.get('title')),
  582. clean_html(traverse_obj(metadata, ('description', 'lead'), expected_type=strip_or_none)),
  583. categories=[traverse_obj(metadata, ('mainCategory', 'name'))],
  584. age_limit=int_or_none(metadata.get('rating')),
  585. )