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.

168 lines
5.6 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 ..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 RutubeEmbedIE(InfoExtractor):
  62. IE_NAME = 'rutube:embed'
  63. IE_DESC = 'Rutube embedded videos'
  64. _VALID_URL = 'https?://rutube\.ru/video/embed/(?P<id>[0-9]+)'
  65. _TEST = {
  66. 'url': 'http://rutube.ru/video/embed/6722881?vk_puid37=&vk_puid38=',
  67. 'info_dict': {
  68. 'id': 'a10e53b86e8f349080f718582ce4c661',
  69. 'ext': 'mp4',
  70. 'upload_date': '20131223',
  71. 'uploader_id': '297833',
  72. 'description': 'Видео группы ★http://vk.com/foxkidsreset★ музей Fox Kids и Jetix<br/><br/> восстановлено и сделано в шикоформате subziro89 http://vk.com/subziro89',
  73. 'uploader': 'subziro89 ILya',
  74. 'title': 'Мистический городок Эйри в Индиан 5 серия озвучка subziro89',
  75. },
  76. 'params': {
  77. 'skip_download': 'Requires ffmpeg',
  78. },
  79. }
  80. def _real_extract(self, url):
  81. embed_id = self._match_id(url)
  82. webpage = self._download_webpage(url, embed_id)
  83. canonical_url = self._html_search_regex(
  84. r'<link\s+rel="canonical"\s+href="([^"]+?)"', webpage,
  85. 'Canonical URL')
  86. return self.url_result(canonical_url, 'Rutube')
  87. class RutubeChannelIE(InfoExtractor):
  88. IE_NAME = 'rutube:channel'
  89. IE_DESC = 'Rutube channels'
  90. _VALID_URL = r'http://rutube\.ru/tags/video/(?P<id>\d+)'
  91. _TESTS = [{
  92. 'url': 'http://rutube.ru/tags/video/1800/',
  93. 'info_dict': {
  94. 'id': '1800',
  95. },
  96. 'playlist_mincount': 68,
  97. }]
  98. _PAGE_TEMPLATE = 'http://rutube.ru/api/tags/video/%s/?page=%s&format=json'
  99. def _extract_videos(self, channel_id, channel_title=None):
  100. entries = []
  101. for pagenum in itertools.count(1):
  102. page = self._download_json(
  103. self._PAGE_TEMPLATE % (channel_id, pagenum),
  104. channel_id, 'Downloading page %s' % pagenum)
  105. results = page['results']
  106. if not results:
  107. break
  108. entries.extend(self.url_result(result['video_url'], 'Rutube') for result in results)
  109. if not page['has_next']:
  110. break
  111. return self.playlist_result(entries, channel_id, channel_title)
  112. def _real_extract(self, url):
  113. mobj = re.match(self._VALID_URL, url)
  114. channel_id = mobj.group('id')
  115. return self._extract_videos(channel_id)
  116. class RutubeMovieIE(RutubeChannelIE):
  117. IE_NAME = 'rutube:movie'
  118. IE_DESC = 'Rutube movies'
  119. _VALID_URL = r'http://rutube\.ru/metainfo/tv/(?P<id>\d+)'
  120. _TESTS = []
  121. _MOVIE_TEMPLATE = 'http://rutube.ru/api/metainfo/tv/%s/?format=json'
  122. _PAGE_TEMPLATE = 'http://rutube.ru/api/metainfo/tv/%s/video?page=%s&format=json'
  123. def _real_extract(self, url):
  124. movie_id = self._match_id(url)
  125. movie = self._download_json(
  126. self._MOVIE_TEMPLATE % movie_id, movie_id,
  127. 'Downloading movie JSON')
  128. movie_name = movie['name']
  129. return self._extract_videos(movie_id, movie_name)
  130. class RutubePersonIE(RutubeChannelIE):
  131. IE_NAME = 'rutube:person'
  132. IE_DESC = 'Rutube person videos'
  133. _VALID_URL = r'http://rutube\.ru/video/person/(?P<id>\d+)'
  134. _TESTS = [{
  135. 'url': 'http://rutube.ru/video/person/313878/',
  136. 'info_dict': {
  137. 'id': '313878',
  138. },
  139. 'playlist_mincount': 37,
  140. }]
  141. _PAGE_TEMPLATE = 'http://rutube.ru/api/video/person/%s/?page=%s&format=json'