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.

114 lines
3.9 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?://(?:play|prima)\.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. def _real_extract(self, url):
  41. video_id = self._match_id(url)
  42. self._set_cookie('play.iprima.cz', 'ott_adult_confirmed', '1')
  43. webpage = self._download_webpage(url, video_id)
  44. video_id = self._search_regex(
  45. (r'<iframe[^>]+\bsrc=["\'](?:https?:)?//(?:api\.play-backend\.iprima\.cz/prehravac/embedded|prima\.iprima\.cz/[^/]+/[^/]+)\?.*?\bid=(p\d+)',
  46. r'data-product="([^"]+)">'),
  47. webpage, 'real id')
  48. playerpage = self._download_webpage(
  49. 'http://play.iprima.cz/prehravac/init',
  50. video_id, note='Downloading player', query={
  51. '_infuse': 1,
  52. '_ts': round(time.time()),
  53. 'productId': video_id,
  54. }, headers={'Referer': url})
  55. formats = []
  56. def extract_formats(format_url, format_key=None, lang=None):
  57. ext = determine_ext(format_url)
  58. new_formats = []
  59. if format_key == 'hls' or ext == 'm3u8':
  60. new_formats = self._extract_m3u8_formats(
  61. format_url, video_id, 'mp4', entry_protocol='m3u8_native',
  62. m3u8_id='hls', fatal=False)
  63. elif format_key == 'dash' or ext == 'mpd':
  64. return
  65. new_formats = self._extract_mpd_formats(
  66. format_url, video_id, mpd_id='dash', fatal=False)
  67. if lang:
  68. for f in new_formats:
  69. if not f.get('language'):
  70. f['language'] = lang
  71. formats.extend(new_formats)
  72. options = self._parse_json(
  73. self._search_regex(
  74. r'(?s)(?:TDIPlayerOptions|playerOptions)\s*=\s*({.+?});\s*\]\]',
  75. playerpage, 'player options', default='{}'),
  76. video_id, transform_source=js_to_json, fatal=False)
  77. if options:
  78. for key, tracks in options.get('tracks', {}).items():
  79. if not isinstance(tracks, list):
  80. continue
  81. for track in tracks:
  82. src = track.get('src')
  83. if src:
  84. extract_formats(src, key.lower(), track.get('lang'))
  85. if not formats:
  86. for _, src in re.findall(r'src["\']\s*:\s*(["\'])(.+?)\1', playerpage):
  87. extract_formats(src)
  88. if not formats and '>GEO_IP_NOT_ALLOWED<' in playerpage:
  89. self.raise_geo_restricted(countries=['CZ'])
  90. self._sort_formats(formats)
  91. return {
  92. 'id': video_id,
  93. 'title': self._og_search_title(webpage),
  94. 'thumbnail': self._og_search_thumbnail(webpage),
  95. 'formats': formats,
  96. 'description': self._og_search_description(webpage),
  97. }