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.

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