tvigle.py 3.8 KB

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