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.

137 lines
4.4 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import itertools
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_str,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. unified_strdate,
  12. )
  13. class RutubeIE(InfoExtractor):
  14. IE_NAME = 'rutube'
  15. IE_DESC = 'Rutube videos'
  16. _VALID_URL = r'https?://rutube\.ru/video/(?P<id>[\da-z]{32})'
  17. _TEST = {
  18. 'url': 'http://rutube.ru/video/3eac3b4561676c17df9132a9a1e62e3e/',
  19. 'info_dict': {
  20. 'id': '3eac3b4561676c17df9132a9a1e62e3e',
  21. 'ext': 'mp4',
  22. 'title': 'Раненный кенгуру забежал в аптеку',
  23. 'description': 'http://www.ntdtv.ru ',
  24. 'duration': 80,
  25. 'uploader': 'NTDRussian',
  26. 'uploader_id': '29790',
  27. 'upload_date': '20131016',
  28. },
  29. 'params': {
  30. # It requires ffmpeg (m3u8 download)
  31. 'skip_download': True,
  32. },
  33. }
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url)
  36. video = self._download_json(
  37. 'http://rutube.ru/api/video/%s/?format=json' % video_id,
  38. video_id, 'Downloading video JSON')
  39. # Some videos don't have the author field
  40. author = video.get('author') or {}
  41. options = self._download_json(
  42. 'http://rutube.ru/api/play/options/%s/?format=json' % video_id,
  43. video_id, 'Downloading options JSON')
  44. m3u8_url = options['video_balancer'].get('m3u8')
  45. if m3u8_url is None:
  46. raise ExtractorError('Couldn\'t find m3u8 manifest url')
  47. formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
  48. return {
  49. 'id': video['id'],
  50. 'title': video['title'],
  51. 'description': video['description'],
  52. 'duration': video['duration'],
  53. 'view_count': video['hits'],
  54. 'formats': formats,
  55. 'thumbnail': video['thumbnail_url'],
  56. 'uploader': author.get('name'),
  57. 'uploader_id': compat_str(author['id']) if author else None,
  58. 'upload_date': unified_strdate(video['created_ts']),
  59. 'age_limit': 18 if video['is_adult'] else 0,
  60. }
  61. class RutubeChannelIE(InfoExtractor):
  62. IE_NAME = 'rutube:channel'
  63. IE_DESC = 'Rutube channels'
  64. _VALID_URL = r'http://rutube\.ru/tags/video/(?P<id>\d+)'
  65. _TESTS = [{
  66. 'url': 'http://rutube.ru/tags/video/1800/',
  67. 'info_dict': {
  68. 'id': '1800',
  69. },
  70. 'playlist_mincount': 68,
  71. }]
  72. _PAGE_TEMPLATE = 'http://rutube.ru/api/tags/video/%s/?page=%s&format=json'
  73. def _extract_videos(self, channel_id, channel_title=None):
  74. entries = []
  75. for pagenum in itertools.count(1):
  76. page = self._download_json(
  77. self._PAGE_TEMPLATE % (channel_id, pagenum),
  78. channel_id, 'Downloading page %s' % pagenum)
  79. results = page['results']
  80. if not results:
  81. break
  82. entries.extend(self.url_result(result['video_url'], 'Rutube') for result in results)
  83. if not page['has_next']:
  84. break
  85. return self.playlist_result(entries, channel_id, channel_title)
  86. def _real_extract(self, url):
  87. mobj = re.match(self._VALID_URL, url)
  88. channel_id = mobj.group('id')
  89. return self._extract_videos(channel_id)
  90. class RutubeMovieIE(RutubeChannelIE):
  91. IE_NAME = 'rutube:movie'
  92. IE_DESC = 'Rutube movies'
  93. _VALID_URL = r'http://rutube\.ru/metainfo/tv/(?P<id>\d+)'
  94. _TESTS = []
  95. _MOVIE_TEMPLATE = 'http://rutube.ru/api/metainfo/tv/%s/?format=json'
  96. _PAGE_TEMPLATE = 'http://rutube.ru/api/metainfo/tv/%s/video?page=%s&format=json'
  97. def _real_extract(self, url):
  98. movie_id = self._match_id(url)
  99. movie = self._download_json(
  100. self._MOVIE_TEMPLATE % movie_id, movie_id,
  101. 'Downloading movie JSON')
  102. movie_name = movie['name']
  103. return self._extract_videos(movie_id, movie_name)
  104. class RutubePersonIE(RutubeChannelIE):
  105. IE_NAME = 'rutube:person'
  106. IE_DESC = 'Rutube person videos'
  107. _VALID_URL = r'http://rutube\.ru/video/person/(?P<id>\d+)'
  108. _TESTS = [{
  109. 'url': 'http://rutube.ru/video/person/313878/',
  110. 'info_dict': {
  111. 'id': '313878',
  112. },
  113. 'playlist_mincount': 37,
  114. }]
  115. _PAGE_TEMPLATE = 'http://rutube.ru/api/video/person/%s/?page=%s&format=json'