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.

109 lines
3.8 KiB

10 years ago
  1. # encoding: 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'class="video-preview current_playing" id="(\d+)">',
  55. webpage, 'video id')
  56. video_data = self._download_json(
  57. 'http://cloud.tvigle.ru/api/play/video/%s/' % video_id, display_id)
  58. item = video_data['playlist']['items'][0]
  59. videos = item.get('videos')
  60. error_message = item.get('errorMessage')
  61. if not videos and error_message:
  62. raise ExtractorError(
  63. '%s returned error: %s' % (self.IE_NAME, error_message), expected=True)
  64. title = item['title']
  65. description = item.get('description')
  66. thumbnail = item.get('thumbnail')
  67. duration = float_or_none(item.get('durationMilliseconds'), 1000)
  68. age_limit = parse_age_limit(item.get('ageRestrictions'))
  69. formats = []
  70. for vcodec, fmts in item['videos'].items():
  71. for format_id, video_url in fmts.items():
  72. if format_id == 'm3u8':
  73. formats.extend(self._extract_m3u8_formats(
  74. video_url, video_id, 'mp4', m3u8_id=vcodec))
  75. continue
  76. height = self._search_regex(
  77. r'^(\d+)[pP]$', format_id, 'height', default=None)
  78. formats.append({
  79. 'url': video_url,
  80. 'format_id': '%s-%s' % (vcodec, format_id),
  81. 'vcodec': vcodec,
  82. 'height': int_or_none(height),
  83. 'filesize': int_or_none(item.get('video_files_size', {}).get(vcodec, {}).get(format_id)),
  84. })
  85. self._sort_formats(formats)
  86. return {
  87. 'id': video_id,
  88. 'display_id': display_id,
  89. 'title': title,
  90. 'description': description,
  91. 'thumbnail': thumbnail,
  92. 'duration': duration,
  93. 'age_limit': age_limit,
  94. 'formats': formats,
  95. }