logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

iprima.py (5246B)


  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. r'\bvideos\s*=\s*["\'](p\d+)'),
  81. webpage, 'real id')
  82. playerpage = self._download_webpage(
  83. 'http://play.iprima.cz/prehravac/init',
  84. video_id, note='Downloading player', query={
  85. '_infuse': 1,
  86. '_ts': round(time.time()),
  87. 'productId': video_id,
  88. }, headers={'Referer': url})
  89. formats = []
  90. def extract_formats(format_url, format_key=None, lang=None):
  91. ext = determine_ext(format_url)
  92. new_formats = []
  93. if format_key == 'hls' or ext == 'm3u8':
  94. new_formats = self._extract_m3u8_formats(
  95. format_url, video_id, 'mp4', entry_protocol='m3u8_native',
  96. m3u8_id='hls', fatal=False)
  97. elif format_key == 'dash' or ext == 'mpd':
  98. return
  99. new_formats = self._extract_mpd_formats(
  100. format_url, video_id, mpd_id='dash', fatal=False)
  101. if lang:
  102. for f in new_formats:
  103. if not f.get('language'):
  104. f['language'] = lang
  105. formats.extend(new_formats)
  106. options = self._parse_json(
  107. self._search_regex(
  108. r'(?s)(?:TDIPlayerOptions|playerOptions)\s*=\s*({.+?});\s*\]\]',
  109. playerpage, 'player options', default='{}'),
  110. video_id, transform_source=js_to_json, fatal=False)
  111. if options:
  112. for key, tracks in options.get('tracks', {}).items():
  113. if not isinstance(tracks, list):
  114. continue
  115. for track in tracks:
  116. src = track.get('src')
  117. if src:
  118. extract_formats(src, key.lower(), track.get('lang'))
  119. if not formats:
  120. for _, src in re.findall(r'src["\']\s*:\s*(["\'])(.+?)\1', playerpage):
  121. extract_formats(src)
  122. if not formats and '>GEO_IP_NOT_ALLOWED<' in playerpage:
  123. self.raise_geo_restricted(countries=['CZ'])
  124. self._sort_formats(formats)
  125. return {
  126. 'id': video_id,
  127. 'title': title,
  128. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  129. 'formats': formats,
  130. 'description': self._og_search_description(webpage, default=None),
  131. }