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.

138 lines
4.5 KiB

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