3 from .common
import InfoExtractor
15 class RutubeBaseIE(InfoExtractor
):
16 def _download_api_info(self
, video_id
, query
=None):
19 query
['format'] = 'json'
20 return self
._download
_json
(
21 f
'http://rutube.ru/api/video/{video_id}/',
22 video_id
, 'Downloading video JSON',
23 'Unable to download video JSON', query
=query
)
25 def _extract_info(self
, video
, video_id
=None, require_title
=True):
26 title
= video
['title'] if require_title
else video
.get('title')
28 age_limit
= video
.get('is_adult')
29 if age_limit
is not None:
30 age_limit
= 18 if age_limit
is True else 0
32 uploader_id
= try_get(video
, lambda x
: x
['author']['id'])
33 category
= try_get(video
, lambda x
: x
['category']['name'])
34 description
= video
.get('description')
35 duration
= int_or_none(video
.get('duration'))
38 'id': video
.get('id') or video_id
if video_id
else video
['id'],
40 'description': description
,
41 'thumbnail': video
.get('thumbnail_url'),
43 'uploader': try_get(video
, lambda x
: x
['author']['name']),
44 'uploader_id': str(uploader_id
) if uploader_id
else None,
45 'timestamp': unified_timestamp(video
.get('created_ts')),
46 'categories': [category
] if category
else None,
47 'age_limit': age_limit
,
48 'view_count': int_or_none(video
.get('hits')),
49 'comment_count': int_or_none(video
.get('comments_count')),
50 'is_live': bool_or_none(video
.get('is_livestream')),
51 'chapters': self
._extract
_chapters
_from
_description
(description
, duration
),
54 def _download_and_extract_info(self
, video_id
, query
=None):
55 return self
._extract
_info
(
56 self
._download
_api
_info
(video_id
, query
=query
), video_id
)
58 def _download_api_options(self
, video_id
, query
=None):
61 query
['format'] = 'json'
62 return self
._download
_json
(
63 f
'http://rutube.ru/api/play/options/{video_id}/',
64 video_id
, 'Downloading options JSON',
65 'Unable to download options JSON',
66 headers
=self
.geo_verification_headers(), query
=query
)
68 def _extract_formats(self
, options
, video_id
):
70 for format_id
, format_url
in options
['video_balancer'].items():
71 ext
= determine_ext(format_url
)
73 formats
.extend(self
._extract
_m
3u8_formats
(
74 format_url
, video_id
, 'mp4', m3u8_id
=format_id
, fatal
=False))
76 formats
.extend(self
._extract
_f
4m
_formats
(
77 format_url
, video_id
, f4m_id
=format_id
, fatal
=False))
81 'format_id': format_id
,
85 def _download_and_extract_formats(self
, video_id
, query
=None):
86 return self
._extract
_formats
(
87 self
._download
_api
_options
(video_id
, query
=query
), video_id
)
90 class RutubeIE(RutubeBaseIE
):
92 IE_DESC
= 'Rutube videos'
93 _VALID_URL
= r
'https?://rutube\.ru/(?:video(?:/private)?|(?:play/)?embed)/(?P<id>[\da-z]{32})'
94 _EMBED_REGEX
= [r
'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//rutube\
.ru
/(?
:play
/)?embed
/[\da
-z
]{32}
.*?
)\
1']
97 'url
': 'http
://rutube
.ru
/video
/3eac3b4561676c17df9132a9a1e62e3e
/',
98 'md5
': 'e33ac625efca66aba86cbec9851f2692
',
100 'id': '3eac3b4561676c17df9132a9a1e62e3e
',
102 'title
': 'Раненный кенгуру забежал в аптеку
',
103 'description
': 'http
://www
.ntdtv
.ru
',
105 'uploader
': 'NTDRussian
',
106 'uploader_id
': '29790',
107 'timestamp
': 1381943602,
108 'upload_date
': '20131016',
111 'thumbnail
': 'http
://pic
.rutubelist
.ru
/video
/d2
/a0
/d2a0aec998494a396deafc7ba2c82add
.jpg
',
112 'categories
': ['Новости и СМИ
'],
115 'expected_warnings
': ['Unable to download f4m
'],
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 'categories
': ['Видеоигры
'],
147 'expected_warnings
': ['Unable to download f4m
'],
149 'url
': 'https
://rutube
.ru
/video
/c65b465ad0c98c89f3b25cb03dcc87c6
/',
151 'id': 'c65b465ad0c98c89f3b25cb03dcc87c6
',
153 'chapters
': 'count
:4',
154 'categories
': ['Бизнес и предпринимательство
'],
155 'description
': 'md5
:252feac1305257d8c1bab215cedde75d
',
156 'thumbnail
': 'http
://pic
.rutubelist
.ru
/video
/71/8f
/718f27425ea9706073eb80883dd3787b
.png
',
159 'uploader_id
': '23491359',
160 'timestamp
': 1677153329,
162 'upload_date
': '20230223',
163 'title
': 'Бизнес с нуля
: найм сотрудников
. Интервью с директором строительной компании
',
164 'uploader
': 'Стас Быков
',
166 'expected_warnings
': ['Unable to download f4m
'],
170 def suitable(cls, url):
171 return False if RutubePlaylistIE.suitable(url) else super().suitable(url)
173 def _real_extract(self, url):
174 video_id = self._match_id(url)
175 query = parse_qs(url)
176 info = self._download_and_extract_info(video_id, query)
177 info['formats
'] = self._download_and_extract_formats(video_id, query)
181 class RutubeEmbedIE(RutubeBaseIE):
182 IE_NAME = 'rutube
:embed
'
183 IE_DESC = 'Rutube embedded videos
'
184 _VALID_URL = r'https?
://rutube\
.ru
/(?
:video|play
)/embed
/(?P
<id>[0-9]+)'
187 'url
': 'http
://rutube
.ru
/video
/embed
/6722881?vk_puid37
=&vk_puid38
=',
189 'id': 'a10e53b86e8f349080f718582ce4c661
',
191 'timestamp
': 1387830582,
192 'upload_date
': '20131223',
193 'uploader_id
': '297833',
194 'description
': 'Видео группы ★http
://vk
.com
/foxkidsreset★ музей Fox Kids и Jetix
<br
/><br
/> восстановлено и сделано в шикоформате subziro89 http
://vk
.com
/subziro89
',
195 'uploader
': 'subziro89 ILya
',
196 'title
': 'Мистический городок Эйри в Индиан
5 серия озвучка subziro89
',
199 'skip_download
': True,
202 'url
': 'http
://rutube
.ru
/play
/embed
/8083783',
203 'only_matching
': True,
206 'url
': 'https
://rutube
.ru
/play
/embed
/10631925?p
=IbAigKqWd1do4mjaM5XLIQ
',
207 'only_matching
': True,
210 def _real_extract(self, url):
211 embed_id = self._match_id(url)
212 # Query may contain private videos token and should be passed to API
213 # requests (see #19163)
214 query = parse_qs(url)
215 options = self._download_api_options(embed_id, query)
216 video_id = options['effective_video
']
217 formats = self._extract_formats(options, video_id)
218 info = self._download_and_extract_info(video_id, query)
220 'extractor_key
': 'Rutube
',
226 class RutubePlaylistBaseIE(RutubeBaseIE):
227 def _next_page_url(self, page_num, playlist_id, *args, **kwargs):
228 return self._PAGE_TEMPLATE % (playlist_id, page_num)
230 def _entries(self, playlist_id, *args, **kwargs):
232 for pagenum in itertools.count(1):
233 page = self._download_json(
234 next_page_url or self._next_page_url(
235 pagenum, playlist_id, *args, **kwargs),
236 playlist_id, f'Downloading page {pagenum}
')
238 results = page.get('results
')
239 if not results or not isinstance(results, list):
242 for result in results:
243 video_url = url_or_none(result.get('video_url
'))
246 entry = self._extract_info(result, require_title=False)
250 'ie_key
': RutubeIE.ie_key(),
254 next_page_url = page.get('next
')
255 if not next_page_url or not page.get('has_next
'):
258 def _extract_playlist(self, playlist_id, *args, **kwargs):
259 return self.playlist_result(
260 self._entries(playlist_id, *args, **kwargs),
261 playlist_id, kwargs.get('playlist_name
'))
263 def _real_extract(self, url):
264 return self._extract_playlist(self._match_id(url))
267 class RutubeTagsIE(RutubePlaylistBaseIE):
268 IE_NAME = 'rutube
:tags
'
269 IE_DESC = 'Rutube tags
'
270 _VALID_URL = r'https?
://rutube\
.ru
/tags
/video
/(?P
<id>\d
+)'
272 'url
': 'http
://rutube
.ru
/tags
/video
/1800/',
276 'playlist_mincount
': 68,
279 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/tags
/video
/%s/?page
=%s&format
=json
'
282 class RutubeMovieIE(RutubePlaylistBaseIE):
283 IE_NAME = 'rutube
:movie
'
284 IE_DESC = 'Rutube movies
'
285 _VALID_URL = r'https?
://rutube\
.ru
/metainfo
/tv
/(?P
<id>\d
+)'
287 _MOVIE_TEMPLATE = 'http
://rutube
.ru
/api
/metainfo
/tv
/%s/?format
=json
'
288 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/metainfo
/tv
/%s/video?page
=%s&format
=json
'
290 def _real_extract(self, url):
291 movie_id = self._match_id(url)
292 movie = self._download_json(
293 self._MOVIE_TEMPLATE % movie_id, movie_id,
294 'Downloading movie JSON
')
295 return self._extract_playlist(
296 movie_id, playlist_name=movie.get('name
'))
299 class RutubePersonIE(RutubePlaylistBaseIE):
300 IE_NAME = 'rutube
:person
'
301 IE_DESC = 'Rutube person videos
'
302 _VALID_URL = r'https?
://rutube\
.ru
/video
/person
/(?P
<id>\d
+)'
304 'url
': 'http
://rutube
.ru
/video
/person
/313878/',
308 'playlist_mincount
': 37,
311 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/video
/person
/%s/?page
=%s&format
=json
'
314 class RutubePlaylistIE(RutubePlaylistBaseIE):
315 IE_NAME = 'rutube
:playlist
'
316 IE_DESC = 'Rutube playlists
'
317 _VALID_URL = r'https?
://rutube\
.ru
/(?
:video|
(?
:play
/)?embed
)/[\da
-z
]{32}
/\?.*?
\bpl
_id
=(?P
<id>\d
+)'
319 'url
': 'https
://rutube
.ru
/video
/cecd58ed7d531fc0f3d795d51cee9026
/?pl_id
=3097&pl_type
=tag
',
323 'playlist_count
': 27,
325 'url
': 'https
://rutube
.ru
/video
/10b3a03fc01d5bbcc632a2f3514e8aab
/?pl_id
=4252&pl_type
=source
',
326 'only_matching
': True,
329 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/playlist
/%s/%s/?page
=%s&format
=json
'
332 def suitable(cls, url):
333 from ..utils import int_or_none, parse_qs
335 if not super().suitable(url):
337 params = parse_qs(url)
338 return params.get('pl_type
', [None])[0] and int_or_none(params.get('pl_id
', [None])[0])
340 def _next_page_url(self, page_num, playlist_id, item_kind):
341 return self._PAGE_TEMPLATE % (item_kind, playlist_id, page_num)
343 def _real_extract(self, url):
345 playlist_kind = qs['pl_type
'][0]
346 playlist_id = qs['pl_id
'][0]
347 return self._extract_playlist(playlist_id, item_kind=playlist_kind)
350 class RutubeChannelIE(RutubePlaylistBaseIE):
351 IE_NAME = 'rutube
:channel
'
352 IE_DESC = 'Rutube channel
'
353 _VALID_URL = r'https?
://rutube\
.ru
/channel
/(?P
<id>\d
+)/videos
'
355 'url
': 'https
://rutube
.ru
/channel
/639184/videos
/',
359 'playlist_mincount
': 133,
362 _PAGE_TEMPLATE = 'http
://rutube
.ru
/api
/video
/person
/%s/?page
=%s&format
=json
'