tvp.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. import itertools
  2. import random
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. clean_html,
  7. determine_ext,
  8. dict_get,
  9. ExtractorError,
  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='Downloading page #%d' % 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\.tvp\.pl/(?:\?(?:[^&]+[&;])*channel_id=)?)(?P<id>\d*)'
  253. _TESTS = [{
  254. # untestable as "video" id changes many times across a day
  255. 'url': 'https://tvpstream.vod.tvp.pl/?channel_id=1455',
  256. 'only_matching': True,
  257. }, {
  258. 'url': 'tvpstream:39821455',
  259. 'only_matching': True,
  260. }, {
  261. # the default stream when you provide no channel_id, most probably TVP Info
  262. 'url': 'tvpstream:',
  263. 'only_matching': True,
  264. }, {
  265. 'url': 'https://tvpstream.vod.tvp.pl/',
  266. 'only_matching': True,
  267. }]
  268. _PLAYER_BOX_RE = r'<div\s[^>]*id\s*=\s*["\']?tvp_player_box["\']?[^>]+data-%s-id\s*=\s*["\']?(\d+)'
  269. _BUTTON_RE = r'<div\s[^>]*data-channel-id=["\']?%s["\']?[^>]*\sdata-title=(?:"([^"]*)"|\'([^\']*)\')[^>]*\sdata-stationname=(?:"([^"]*)"|\'([^\']*)\')'
  270. def _real_extract(self, url):
  271. channel_id = self._match_id(url)
  272. channel_url = self._proto_relative_url('//tvpstream.vod.tvp.pl/?channel_id=%s' % channel_id or 'default')
  273. webpage = self._download_webpage(channel_url, channel_id, 'Downloading channel webpage')
  274. if not channel_id:
  275. channel_id = self._search_regex(self._PLAYER_BOX_RE % 'channel',
  276. webpage, 'default channel id')
  277. video_id = self._search_regex(self._PLAYER_BOX_RE % 'video',
  278. webpage, 'video id')
  279. audition_title, station_name = self._search_regex(
  280. self._BUTTON_RE % (re.escape(channel_id)), webpage,
  281. 'audition title and station name',
  282. group=(1, 2))
  283. return {
  284. '_type': 'url_transparent',
  285. 'id': channel_id,
  286. 'url': 'tvp:%s' % video_id,
  287. 'title': audition_title,
  288. 'alt_title': station_name,
  289. 'is_live': True,
  290. 'ie_key': 'TVPEmbed',
  291. }
  292. class TVPEmbedIE(InfoExtractor):
  293. IE_NAME = 'tvp:embed'
  294. IE_DESC = 'Telewizja Polska'
  295. _GEO_BYPASS = False
  296. _VALID_URL = r'''(?x)
  297. (?:
  298. tvp:
  299. |https?://
  300. (?:[^/]+\.)?
  301. (?:tvp(?:parlament)?\.pl|tvp\.info|tvpworld\.com|swipeto\.pl)/
  302. (?:sess/
  303. (?:tvplayer\.php\?.*?object_id
  304. |TVPlayer2/(?:embed|api)\.php\?.*[Ii][Dd])
  305. |shared/details\.php\?.*?object_id)
  306. =)
  307. (?P<id>\d+)
  308. '''
  309. _EMBED_REGEX = [rf'(?x)<iframe[^>]+?src=(["\'])(?P<url>{_VALID_URL[4:]})']
  310. _TESTS = [{
  311. 'url': 'tvp:194536',
  312. 'info_dict': {
  313. 'id': '194536',
  314. 'ext': 'mp4',
  315. 'title': 'Czas honoru, odc. 13 – Władek',
  316. 'description': 'md5:76649d2014f65c99477be17f23a4dead',
  317. 'age_limit': 12,
  318. 'duration': 2652,
  319. 'series': 'Czas honoru',
  320. 'episode': 'Episode 13',
  321. 'episode_number': 13,
  322. 'season': 'sezon 1',
  323. 'thumbnail': r're:https://.+',
  324. },
  325. }, {
  326. 'url': 'https://www.tvp.pl/sess/tvplayer.php?object_id=51247504&amp;autoplay=false',
  327. 'info_dict': {
  328. 'id': '51247504',
  329. 'ext': 'mp4',
  330. 'title': 'Razmova 091220',
  331. 'duration': 876,
  332. 'age_limit': 0,
  333. 'thumbnail': r're:https://.+',
  334. },
  335. }, {
  336. # TVPlayer2 embed URL
  337. 'url': 'https://tvp.info/sess/TVPlayer2/embed.php?ID=50595757',
  338. 'only_matching': True,
  339. }, {
  340. 'url': 'https://wiadomosci.tvp.pl/sess/TVPlayer2/api.php?id=51233452',
  341. 'only_matching': True,
  342. }, {
  343. # pulsembed on dziennik.pl
  344. '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',
  345. 'only_matching': True,
  346. }]
  347. def _real_extract(self, url):
  348. video_id = self._match_id(url)
  349. # it could be anything that is a valid JS function name
  350. callback = random.choice((
  351. 'jebac_pis',
  352. 'jebacpis',
  353. 'ziobro',
  354. 'sasin70',
  355. 'sasin_przejebal_70_milionow_PLN',
  356. 'tvp_is_a_state_propaganda_service',
  357. ))
  358. webpage = self._download_webpage(
  359. ('https://www.tvp.pl/sess/TVPlayer2/api.php?id=%s'
  360. + '&@method=getTvpConfig&@callback=%s') % (video_id, callback), video_id)
  361. # stripping JSONP padding
  362. datastr = webpage[15 + len(callback):-3]
  363. if datastr.startswith('null,'):
  364. error = self._parse_json(datastr[5:], video_id, fatal=False)
  365. error_desc = traverse_obj(error, (0, 'desc'))
  366. if error_desc == 'Obiekt wymaga płatności':
  367. raise ExtractorError('Video requires payment and log-in, but log-in is not implemented')
  368. raise ExtractorError(error_desc or 'unexpected JSON error')
  369. content = self._parse_json(datastr, video_id)['content']
  370. info = content['info']
  371. is_live = try_get(info, lambda x: x['isLive'], bool)
  372. if info.get('isGeoBlocked'):
  373. # actual country list is not provided, we just assume it's always available in PL
  374. self.raise_geo_restricted(countries=['PL'])
  375. formats = []
  376. for file in content['files']:
  377. video_url = url_or_none(file.get('url'))
  378. if not video_url:
  379. continue
  380. ext = determine_ext(video_url, None)
  381. if ext == 'm3u8':
  382. formats.extend(self._extract_m3u8_formats(video_url, video_id, m3u8_id='hls', fatal=False, live=is_live))
  383. elif ext == 'mpd':
  384. if is_live:
  385. # doesn't work with either ffmpeg or native downloader
  386. continue
  387. formats.extend(self._extract_mpd_formats(video_url, video_id, mpd_id='dash', fatal=False))
  388. elif ext == 'f4m':
  389. formats.extend(self._extract_f4m_formats(video_url, video_id, f4m_id='hds', fatal=False))
  390. elif video_url.endswith('.ism/manifest'):
  391. formats.extend(self._extract_ism_formats(video_url, video_id, ism_id='mss', fatal=False))
  392. else:
  393. formats.append({
  394. 'format_id': 'direct',
  395. 'url': video_url,
  396. 'ext': ext or file.get('type'),
  397. 'fps': int_or_none(traverse_obj(file, ('quality', 'fps'))),
  398. 'tbr': int_or_none(traverse_obj(file, ('quality', 'bitrate')), scale=1000),
  399. 'width': int_or_none(traverse_obj(file, ('quality', 'width'))),
  400. 'height': int_or_none(traverse_obj(file, ('quality', 'height'))),
  401. })
  402. title = dict_get(info, ('subtitle', 'title', 'seoTitle'))
  403. description = dict_get(info, ('description', 'seoDescription'))
  404. thumbnails = []
  405. for thumb in content.get('posters') or ():
  406. thumb_url = thumb.get('src')
  407. if not thumb_url or '{width}' in thumb_url or '{height}' in thumb_url:
  408. continue
  409. thumbnails.append({
  410. 'url': thumb.get('src'),
  411. 'width': thumb.get('width'),
  412. 'height': thumb.get('height'),
  413. })
  414. age_limit = try_get(info, lambda x: x['ageGroup']['minAge'], int)
  415. if age_limit == 1:
  416. age_limit = 0
  417. duration = try_get(info, lambda x: x['duration'], int) if not is_live else None
  418. subtitles = {}
  419. for sub in content.get('subtitles') or []:
  420. if not sub.get('url'):
  421. continue
  422. subtitles.setdefault(sub['lang'], []).append({
  423. 'url': sub['url'],
  424. 'ext': sub.get('type'),
  425. })
  426. info_dict = {
  427. 'id': video_id,
  428. 'title': title,
  429. 'description': description,
  430. 'thumbnails': thumbnails,
  431. 'age_limit': age_limit,
  432. 'is_live': is_live,
  433. 'duration': duration,
  434. 'formats': formats,
  435. 'subtitles': subtitles,
  436. }
  437. # vod.tvp.pl
  438. if info.get('vortalName') == 'vod':
  439. info_dict.update({
  440. 'title': '%s, %s' % (info.get('title'), info.get('subtitle')),
  441. 'series': info.get('title'),
  442. 'season': info.get('season'),
  443. 'episode_number': info.get('episode'),
  444. })
  445. return info_dict
  446. class TVPVODBaseIE(InfoExtractor):
  447. _API_BASE_URL = 'https://vod.tvp.pl/api/products'
  448. def _call_api(self, resource, video_id, **kwargs):
  449. return self._download_json(
  450. f'{self._API_BASE_URL}/{resource}', video_id,
  451. query={'lang': 'pl', 'platform': 'BROWSER'}, **kwargs)
  452. def _parse_video(self, video):
  453. return {
  454. '_type': 'url',
  455. 'url': 'tvp:' + video['externalUid'],
  456. 'ie_key': TVPEmbedIE.ie_key(),
  457. 'title': video.get('title'),
  458. 'description': traverse_obj(video, ('lead', 'description')),
  459. 'age_limit': int_or_none(video.get('rating')),
  460. 'duration': int_or_none(video.get('duration')),
  461. }
  462. class TVPVODVideoIE(TVPVODBaseIE):
  463. IE_NAME = 'tvp:vod'
  464. _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+)(?:\?[^#]+)?(?:#.+)?$'
  465. _TESTS = [{
  466. 'url': 'https://vod.tvp.pl/dla-dzieci,24/laboratorium-alchemika-odcinki,309338/odcinek-24,S01E24,311357',
  467. 'info_dict': {
  468. 'id': '60468609',
  469. 'ext': 'mp4',
  470. 'title': 'Laboratorium alchemika, Tusze termiczne. Jak zobaczyć niewidoczne. Odcinek 24',
  471. 'description': 'md5:1d4098d3e537092ccbac1abf49b7cd4c',
  472. 'duration': 300,
  473. 'episode_number': 24,
  474. 'episode': 'Episode 24',
  475. 'age_limit': 0,
  476. 'series': 'Laboratorium alchemika',
  477. 'thumbnail': 're:https://.+',
  478. },
  479. }, {
  480. 'url': 'https://vod.tvp.pl/filmy-dokumentalne,163/ukrainski-sluga-narodu,339667',
  481. 'info_dict': {
  482. 'id': '51640077',
  483. 'ext': 'mp4',
  484. 'title': 'Ukraiński sługa narodu, Ukraiński sługa narodu',
  485. 'series': 'Ukraiński sługa narodu',
  486. 'description': 'md5:b7940c0a8e439b0c81653a986f544ef3',
  487. 'age_limit': 12,
  488. 'episode': 'Episode 0',
  489. 'episode_number': 0,
  490. 'duration': 3051,
  491. 'thumbnail': 're:https://.+',
  492. },
  493. }]
  494. def _real_extract(self, url):
  495. video_id = self._match_id(url)
  496. return self._parse_video(self._call_api(f'vods/{video_id}', video_id))
  497. class TVPVODSeriesIE(TVPVODBaseIE):
  498. IE_NAME = 'tvp:vod:series'
  499. _VALID_URL = r'https?://vod\.tvp\.pl/[a-z\d-]+,\d+/[a-z\d-]+-odcinki,(?P<id>\d+)(?:\?[^#]+)?(?:#.+)?$'
  500. _TESTS = [{
  501. 'url': 'https://vod.tvp.pl/seriale,18/ranczo-odcinki,316445',
  502. 'info_dict': {
  503. 'id': '316445',
  504. 'title': 'Ranczo',
  505. 'age_limit': 12,
  506. 'categories': ['seriale'],
  507. },
  508. 'playlist_count': 129,
  509. }, {
  510. 'url': 'https://vod.tvp.pl/programy,88/rolnik-szuka-zony-odcinki,284514',
  511. 'only_matching': True,
  512. }, {
  513. 'url': 'https://vod.tvp.pl/dla-dzieci,24/laboratorium-alchemika-odcinki,309338',
  514. 'only_matching': True,
  515. }]
  516. def _entries(self, seasons, playlist_id):
  517. for season in seasons:
  518. episodes = self._call_api(
  519. f'vods/serials/{playlist_id}/seasons/{season["id"]}/episodes', playlist_id,
  520. note=f'Downloading episode list for {season["title"]}')
  521. yield from map(self._parse_video, episodes)
  522. def _real_extract(self, url):
  523. playlist_id = self._match_id(url)
  524. metadata = self._call_api(
  525. f'vods/serials/{playlist_id}', playlist_id,
  526. note='Downloading serial metadata')
  527. seasons = self._call_api(
  528. f'vods/serials/{playlist_id}/seasons', playlist_id,
  529. note='Downloading season list')
  530. return self.playlist_result(
  531. self._entries(seasons, playlist_id), playlist_id, strip_or_none(metadata.get('title')),
  532. clean_html(traverse_obj(metadata, ('description', 'lead'), expected_type=strip_or_none)),
  533. categories=[traverse_obj(metadata, ('mainCategory', 'name'))],
  534. age_limit=int_or_none(metadata.get('rating')),
  535. )