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
)
28 def _extract_info(self
, video
, video_id
=None, require_title
=True):
29 title
= video
['title'] if require_title
else video
.get('title')
31 age_limit
= video
.get('is_adult')
32 if age_limit
is not None:
33 age_limit
= 18 if age_limit
is True else 0
35 uploader_id
= try_get(video
, lambda x
: x
['author']['id'])
36 category
= try_get(video
, lambda x
: x
['category']['name'])
37 description
= video
.get('description')
38 duration
= int_or_none(video
.get('duration'))
41 'id': video
.get('id') or video_id
if video_id
else video
['id'],
43 'description': description
,
44 'thumbnail': video
.get('thumbnail_url'),
46 'uploader': try_get(video
, lambda x
: x
['author']['name']),
47 'uploader_id': compat_str(uploader_id
) if uploader_id
else None,
48 'timestamp': unified_timestamp(video
.get('created_ts')),
49 'category': [category
] if category
else None,
50 'age_limit': age_limit
,
51 'view_count': int_or_none(video
.get('hits')),
52 'comment_count': int_or_none(video
.get('comments_count')),
53 'is_live': bool_or_none(video
.get('is_livestream')),
54 'chapters': self
._extract
_chapters
_from
_description
(description
, duration
),
57 def _download_and_extract_info(self
, video_id
, query
=None):
58 return self
._extract
_info
(
59 self
._download
_api
_info
(video_id
, query
=query
), video_id
)
61 def _download_api_options(self
, video_id
, query
=None):
64 query
['format'] = 'json'
65 return self
._download
_json
(
66 'http://rutube.ru/api/play/options/%s/' % video_id
,
67 video_id
, 'Downloading options JSON',
68 'Unable to download options JSON',
69 headers
=self
.geo_verification_headers(), query
=query
)
71 def _extract_formats(self
, options
, video_id
):
73 for format_id
, format_url
in options
['video_balancer'].items():
74 ext
= determine_ext(format_url
)
76 formats
.extend(self
._extract
_m
3u8_formats
(
77 format_url
, video_id
, 'mp4', m3u8_id
=format_id
, fatal
=False))
79 formats
.extend(self
._extract
_f
4m
_formats
(
80 format_url
, video_id
, f4m_id
=format_id
, fatal
=False))
84 'format_id': format_id
,
88 def _download_and_extract_formats(self
, video_id
, query
=None):
89 return self
._extract
_formats
(
90 self
._download
_api
_options
(video_id
, query
=query
), video_id
)
93 class RutubeIE(RutubeBaseIE
):
95 IE_DESC
= 'Rutube videos'
96 _VALID_URL
= r
'https?://rutube\.ru/(?:video(?:/private)?|(?:play/)?embed)/(?P<id>[\da-z]{32})'
97 _EMBED_REGEX
= [r
'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//rutube\
.ru
/(?
:play
/)?embed
/[\da
-z
]{32}
.*?
)\
1']
100 'url
': 'http
://rutube
.ru
/video
/3eac3b4561676c17df9132a9a1e62e3e
/',
101 'md5
': 'e33ac625efca66aba86cbec9851f2692
',
103 'id': '3eac3b4561676c17df9132a9a1e62e3e
',
105 'title
': 'Раненный кенгуру забежал в аптеку
',
106 'description
': 'http
://www
.ntdtv
.ru
',
108 'uploader
': 'NTDRussian
',
109 'uploader_id
': '29790',
110 'timestamp
': 1381943602,
111 'upload_date
': '20131016',
114 'thumbnail
': 'http
://pic
.rutubelist
.ru
/video
/d2
/a0
/d2a0aec998494a396deafc7ba2c82add
.jpg
',
115 'category
': ['Новости и СМИ
'],
118 'expected_warnings
': ['Unable to download f4m
'],
120 'url
': 'http
://rutube
.ru
/play
/embed
/a10e53b86e8f349080f718582ce4c661
',
121 'only_matching
': True,
123 'url
': 'http
://rutube
.ru
/embed
/a10e53b86e8f349080f718582ce4c661
',
124 'only_matching
': True,
126 'url
': 'http
://rutube
.ru
/video
/3eac3b4561676c17df9132a9a1e62e3e
/?pl_id
=4252',
127 'only_matching
': True,
129 'url
': 'https
://rutube
.ru
/video
/10b3a03fc01d5bbcc632a2f3514e8aab
/?pl_type
=source
',
130 'only_matching
': True,
132 'url
': 'https
://rutube
.ru
/video
/private
/884fb55f07a97ab673c7d654553e0f48
/?p
=x2QojCumHTS3rsKHWXN8Lg
',
133 'md5
': 'd106225f15d625538fe22971158e896f
',
135 'id': '884fb55f07a97ab673c7d654553e0f48
',
137 'title
': 'Яцуноками
, Nioh2
',
138 'description
': 'Nioh2
: финал сражения с боссом Яцуноками
',
141 'uploader_id
': '24222106',
142 'timestamp
': 1670646232,
143 'upload_date
': '20221210',
146 'thumbnail
': 'http
://pic
.rutubelist
.ru
/video
/f2
/d4
/f2d42b54be0a6e69c1c22539e3152156
.jpg
',
147 'category
': ['Видеоигры
'],
150 'expected_warnings
': ['Unable to download f4m
'],
152 'url
': 'https
://rutube
.ru
/video
/c65b465ad0c98c89f3b25cb03dcc87c6
/',
154 'id': 'c65b465ad0c98c89f3b25cb03dcc87c6
',
156 'chapters
': 'count
:4',
157 'category
': ['Бизнес и предпринимательство
'],
158 'description
': 'md5
:252feac1305257d8c1bab215cedde75d
',
159 'thumbnail
': 'http
://pic
.rutubelist
.ru
/video
/71/8f
/718f27425ea9706073eb80883dd3787b
.png
',
162 'uploader_id
': '23491359',
163 'timestamp
': 1677153329,
165 'upload_date
': '20230223',
166 'title
': 'Бизнес с нуля
: найм сотрудников
. Интервью с директором строительной компании
',
167 'uploader
': 'Стас Быков
',
169 'expected_warnings
': ['Unable to download f4m
'],
173 def suitable(cls, url):
174 return False if RutubePlaylistIE.suitable(url) else super(RutubeIE, cls).suitable(url)
176 def _real_extract(self, url):
177 video_id = self._match_id(url)
178 query = parse_qs(url)
179 info = self._download_and_extract_info(video_id, query)
180 info['formats
'] = self._download_and_extract_formats(video_id, query)
184 class RutubeEmbedIE(RutubeBaseIE):
185 IE_NAME = 'rutube
:embed
'
186 IE_DESC = 'Rutube embedded videos
'
187 _VALID_URL = r'https?
://rutube\
.ru
/(?
:video|play
)/embed
/(?P
<id>[0-9]+)'
190 'url
': 'http
://rutube
.ru
/video
/embed
/6722881?vk_puid37
=&vk_puid38
=',
192 'id': 'a10e53b86e8f349080f718582ce4c661
',
194 'timestamp
': 1387830582,
195 'upload_date
': '20131223',
196 'uploader_id
': '297833',
197 'description
': 'Видео группы ★http
://vk
.com
/foxkidsreset★ музей Fox Kids и Jetix
<br
/><br
/> восстановлено и сделано в шикоформате subziro89 http
://vk
.com
/subziro89
',
198 'uploader
': 'subziro89 ILya
',
199 'title
': 'Мистический городок Эйри в Индиан
5 серия озвучка subziro89
',
202 'skip_download
': True,
205 'url
': 'http
://rutube
.ru
/play
/embed
/8083783',
206 'only_matching
': True,
209 'url
': 'https
://rutube
.ru
/play
/embed
/10631925?p
=IbAigKqWd1do4mjaM5XLIQ
',
210 'only_matching
': True,
213 def _real_extract(self, url):
214 embed_id = self._match_id(url)
215 # Query may contain private videos token and should be passed to API
216 # requests (see #19163)
217 query = parse_qs(url)
218 options = self._download_api_options(embed_id, query)
219 video_id = options['effective_video
']
220 formats = self._extract_formats(options, video_id)
221 info = self._download_and_extract_info(video_id, query)
223 'extractor_key
': 'Rutube
',
229 class RutubePlaylistBaseIE(RutubeBaseIE):
230 def _next_page_url(self, page_num, playlist_id, *args, **kwargs):
231 return self._PAGE_TEMPLATE % (playlist_id, page_num)
233 def _entries(self, playlist_id, *args, **kwargs):
235 for pagenum in itertools.count(1):
236 page = self._download_json(
237 next_page_url or self._next_page_url(
238 pagenum, playlist_id, *args, **kwargs),
239 playlist_id, 'Downloading page
%s' % pagenum)
241 results = page.get('results
')
242 if not results or not isinstance(results, list):
245 for result in results:
246 video_url = url_or_none(result.get('video_url
'))
249 entry = self._extract_info(result, require_title=False)
253 'ie_key
': RutubeIE.ie_key(),
257 next_page_url = page.get('next
')
258 if not next_page_url or not page.get('has_next
'):
261 def _extract_playlist(self, playlist_id, *args, **kwargs):
262 return self.playlist_result(
263 self._entries(playlist_id, *args, **kwargs),
264 playlist_id, kwargs.get('playlist_name
'))
266 def _real_extract(self, url):
267 return self._extract_playlist(self._match_id(url))
270 class RutubeTagsIE(RutubePlaylistBaseIE):
271 IE_NAME = 'rutube
:tags
'
272 IE_DESC = 'Rutube tags
'
273 _VALID_URL = r'https?
://rutube\
.ru
/tags
/video
/(?P
<id>\d
+)'
275 'url
': 'http
://rutube
.ru
/tags
/video
/1800/',
279 'playlist_mincount
': 68,
282 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/tags
/video
/%s/?page
=%s&format
=json
'
285 class RutubeMovieIE(RutubePlaylistBaseIE):
286 IE_NAME = 'rutube
:movie
'
287 IE_DESC = 'Rutube movies
'
288 _VALID_URL = r'https?
://rutube\
.ru
/metainfo
/tv
/(?P
<id>\d
+)'
290 _MOVIE_TEMPLATE = 'http
://rutube
.ru
/api
/metainfo
/tv
/%s/?format
=json
'
291 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/metainfo
/tv
/%s/video?page
=%s&format
=json
'
293 def _real_extract(self, url):
294 movie_id = self._match_id(url)
295 movie = self._download_json(
296 self._MOVIE_TEMPLATE % movie_id, movie_id,
297 'Downloading movie JSON
')
298 return self._extract_playlist(
299 movie_id, playlist_name=movie.get('name
'))
302 class RutubePersonIE(RutubePlaylistBaseIE):
303 IE_NAME = 'rutube
:person
'
304 IE_DESC = 'Rutube person videos
'
305 _VALID_URL = r'https?
://rutube\
.ru
/video
/person
/(?P
<id>\d
+)'
307 'url
': 'http
://rutube
.ru
/video
/person
/313878/',
311 'playlist_mincount
': 37,
314 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/video
/person
/%s/?page
=%s&format
=json
'
317 class RutubePlaylistIE(RutubePlaylistBaseIE):
318 IE_NAME = 'rutube
:playlist
'
319 IE_DESC = 'Rutube playlists
'
320 _VALID_URL = r'https?
://rutube\
.ru
/(?
:video|
(?
:play
/)?embed
)/[\da
-z
]{32}
/\?.*?
\bpl
_id
=(?P
<id>\d
+)'
322 'url
': 'https
://rutube
.ru
/video
/cecd58ed7d531fc0f3d795d51cee9026
/?pl_id
=3097&pl_type
=tag
',
326 'playlist_count
': 27,
328 'url
': 'https
://rutube
.ru
/video
/10b3a03fc01d5bbcc632a2f3514e8aab
/?pl_id
=4252&pl_type
=source
',
329 'only_matching
': True,
332 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/playlist
/%s/%s/?page
=%s&format
=json
'
335 def suitable(cls, url):
336 from ..utils import int_or_none, parse_qs
338 if not super(RutubePlaylistIE, cls).suitable(url):
340 params = parse_qs(url)
341 return params.get('pl_type
', [None])[0] and int_or_none(params.get('pl_id
', [None])[0])
343 def _next_page_url(self, page_num, playlist_id, item_kind):
344 return self._PAGE_TEMPLATE % (item_kind, playlist_id, page_num)
346 def _real_extract(self, url):
348 playlist_kind = qs['pl_type
'][0]
349 playlist_id = qs['pl_id
'][0]
350 return self._extract_playlist(playlist_id, item_kind=playlist_kind)
353 class RutubeChannelIE(RutubePlaylistBaseIE):
354 IE_NAME = 'rutube
:channel
'
355 IE_DESC = 'Rutube channel
'
356 _VALID_URL = r'https?
://rutube\
.ru
/channel
/(?P
<id>\d
+)/videos
'
358 'url
': 'https
://rutube
.ru
/channel
/639184/videos
/',
362 'playlist_mincount
': 133,
365 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/video
/person
/%s/?page
=%s&format
=json
'