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.

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