You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.6 KiB

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