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.

119 lines
4.1 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. float_or_none,
  8. int_or_none,
  9. parse_age_limit,
  10. )
  11. class TvigleIE(InfoExtractor):
  12. IE_NAME = 'tvigle'
  13. IE_DESC = 'Интернет-телевидение Tvigle.ru'
  14. _VALID_URL = r'https?://(?:www\.)?(?:tvigle\.ru/(?:[^/]+/)+(?P<display_id>[^/]+)/$|cloud\.tvigle\.ru/video/(?P<id>\d+))'
  15. _GEO_BYPASS = False
  16. _GEO_COUNTRIES = ['RU']
  17. _TESTS = [
  18. {
  19. 'url': 'http://www.tvigle.ru/video/sokrat/',
  20. 'md5': '36514aed3657d4f70b4b2cef8eb520cd',
  21. 'info_dict': {
  22. 'id': '1848932',
  23. 'display_id': 'sokrat',
  24. 'ext': 'flv',
  25. 'title': 'Сократ',
  26. 'description': 'md5:d6b92ffb7217b4b8ebad2e7665253c17',
  27. 'duration': 6586,
  28. 'age_limit': 12,
  29. },
  30. 'skip': 'georestricted',
  31. },
  32. {
  33. 'url': 'http://www.tvigle.ru/video/vladimir-vysotskii/vedushchii-teleprogrammy-60-minut-ssha-o-vladimire-vysotskom/',
  34. 'md5': 'e7efe5350dd5011d0de6550b53c3ba7b',
  35. 'info_dict': {
  36. 'id': '5142516',
  37. 'ext': 'flv',
  38. 'title': 'Ведущий телепрограммы «60 минут» (США) о Владимире Высоцком',
  39. 'description': 'md5:027f7dc872948f14c96d19b4178428a4',
  40. 'duration': 186.080,
  41. 'age_limit': 0,
  42. },
  43. 'skip': 'georestricted',
  44. }, {
  45. 'url': 'https://cloud.tvigle.ru/video/5267604/',
  46. 'only_matching': True,
  47. }
  48. ]
  49. def _real_extract(self, url):
  50. mobj = re.match(self._VALID_URL, url)
  51. video_id = mobj.group('id')
  52. display_id = mobj.group('display_id')
  53. if not video_id:
  54. webpage = self._download_webpage(url, display_id)
  55. video_id = self._html_search_regex(
  56. (r'<div[^>]+class=["\']player["\'][^>]+id=["\'](\d+)',
  57. r'var\s+cloudId\s*=\s*["\'](\d+)',
  58. r'class="video-preview current_playing" id="(\d+)"'),
  59. webpage, 'video id')
  60. video_data = self._download_json(
  61. 'http://cloud.tvigle.ru/api/play/video/%s/' % video_id, display_id)
  62. item = video_data['playlist']['items'][0]
  63. videos = item.get('videos')
  64. error_message = item.get('errorMessage')
  65. if not videos and error_message:
  66. if item.get('isGeoBlocked') is True:
  67. self.raise_geo_restricted(
  68. msg=error_message, countries=self._GEO_COUNTRIES)
  69. else:
  70. raise ExtractorError(
  71. '%s returned error: %s' % (self.IE_NAME, error_message),
  72. expected=True)
  73. title = item['title']
  74. description = item.get('description')
  75. thumbnail = item.get('thumbnail')
  76. duration = float_or_none(item.get('durationMilliseconds'), 1000)
  77. age_limit = parse_age_limit(item.get('ageRestrictions'))
  78. formats = []
  79. for vcodec, fmts in item['videos'].items():
  80. if vcodec == 'hls':
  81. continue
  82. for format_id, video_url in fmts.items():
  83. if format_id == 'm3u8':
  84. continue
  85. height = self._search_regex(
  86. r'^(\d+)[pP]$', format_id, 'height', default=None)
  87. formats.append({
  88. 'url': video_url,
  89. 'format_id': '%s-%s' % (vcodec, format_id),
  90. 'vcodec': vcodec,
  91. 'height': int_or_none(height),
  92. 'filesize': int_or_none(item.get('video_files_size', {}).get(vcodec, {}).get(format_id)),
  93. })
  94. self._sort_formats(formats)
  95. return {
  96. 'id': video_id,
  97. 'display_id': display_id,
  98. 'title': title,
  99. 'description': description,
  100. 'thumbnail': thumbnail,
  101. 'duration': duration,
  102. 'age_limit': age_limit,
  103. 'formats': formats,
  104. }