iprima.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import time
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. determine_ext,
  8. js_to_json,
  9. )
  10. class IPrimaIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:[^/]+)\.iprima\.cz/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  12. _GEO_BYPASS = False
  13. _TESTS = [{
  14. 'url': 'https://prima.iprima.cz/particka/92-epizoda',
  15. 'info_dict': {
  16. 'id': 'p51388',
  17. 'ext': 'mp4',
  18. 'title': 'Partička (92)',
  19. 'description': 'md5:859d53beae4609e6dd7796413f1b6cac',
  20. },
  21. 'params': {
  22. 'skip_download': True, # m3u8 download
  23. },
  24. }, {
  25. 'url': 'https://cnn.iprima.cz/videa/70-epizoda',
  26. 'info_dict': {
  27. 'id': 'p681554',
  28. 'ext': 'mp4',
  29. 'title': 'HLAVNÍ ZPRÁVY 3.5.2020',
  30. },
  31. 'params': {
  32. 'skip_download': True, # m3u8 download
  33. },
  34. }, {
  35. 'url': 'http://play.iprima.cz/particka/particka-92',
  36. 'only_matching': True,
  37. }, {
  38. # geo restricted
  39. 'url': 'http://play.iprima.cz/closer-nove-pripady/closer-nove-pripady-iv-1',
  40. 'only_matching': True,
  41. }, {
  42. # iframe api.play-backend.iprima.cz
  43. 'url': 'https://prima.iprima.cz/my-little-pony/mapa-znameni-2-2',
  44. 'only_matching': True,
  45. }, {
  46. # iframe prima.iprima.cz
  47. 'url': 'https://prima.iprima.cz/porady/jak-se-stavi-sen/rodina-rathousova-praha',
  48. 'only_matching': True,
  49. }, {
  50. 'url': 'http://www.iprima.cz/filmy/desne-rande',
  51. 'only_matching': True,
  52. }, {
  53. 'url': 'https://zoom.iprima.cz/10-nejvetsich-tajemstvi-zahad/posvatna-mista-a-stavby',
  54. 'only_matching': True,
  55. }, {
  56. 'url': 'https://krimi.iprima.cz/mraz-0/sebevrazdy',
  57. 'only_matching': True,
  58. }, {
  59. 'url': 'https://cool.iprima.cz/derava-silnice-nevadi',
  60. 'only_matching': True,
  61. }, {
  62. 'url': 'https://love.iprima.cz/laska-az-za-hrob/slib-dany-bratrovi',
  63. 'only_matching': True,
  64. }, {
  65. 'url': 'https://autosalon.iprima.cz/motorsport/7-epizoda-1',
  66. 'only_matching': True,
  67. }]
  68. def _real_extract(self, url):
  69. video_id = self._match_id(url)
  70. self._set_cookie('play.iprima.cz', 'ott_adult_confirmed', '1')
  71. webpage = self._download_webpage(url, video_id)
  72. title = self._og_search_title(
  73. webpage, default=None) or self._search_regex(
  74. r'<h1>([^<]+)', webpage, 'title')
  75. video_id = self._search_regex(
  76. (r'<iframe[^>]+\bsrc=["\'](?:https?:)?//(?:api\.play-backend\.iprima\.cz/prehravac/embedded|prima\.iprima\.cz/[^/]+/[^/]+)\?.*?\bid=(p\d+)',
  77. r'data-product="([^"]+)">',
  78. r'id=["\']player-(p\d+)"',
  79. r'playerId\s*:\s*["\']player-(p\d+)'),
  80. webpage, 'real id')
  81. playerpage = self._download_webpage(
  82. 'http://play.iprima.cz/prehravac/init',
  83. video_id, note='Downloading player', query={
  84. '_infuse': 1,
  85. '_ts': round(time.time()),
  86. 'productId': video_id,
  87. }, headers={'Referer': url})
  88. formats = []
  89. def extract_formats(format_url, format_key=None, lang=None):
  90. ext = determine_ext(format_url)
  91. new_formats = []
  92. if format_key == 'hls' or ext == 'm3u8':
  93. new_formats = self._extract_m3u8_formats(
  94. format_url, video_id, 'mp4', entry_protocol='m3u8_native',
  95. m3u8_id='hls', fatal=False)
  96. elif format_key == 'dash' or ext == 'mpd':
  97. return
  98. new_formats = self._extract_mpd_formats(
  99. format_url, video_id, mpd_id='dash', fatal=False)
  100. if lang:
  101. for f in new_formats:
  102. if not f.get('language'):
  103. f['language'] = lang
  104. formats.extend(new_formats)
  105. options = self._parse_json(
  106. self._search_regex(
  107. r'(?s)(?:TDIPlayerOptions|playerOptions)\s*=\s*({.+?});\s*\]\]',
  108. playerpage, 'player options', default='{}'),
  109. video_id, transform_source=js_to_json, fatal=False)
  110. if options:
  111. for key, tracks in options.get('tracks', {}).items():
  112. if not isinstance(tracks, list):
  113. continue
  114. for track in tracks:
  115. src = track.get('src')
  116. if src:
  117. extract_formats(src, key.lower(), track.get('lang'))
  118. if not formats:
  119. for _, src in re.findall(r'src["\']\s*:\s*(["\'])(.+?)\1', playerpage):
  120. extract_formats(src)
  121. if not formats and '>GEO_IP_NOT_ALLOWED<' in playerpage:
  122. self.raise_geo_restricted(countries=['CZ'])
  123. self._sort_formats(formats)
  124. return {
  125. 'id': video_id,
  126. 'title': title,
  127. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  128. 'formats': formats,
  129. 'description': self._og_search_description(webpage, default=None),
  130. }