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.

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