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.

84 lines
2.8 KiB

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