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.

101 lines
3.4 KiB

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