3 from .common
import InfoExtractor
18 class RutubeBaseIE(InfoExtractor
):
19 def _download_api_info(self
, video_id
, query
=None):
22 query
['format'] = 'json'
23 return self
._download
_json
(
24 'http://rutube.ru/api/video/%s/' % video_id
,
25 video_id
, 'Downloading video JSON',
26 'Unable to download video JSON', query
=query
)
29 def _extract_info(video
, video_id
=None, require_title
=True):
30 title
= video
['title'] if require_title
else video
.get('title')
32 age_limit
= video
.get('is_adult')
33 if age_limit
is not None:
34 age_limit
= 18 if age_limit
is True else 0
36 uploader_id
= try_get(video
, lambda x
: x
['author']['id'])
37 category
= try_get(video
, lambda x
: x
['category']['name'])
40 'id': video
.get('id') or video_id
if video_id
else video
['id'],
42 'description': video
.get('description'),
43 'thumbnail': video
.get('thumbnail_url'),
44 'duration': int_or_none(video
.get('duration')),
45 'uploader': try_get(video
, lambda x
: x
['author']['name']),
46 'uploader_id': compat_str(uploader_id
) if uploader_id
else None,
47 'timestamp': unified_timestamp(video
.get('created_ts')),
48 'category': [category
] if category
else None,
49 'age_limit': age_limit
,
50 'view_count': int_or_none(video
.get('hits')),
51 'comment_count': int_or_none(video
.get('comments_count')),
52 'is_live': bool_or_none(video
.get('is_livestream')),
55 def _download_and_extract_info(self
, video_id
, query
=None):
56 return self
._extract
_info
(
57 self
._download
_api
_info
(video_id
, query
=query
), video_id
)
59 def _download_api_options(self
, video_id
, query
=None):
62 query
['format'] = 'json'
63 return self
._download
_json
(
64 'http://rutube.ru/api/play/options/%s/' % video_id
,
65 video_id
, 'Downloading options JSON',
66 'Unable to download options JSON',
67 headers
=self
.geo_verification_headers(), query
=query
)
69 def _extract_formats(self
, options
, video_id
):
71 for format_id
, format_url
in options
['video_balancer'].items():
72 ext
= determine_ext(format_url
)
74 formats
.extend(self
._extract
_m
3u8_formats
(
75 format_url
, video_id
, 'mp4', m3u8_id
=format_id
, fatal
=False))
77 formats
.extend(self
._extract
_f
4m
_formats
(
78 format_url
, video_id
, f4m_id
=format_id
, fatal
=False))
82 'format_id': format_id
,
86 def _download_and_extract_formats(self
, video_id
, query
=None):
87 return self
._extract
_formats
(
88 self
._download
_api
_options
(video_id
, query
=query
), video_id
)
91 class RutubeIE(RutubeBaseIE
):
93 IE_DESC
= 'Rutube videos'
94 _VALID_URL
= r
'https?://rutube\.ru/(?:video(?:/private)?|(?:play/)?embed)/(?P<id>[\da-z]{32})'
95 _EMBED_REGEX
= [r
'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//rutube\
.ru
/(?
:play
/)?embed
/[\da
-z
]{32}
.*?
)\
1']
98 'url
': 'http
://rutube
.ru
/video
/3eac3b4561676c17df9132a9a1e62e3e
/',
99 'md5
': 'e33ac625efca66aba86cbec9851f2692
',
101 'id': '3eac3b4561676c17df9132a9a1e62e3e
',
103 'title
': 'Раненный кенгуру забежал в аптеку
',
104 'description
': 'http
://www
.ntdtv
.ru
',
106 'uploader
': 'NTDRussian
',
107 'uploader_id
': '29790',
108 'timestamp
': 1381943602,
109 'upload_date
': '20131016',
112 'thumbnail
': 'http
://pic
.rutubelist
.ru
/video
/d2
/a0
/d2a0aec998494a396deafc7ba2c82add
.jpg
',
113 'category
': ['Новости и СМИ
'],
117 'url
': 'http
://rutube
.ru
/play
/embed
/a10e53b86e8f349080f718582ce4c661
',
118 'only_matching
': True,
120 'url
': 'http
://rutube
.ru
/embed
/a10e53b86e8f349080f718582ce4c661
',
121 'only_matching
': True,
123 'url
': 'http
://rutube
.ru
/video
/3eac3b4561676c17df9132a9a1e62e3e
/?pl_id
=4252',
124 'only_matching
': True,
126 'url
': 'https
://rutube
.ru
/video
/10b3a03fc01d5bbcc632a2f3514e8aab
/?pl_type
=source
',
127 'only_matching
': True,
129 'url
': 'https
://rutube
.ru
/video
/private
/884fb55f07a97ab673c7d654553e0f48
/?p
=x2QojCumHTS3rsKHWXN8Lg
',
130 'md5
': 'd106225f15d625538fe22971158e896f
',
132 'id': '884fb55f07a97ab673c7d654553e0f48
',
134 'title
': 'Яцуноками
, Nioh2
',
135 'description
': 'Nioh2
: финал сражения с боссом Яцуноками
',
138 'uploader_id
': '24222106',
139 'timestamp
': 1670646232,
140 'upload_date
': '20221210',
143 'thumbnail
': 'http
://pic
.rutubelist
.ru
/video
/f2
/d4
/f2d42b54be0a6e69c1c22539e3152156
.jpg
',
144 'category
': ['Видеоигры
'],
149 def suitable(cls, url):
150 return False if RutubePlaylistIE.suitable(url) else super(RutubeIE, cls).suitable(url)
152 def _real_extract(self, url):
153 video_id = self._match_id(url)
154 query = parse_qs(url)
155 info = self._download_and_extract_info(video_id, query)
156 info['formats
'] = self._download_and_extract_formats(video_id, query)
160 class RutubeEmbedIE(RutubeBaseIE):
161 IE_NAME = 'rutube
:embed
'
162 IE_DESC = 'Rutube embedded videos
'
163 _VALID_URL = r'https?
://rutube\
.ru
/(?
:video|play
)/embed
/(?P
<id>[0-9]+)'
166 'url
': 'http
://rutube
.ru
/video
/embed
/6722881?vk_puid37
=&vk_puid38
=',
168 'id': 'a10e53b86e8f349080f718582ce4c661
',
170 'timestamp
': 1387830582,
171 'upload_date
': '20131223',
172 'uploader_id
': '297833',
173 'description
': 'Видео группы ★http
://vk
.com
/foxkidsreset★ музей Fox Kids и Jetix
<br
/><br
/> восстановлено и сделано в шикоформате subziro89 http
://vk
.com
/subziro89
',
174 'uploader
': 'subziro89 ILya
',
175 'title
': 'Мистический городок Эйри в Индиан
5 серия озвучка subziro89
',
178 'skip_download
': True,
181 'url
': 'http
://rutube
.ru
/play
/embed
/8083783',
182 'only_matching
': True,
185 'url
': 'https
://rutube
.ru
/play
/embed
/10631925?p
=IbAigKqWd1do4mjaM5XLIQ
',
186 'only_matching
': True,
189 def _real_extract(self, url):
190 embed_id = self._match_id(url)
191 # Query may contain private videos token and should be passed to API
192 # requests (see #19163)
193 query = parse_qs(url)
194 options = self._download_api_options(embed_id, query)
195 video_id = options['effective_video
']
196 formats = self._extract_formats(options, video_id)
197 info = self._download_and_extract_info(video_id, query)
199 'extractor_key
': 'Rutube
',
205 class RutubePlaylistBaseIE(RutubeBaseIE):
206 def _next_page_url(self, page_num, playlist_id, *args, **kwargs):
207 return self._PAGE_TEMPLATE % (playlist_id, page_num)
209 def _entries(self, playlist_id, *args, **kwargs):
211 for pagenum in itertools.count(1):
212 page = self._download_json(
213 next_page_url or self._next_page_url(
214 pagenum, playlist_id, *args, **kwargs),
215 playlist_id, 'Downloading page
%s' % pagenum)
217 results = page.get('results
')
218 if not results or not isinstance(results, list):
221 for result in results:
222 video_url = url_or_none(result.get('video_url
'))
225 entry = self._extract_info(result, require_title=False)
229 'ie_key
': RutubeIE.ie_key(),
233 next_page_url = page.get('next
')
234 if not next_page_url or not page.get('has_next
'):
237 def _extract_playlist(self, playlist_id, *args, **kwargs):
238 return self.playlist_result(
239 self._entries(playlist_id, *args, **kwargs),
240 playlist_id, kwargs.get('playlist_name
'))
242 def _real_extract(self, url):
243 return self._extract_playlist(self._match_id(url))
246 class RutubeTagsIE(RutubePlaylistBaseIE):
247 IE_NAME = 'rutube
:tags
'
248 IE_DESC = 'Rutube tags
'
249 _VALID_URL = r'https?
://rutube\
.ru
/tags
/video
/(?P
<id>\d
+)'
251 'url
': 'http
://rutube
.ru
/tags
/video
/1800/',
255 'playlist_mincount
': 68,
258 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/tags
/video
/%s/?page
=%s&format
=json
'
261 class RutubeMovieIE(RutubePlaylistBaseIE):
262 IE_NAME = 'rutube
:movie
'
263 IE_DESC = 'Rutube movies
'
264 _VALID_URL = r'https?
://rutube\
.ru
/metainfo
/tv
/(?P
<id>\d
+)'
266 _MOVIE_TEMPLATE = 'http
://rutube
.ru
/api
/metainfo
/tv
/%s/?format
=json
'
267 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/metainfo
/tv
/%s/video?page
=%s&format
=json
'
269 def _real_extract(self, url):
270 movie_id = self._match_id(url)
271 movie = self._download_json(
272 self._MOVIE_TEMPLATE % movie_id, movie_id,
273 'Downloading movie JSON
')
274 return self._extract_playlist(
275 movie_id, playlist_name=movie.get('name
'))
278 class RutubePersonIE(RutubePlaylistBaseIE):
279 IE_NAME = 'rutube
:person
'
280 IE_DESC = 'Rutube person videos
'
281 _VALID_URL = r'https?
://rutube\
.ru
/video
/person
/(?P
<id>\d
+)'
283 'url
': 'http
://rutube
.ru
/video
/person
/313878/',
287 'playlist_mincount
': 37,
290 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/video
/person
/%s/?page
=%s&format
=json
'
293 class RutubePlaylistIE(RutubePlaylistBaseIE):
294 IE_NAME = 'rutube
:playlist
'
295 IE_DESC = 'Rutube playlists
'
296 _VALID_URL = r'https?
://rutube\
.ru
/(?
:video|
(?
:play
/)?embed
)/[\da
-z
]{32}
/\?.*?
\bpl
_id
=(?P
<id>\d
+)'
298 'url
': 'https
://rutube
.ru
/video
/cecd58ed7d531fc0f3d795d51cee9026
/?pl_id
=3097&pl_type
=tag
',
302 'playlist_count
': 27,
304 'url
': 'https
://rutube
.ru
/video
/10b3a03fc01d5bbcc632a2f3514e8aab
/?pl_id
=4252&pl_type
=source
',
305 'only_matching
': True,
308 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/playlist
/%s/%s/?page
=%s&format
=json
'
311 def suitable(cls, url):
312 from ..utils import int_or_none, parse_qs
314 if not super(RutubePlaylistIE, cls).suitable(url):
316 params = parse_qs(url)
317 return params.get('pl_type
', [None])[0] and int_or_none(params.get('pl_id
', [None])[0])
319 def _next_page_url(self, page_num, playlist_id, item_kind):
320 return self._PAGE_TEMPLATE % (item_kind, playlist_id, page_num)
322 def _real_extract(self, url):
324 playlist_kind = qs['pl_type
'][0]
325 playlist_id = qs['pl_id
'][0]
326 return self._extract_playlist(playlist_id, item_kind=playlist_kind)
329 class RutubeChannelIE(RutubePlaylistBaseIE):
330 IE_NAME = 'rutube
:channel
'
331 IE_DESC = 'Rutube channel
'
332 _VALID_URL = r'https?
://rutube\
.ru
/channel
/(?P
<id>\d
+)/videos
'
334 'url
': 'https
://rutube
.ru
/channel
/639184/videos
/',
338 'playlist_mincount
': 133,
341 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/video
/person
/%s/?page
=%s&format
=json
'