5 from .common
import InfoExtractor
6 from .dailymotion
import DailymotionIE
7 from .odnoklassniki
import OdnoklassnikiIE
8 from .pladform
import PladformIE
9 from .sibnet
import SibnetEmbedIE
10 from .vimeo
import VimeoIE
11 from .youtube
import YoutubeIE
17 get_element_html_by_id
,
34 class VKBaseIE(InfoExtractor
):
37 def _download_webpage_handle(self
, url_or_request
, video_id
, *args
, fatal
=True, **kwargs
):
38 response
= super()._download
_webpage
_handle
(url_or_request
, video_id
, *args
, fatal
=fatal
, **kwargs
)
39 challenge_url
, cookie
= response
[1].url
if response
else '', None
40 if challenge_url
.startswith('https://vk.com/429.html?'):
41 cookie
= self
._get
_cookies
(challenge_url
).get('hash429')
45 hash429
= hashlib
.md5(cookie
.value
.encode('ascii')).hexdigest()
46 self
._request
_webpage
(
47 update_url_query(challenge_url
, {'key': hash429}
), video_id
, fatal
=fatal
,
48 note
='Resolving WAF challenge', errnote
='Failed to bypass WAF challenge')
49 return super()._download
_webpage
_handle
(url_or_request
, video_id
, *args
, fatal
=True, **kwargs
)
51 def _perform_login(self
, username
, password
):
52 login_page
, url_handle
= self
._download
_webpage
_handle
(
53 'https://vk.com', None, 'Downloading login page')
55 login_form
= self
._hidden
_inputs
(login_page
)
58 'email': username
.encode('cp1251'),
59 'pass': password
.encode('cp1251'),
62 # vk serves two same remixlhk cookies in Set-Cookie header and expects
63 # first one to be actually set
64 self
._apply
_first
_set
_cookie
_header
(url_handle
, 'remixlhk')
66 login_page
= self
._download
_webpage
(
67 'https://vk.com/login', None,
69 data
=urlencode_postdata(login_form
))
71 if re
.search(r
'onLoginFailed', login_page
):
73 'Unable to login, incorrect username and/or password', expected
=True)
75 def _download_payload(self
, path
, video_id
, data
, fatal
=True):
76 endpoint
= f
'https://vk.com/{path}.php'
78 code
, payload
= self
._download
_json
(
79 endpoint
, video_id
, data
=urlencode_postdata(data
), fatal
=fatal
,
82 'X-Requested-With': 'XMLHttpRequest',
85 self
.raise_login_required()
87 raise ExtractorError(clean_html(payload
[0][1:-1]), expected
=True)
94 _EMBED_REGEX
= [r
'<iframe[^>]+?src=(["\'])(?P
<url
>https?
://vk\
.com
/video_ext\
.php
.+?
)\
1']
99 (?:(?:m|new)\.)?vk\.com/video_|
100 (?:www\.)?daxab\.com/
102 ext\.php\?(?P<embed_query>.*?\boid=(?P<oid>-?\d+).*?\bid=(?P<id>\d+).*)|
104 (?:(?:m|new)\.)?vk\.com/(?:.+?\?.*?z=)?(?:video|clip)|
105 (?:www\.)?daxab\.com/embed/
107 (?P<videoid>-?\d+_\d+)(?:.*\blist=(?P<list_id>([\da-f]+)|(ln-[\da-zA-Z]+)))?
113 'url
': 'http
://vk
.com
/videos
-77521?z
=video
-77521_162222515%2Fclub77521
',
115 'id': '-77521_162222515',
117 'title
': 'ProtivoGunz
- Хуёвая песня
',
118 'uploader
': 're
:(?
:Noize MC|Alexander Ilyashenko
).*',
119 'uploader_id
': '39545378',
121 'timestamp
': 1329049880,
122 'upload_date
': '20120212',
123 'comment_count
': int,
125 'thumbnail
': r're
:https?
://.+(?
:\
.jpg|getVideoPreview
.*)$
',
127 'params
': {'skip_download': 'm3u8'},
130 'url
': 'http
://vk
.com
/video205387401_165548505
',
132 'id': '205387401_165548505',
135 'uploader
': 'Tom Cruise
',
136 'uploader_id
': '205387401',
138 'timestamp
': 1374364108,
139 'upload_date
': '20130720',
140 'comment_count
': int,
142 'thumbnail
': r're
:https?
://.+(?
:\
.jpg|getVideoPreview
.*)$
',
146 'note
': 'Embedded video
',
147 'url
': 'https
://vk
.com
/video_ext
.php?oid
=-77521&id=162222515&hash=87b046504ccd8bfa
',
149 'id': '-77521_162222515',
151 'uploader
': 're
:(?
:Noize MC|Alexander Ilyashenko
).*',
152 'title
': 'ProtivoGunz
- Хуёвая песня
',
154 'upload_date
': '20120212',
155 'timestamp
': 1329049880,
156 'uploader_id
': '39545378',
157 'thumbnail
': r're
:https?
://.+(?
:\
.jpg|getVideoPreview
.*)$
',
159 'params
': {'skip_download': 'm3u8'},
162 'url
': 'https
://vk
.com
/video
-93049196_456239755?
list=ln
-cBjJ7S4jYYx3ADnmDT
',
164 'id': '-93049196_456239755',
166 'title
': '8 серия
(озвучка
)',
168 'comment_count
': int,
169 'uploader
': 'Dizi2021
',
171 'timestamp
': 1640162189,
172 'upload_date
': '20211222',
173 'uploader_id
': '-93049196',
174 'thumbnail
': r're
:https?
://.+(?
:\
.jpg|getVideoPreview
.*)$
',
178 'note
': 'youtube embed
',
179 'url
': 'https
://vk
.com
/video276849682_170681728
',
183 'title
': "DSWD Awards 'Children
's Joy Foundation, Inc.' Certificate of Registration
and License to Operate
",
184 'description': 'md5:bf9c26cfa4acdfb146362682edd3827a',
186 'upload_date': '20130117',
187 'uploader': "Children
's Joy Foundation Inc.",
188 'uploader_id
': 'thecjf
',
190 'channel_id
': 'UCgzCNQ11TmR9V97ECnhi3gw
',
191 'availability
': 'public
',
193 'live_status
': 'not_live
',
194 'playable_in_embed
': True,
195 'channel
': 'Children
\'s Joy Foundation Inc
.',
196 'uploader_url
': 'http
://www
.youtube
.com
/user
/thecjf
',
197 'thumbnail
': r're
:https?
://.+\
.jpg$
',
200 'categories
': ['Nonprofits
& Activism
'],
201 'channel_url
': 'https
://www
.youtube
.com
/channel
/UCgzCNQ11TmR9V97ECnhi3gw
',
202 'channel_follower_count
': int,
207 'note
': 'dailymotion embed
',
208 'url
': 'https
://vk
.com
/video
-95168827_456239103?
list=cca524a0f0d5557e16
',
212 'title
': 'md5
:45410f60ccd4b2760da98cb5fc777d70
',
213 'description
': 'md5
:2e71c5c9413735cfa06cf1a166f16c84
',
214 'uploader
': 'Movies
and cinema
.',
215 'upload_date
': '20221218',
216 'uploader_id
': 'x1jdavv
',
217 'timestamp
': 1671387617,
222 'thumbnail
': r're
:https?
://.+x1080$
',
227 'url
': 'https
://vk
.com
/clips
-74006511?z
=clip
-74006511_456247211',
229 'id': '-74006511_456247211',
231 'comment_count
': int,
234 'thumbnail
': r're
:https?
://.+(?
:\
.jpg|getVideoPreview
.*)$
',
235 'timestamp
': 1664995597,
236 'title
': 'Clip by
@madempress',
237 'upload_date
': '20221005',
238 'uploader
': 'Шальная императрица
',
239 'uploader_id
': '-74006511',
243 # video key is extra_data not url\d+
244 'url
': 'http
://vk
.com
/video
-110305615_171782105',
245 'md5
': 'e13fcda136f99764872e739d13fac1d1
',
247 'id': '-110305615_171782105',
249 'title
': 'S
-Dance
, репетиции к The way show
',
250 'uploader
': 'THE WAY SHOW |
17 апреля
',
251 'uploader_id
': '-110305615',
252 'timestamp
': 1454859345,
253 'upload_date
': '20160207',
258 'note
': 'finished live stream
, postlive_mp4
',
259 'url
': 'https
://vk
.com
/videos
-387766?z
=video
-387766_456242764%2Fpl_
-387766_-2',
261 'id': '-387766_456242764',
263 'title
': 'ИгроМир
2016 День
1 — Игромания Утром
',
264 'uploader
': 'Игромания
',
266 'upload_date
': '20160929',
267 'uploader_id
': '-387766',
268 'timestamp
': 1475137527,
269 'thumbnail
': r're
:https?
://.+\
.jpg$
',
270 'comment_count
': int,
274 'skip_download
': True,
278 # live stream, hls and rtmp links, most likely already finished live
279 # stream by the time you are reading this comment
280 'url
': 'https
://vk
.com
/video
-140332_456239111',
281 'only_matching
': True,
284 # removed video, just testing that we match the pattern
285 'url
': 'http
://vk
.com
/feed?z
=video
-43215063_166094326%2Fbb50cacd3177146d7a
',
286 'only_matching
': True,
289 # age restricted video, requires vk account credentials
290 'url
': 'https
://vk
.com
/video205387401_164765225
',
291 'only_matching
': True,
295 'url
': 'https
://vk
.com
/video
-76116461_171554880',
296 'only_matching
': True,
299 'url
': 'http
://new
.vk
.com
/video205387401_165548505
',
300 'only_matching
': True,
303 # This video is no longer available, because its author has been blocked.
304 'url
': 'https
://vk
.com
/video
-10639516_456240611',
305 'only_matching
': True,
308 # The video is not available in your region.
309 'url
': 'https
://vk
.com
/video
-51812607_171445436',
310 'only_matching
': True,
313 'url
': 'https
://vk
.com
/clip30014565_456240946
',
314 'only_matching
': True,
317 def _real_extract(self, url):
318 mobj = self._match_valid_url(url)
319 video_id = mobj.group('videoid
')
327 # Some videos (removed?) can only be downloaded with list id specified
328 list_id = mobj.group('list_id
')
330 data['list'] = list_id
332 payload = self._download_payload('al_video
', video_id, data)
333 info_page = payload[1]
335 mv_data = opts.get('mvData
') or {}
336 player = opts.get('player
') or {}
338 video_id = '%s_%s' % (mobj.group('oid
'), mobj.group('id'))
340 info_page = self._download_webpage(
341 'http
://vk
.com
/video_ext
.php?
' + mobj.group('embed_query
'), video_id)
343 error_message = self._html_search_regex(
344 [r'(?s
)<!><div
[^
>]+class="video_layer_message"[^
>]*>(.+?
)</div
>',
345 r'(?s
)<div
[^
>]+id="video_ext_msg"[^
>]*>(.+?
)</div
>'],
346 info_page, 'error message
', default=None)
348 raise ExtractorError(error_message, expected=True)
350 if re.search(r'<!>/login\
.php
\?.*\bact
=security_check
', info_page):
351 raise ExtractorError(
352 'You are trying to log
in from an unusual location
. You should confirm ownership at vk
.com to log
in with this IP
.',
355 ERROR_COPYRIGHT = 'Video
%s has been removed
from public access due to rightholder complaint
.'
358 r'>Видеозапись
.*? была изъята из публичного доступа в связи с обращением правообладателя
.<':
361 r'>The video
.*? was removed
from public access by request of the copyright holder
.<':
364 r'<!>Please log
in or <':
365 'Video
%s is only available
for registered users
, '
366 'use
--username
and --password options to provide account credentials
.',
369 'Video
%s does
not exist
.',
371 r'<!>Видео временно недоступно
':
372 'Video
%s is temporarily unavailable
.',
375 'Access denied to video
%s.',
377 r'<!>Видеозапись недоступна
, так как её автор был заблокирован
.':
378 'Video
%s is no longer available
, because its author has been blocked
.',
380 r'<!>This video
is no longer available
, because its author has been blocked
.':
381 'Video
%s is no longer available
, because its author has been blocked
.',
383 r'<!>This video
is no longer available
, because it has been deleted
.':
384 'Video
%s is no longer available
, because it has been deleted
.',
386 r'<!>The video
.+?
is not available
in your region
.':
387 'Video
%s is not available
in your region
.',
390 for error_re, error_msg in ERRORS.items():
391 if re.search(error_re, info_page):
392 raise ExtractorError(error_msg % video_id, expected=True)
394 player = self._parse_json(self._search_regex(
395 r'var\s
+playerParams\s
*=\s
*({.+?}
)\s
*;\s
*\n',
396 info_page, 'player params
'), video_id)
398 youtube_url = YoutubeIE._extract_url(info_page)
400 return self.url_result(youtube_url, YoutubeIE.ie_key())
402 vimeo_url = VimeoIE._extract_url(url, info_page)
403 if vimeo_url is not None:
404 return self.url_result(vimeo_url, VimeoIE.ie_key())
406 pladform_url = PladformIE._extract_url(info_page)
408 return self.url_result(pladform_url, PladformIE.ie_key())
410 m_rutube = re.search(
411 r'\ssrc
="((?:https?:)?//rutube\.ru\\?/(?:video|play)\\?/embed(?:.*?))\\?"', info_page)
412 if m_rutube is not None:
413 rutube_url = self._proto_relative_url(
414 m_rutube.group(1).replace('\\', ''))
415 return self.url_result(rutube_url)
417 dailymotion_url = next(DailymotionIE._extract_embed_urls(url, info_page), None)
419 return self.url_result(dailymotion_url, DailymotionIE.ie_key())
421 odnoklassniki_url = OdnoklassnikiIE._extract_url(info_page)
422 if odnoklassniki_url:
423 return self.url_result(odnoklassniki_url, OdnoklassnikiIE.ie_key())
425 sibnet_url = next(SibnetEmbedIE._extract_embed_urls(url, info_page), None)
427 return self.url_result(sibnet_url)
429 m_opts = re.search(r'(?s
)var\s
+opts\s
*=\s
*({.+?}
);', info_page)
431 m_opts_url = re.search(r"url\s*:\s*'((?
!/\b)[^
']+)", m_opts.group(1))
433 opts_url = m_opts_url.group(1)
434 if opts_url.startswith('//'):
435 opts_url = 'http
:' + opts_url
436 return self.url_result(opts_url)
438 data = player['params
'][0]
439 title = unescapeHTML(data['md_title
'])
442 # 3 = post live (finished live)
443 is_live = data.get('live
') == 2
445 timestamp = unified_timestamp(self._html_search_regex(
446 r'class=["\']mv_info_date[^>]+>([^<]+)(?:<|from)', info_page,
447 'upload date', default=None)) or int_or_none(data.get('date'))
449 view_count = str_to_int(self._search_regex(
450 r'class=["\']mv_views_count
[^
>]+>\s
*([\d
,.]+)',
451 info_page, 'view count
', default=None))
455 for format_id, format_url in data.items():
456 format_url = url_or_none(format_url)
457 if not format_url or not format_url.startswith(('http
', '//', 'rtmp
')):
459 if (format_id.startswith(('url
', 'cache
'))
460 or format_id in ('extra_data
', 'live_mp4
', 'postlive_mp4
')):
461 height = int_or_none(self._search_regex(
462 r'^
(?
:url|cache
)(\d
+)', format_id, 'height
', default=None))
464 'format_id
': format_id,
467 'source_preference
': 1,
470 elif format_id == 'hls
':
471 fmts, subs = self._extract_m3u8_formats_and_subtitles(
472 format_url, video_id, 'mp4
', 'm3u8_native
',
473 m3u8_id=format_id, fatal=False, live=is_live)
475 self._merge_subtitles(subs, target=subtitles)
476 elif format_id.startswith('dash_
'):
477 fmts, subs = self._extract_mpd_formats_and_subtitles(
478 format_url, video_id, mpd_id=format_id, fatal=False)
480 self._merge_subtitles(subs, target=subtitles)
481 elif format_id == 'rtmp
':
483 'format_id
': format_id,
488 for sub in data.get('subs
') or {}:
489 subtitles.setdefault(sub.get('lang
', 'en
'), []).append({
490 'ext
': sub.get('title
', '.srt
').split('.')[-1],
491 'url
': url_or_none(sub.get('url
')),
498 'thumbnail
': data.get('jpg
'),
499 'uploader
': data.get('md_author
'),
500 'uploader_id
': str_or_none(data.get('author_id
') or mv_data.get('authorId
')),
501 'duration
': int_or_none(data.get('duration
') or mv_data.get('duration
')),
502 'timestamp
': timestamp,
503 'view_count
': view_count,
504 'like_count
': int_or_none(mv_data.get('likes
')),
505 'comment_count
': int_or_none(mv_data.get('commcount
')),
507 'subtitles
': subtitles,
508 '_format_sort_fields
': ('res
', 'source
'),
512 class VKUserVideosIE(VKBaseIE):
513 IE_NAME = 'vk
:uservideos
'
514 IE_DESC = "VK - User's Videos
"
515 _VALID_URL = r'https?://(?:(?:m|new)\.)?vk\.com/video/(?:playlist/)?(?P<id>[^?$#/&]+)(?!\?.*\bz=video)(?:[/?#&](?:.*?\bsection=(?P<section>\w+))?|$)'
516 _TEMPLATE_URL = 'https://vk.com/videos'
518 'url': 'https://vk.com/video/@mobidevices',
520 'id': '-17892518_all',
522 'playlist_mincount': 1355,
524 'url': 'https://vk.com/video/@mobidevices?section=uploaded',
526 'id': '-17892518_uploaded',
528 'playlist_mincount': 182,
530 'url': 'https://vk.com/video/playlist/-174476437_2',
532 'id': '-174476437_playlist_2',
535 'playlist_mincount': 108,
537 _VIDEO = collections.namedtuple('Video', ['owner_id', 'id'])
539 def _entries(self, page_id, section):
540 video_list_json = self._download_payload('al_video', page_id, {
541 'act': 'load_videos_silent',
546 count = video_list_json['count']
547 total = video_list_json['total']
548 video_list = video_list_json['list']
551 for video in video_list:
552 v = self._VIDEO._make(video[:2])
553 video_id = '%d_%d' % (v.owner_id, v.id)
554 yield self.url_result(
555 'http://vk.com/video' + video_id, VKIE.ie_key(), video_id)
558 video_list_json = self._download_payload('al_video', page_id, {
559 'act': 'load_videos_silent',
564 count += video_list_json['count']
565 video_list = video_list_json['list']
567 def _real_extract(self, url):
568 u_id, section = self._match_valid_url(url).groups()
569 webpage = self._download_webpage(url, u_id)
571 if u_id.startswith('@'):
572 page_id = self._search_regex(r'data-owner-id\s?=\s?"([^
"]+)"', webpage, 'page_id
')
574 page_id, section = u_id.split('_
', 1)
575 section = f'playlist_{section}
'
577 raise ExtractorError('Invalid URL
', expected=True)
582 playlist_title = clean_html(get_element_by_class('VideoInfoPanel__title
', webpage))
583 return self.playlist_result(self._entries(page_id, section), '%s_%s' % (page_id, section), playlist_title)
586 class VKWallPostIE(VKBaseIE):
587 IE_NAME = 'vk
:wallpost
'
588 _VALID_URL = r'https?
://(?
:(?
:(?
:(?
:m|new
)\
.)?vk\
.com
/(?
:[^?
]+\?.*\bw
=)?
wall(?P
<id>-?\d
+_\d
+)))'
590 # public page URL, audio playlist
591 'url
': 'https
://vk
.com
/bs
.official?w
=wall
-23538238_35',
593 'id': '-23538238_35',
594 'title
': 'Black Shadow
- Wall post
-23538238_35',
595 'description
': 'md5
:190c78f905a53e0de793d83933c6e67f
',
598 'md5
': '5ba93864ec5b85f7ce19a9af4af080f6
',
600 'id': '135220665_111806521',
602 'title
': 'Black Shadow
- Слепое Верование
',
604 'uploader
': 'Black Shadow
',
605 'artist
': 'Black Shadow
',
606 'track
': 'Слепое Верование
',
609 'md5
': '4cc7e804579122b17ea95af7834c9233
',
611 'id': '135220665_111802303',
613 'title
': 'Black Shadow
- Война
- Негасимое Бездны Пламя
!',
615 'uploader
': 'Black Shadow
',
616 'artist
': 'Black Shadow
',
617 'track
': 'Война
- Негасимое Бездны Пламя
!',
621 'skip_download
': True,
624 # single YouTube embed with irrelevant reaction videos
625 'url
': 'https
://vk
.com
/wall
-32370614_7173954',
627 'id': '-32370614_7173954',
628 'title
': 'md5
:9f93c405bbc00061d34007d78c75e3bc
',
629 'description
': 'md5
:953b811f26fa9f21ee5856e2ea8e68fc
',
634 'url
': 'https
://vk
.com
/wall
-23538238_35',
635 'only_matching
': True,
637 # mobile wall page URL
638 'url
': 'https
://m
.vk
.com
/wall
-23538238_35',
639 'only_matching
': True,
641 _BASE64_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN0PQRSTUVWXYZO123456789
+/='
642 _AUDIO = collections.namedtuple('Audio
', ['id', 'owner_id
', 'url
', 'title
', 'performer
', 'duration
', 'album_id
', 'unk
', 'author_link
', 'lyrics
', 'flags
', 'context
', 'extra
', 'hashes
', 'cover_url
', 'ads
'])
644 def _decode(self, enc):
648 r = self._BASE64_CHARS.index(c)
650 e = 64 * e + r if cond else r
653 dec += chr(255 & e >> (-2 * n & 6))
656 def _unmask_url(self, mask_url, vk_id):
657 if 'audio_api_unavailable
' in mask_url:
658 extra = mask_url.split('?extra
=')[1].split('#')
659 func
, base
= self
._decode
(extra
[1]).split(chr(11))
660 mask_url
= list(self
._decode
(extra
[0]))
661 url_len
= len(mask_url
)
662 indexes
= [None] * url_len
663 index
= int(base
) ^ vk_id
664 for n
in range(url_len
- 1, -1, -1):
665 index
= (url_len
* (n
+ 1) ^ index
+ n
) % url_len
667 for n
in range(1, url_len
):
669 index
= indexes
[url_len
- 1 - n
]
670 mask_url
[n
] = mask_url
[index
]
672 mask_url
= ''.join(mask_url
)
675 def _real_extract(self
, url
):
676 post_id
= self
._match
_id
(url
)
678 webpage
= self
._download
_payload
('wkview', post_id
, {
680 'w': 'wall' + post_id
,
683 uploader
= clean_html(get_element_by_class('PostHeaderTitle__authorName', webpage
))
687 for audio
in re
.findall(r
'data-audio="([^"]+)', webpage
):
688 audio
= self
._parse
_json
(unescapeHTML(audio
), post_id
)
691 title
= unescapeHTML(audio
.get('title'))
692 artist
= unescapeHTML(audio
.get('artist'))
694 'id': f
'{audio["owner_id"]}_{audio["id"]}',
695 'title': join_nonempty(artist
, title
, delim
=' - '),
696 'thumbnails': try_call(lambda: [{'url': u}
for u
in audio
['coverUrl'].split(',')]),
697 'duration': int_or_none(audio
.get('duration')),
698 'uploader': uploader
,
706 'container': 'm4a_dash',
710 entries
.extend(self
.url_result(urljoin(url
, entry
), VKIE
) for entry
in set(re
.findall(
711 r
'<a[^>]+href=(?:["\'])(/video(?
:-?
[\d_
]+)[^
"\']*)',
712 get_element_html_by_id('wl_post_body', webpage))))
714 return self.playlist_result(
715 entries, post_id, join_nonempty(uploader, f'Wall post {post_id}', delim=' - '),
716 clean_html(get_element_by_class('wall_post_text', webpage)))
719 class VKPlayBaseIE(InfoExtractor):
720 _BASE_URL_RE = r'https?://(?:vkplay\.live|live\.vkplay\.ru)/'
727 'full_hd': '1920x1080',
728 'quad_hd': '2560x1440',
731 def _extract_from_initial_state(self, url, video_id, path):
732 webpage = self._download_webpage(url, video_id)
733 video_info = traverse_obj(self._search_json(
734 r'<script[^>]+\bid="initial
-state
"[^>]*>', webpage, 'initial state', video_id),
735 path, expected_type=dict)
737 raise ExtractorError('Unable to extract video info from html inline initial state')
740 def _extract_formats(self, stream_info, video_id):
742 for stream in traverse_obj(stream_info, (
743 'data', 0, 'playerUrls', lambda _, v: url_or_none(v['url']) and v['type'])):
745 format_id = str_or_none(stream['type'])
746 if format_id in ('hls', 'live_hls', 'live_playback_hls') or '.m3u8' in url:
747 formats.extend(self._extract_m3u8_formats(url, video_id, m3u8_id=format_id, fatal=False))
748 elif format_id == 'dash':
749 formats.extend(self._extract_mpd_formats(url, video_id, mpd_id=format_id, fatal=False))
750 elif format_id in ('live_dash', 'live_playback_dash'):
751 self.write_debug(f'Not extracting unsupported format "{format_id}
"')
756 'format_id': format_id,
757 **parse_resolution(self._RESOLUTIONS.get(format_id)),
761 def _extract_common_meta(self, stream_info):
762 return traverse_obj(stream_info, {
763 'id': ('id', {str_or_none}),
764 'title': ('title', {str}),
765 'release_timestamp': ('startTime', {int_or_none}),
766 'thumbnail': ('previewUrl', {url_or_none}),
767 'view_count': ('count', 'views', {int_or_none}),
768 'like_count': ('count', 'likes', {int_or_none}),
769 'categories': ('category', 'title', {str}, {lambda x: [x] if x else None}),
770 'uploader': (('user', ('blog', 'owner')), 'nick', {str}),
771 'uploader_id': (('user', ('blog', 'owner')), 'id', {str_or_none}),
772 'duration': ('duration', {int_or_none}),
773 'is_live': ('isOnline', {bool}),
774 'concurrent_view_count': ('count', 'viewers', {int_or_none}),
778 class VKPlayIE(VKPlayBaseIE):
779 _VALID_URL = rf'{VKPlayBaseIE._BASE_URL_RE}(?P<username>[^/#?]+)/record/(?P<id>[\da-f-]+)'
781 'url': 'https://vkplay.live/zitsmann/record/f5e6e3b5-dc52-4d14-965d-0680dd2882da',
783 'id': 'f5e6e3b5-dc52-4d14-965d-0680dd2882da',
785 'title': 'Atomic Heart (пробуем!) спасибо подписчику EKZO!',
786 'uploader': 'ZitsmanN',
787 'uploader_id': '13159830',
788 'release_timestamp': 1683461378,
789 'release_date': '20230507',
790 'thumbnail': r're:https://[^/]+/public_video_stream/record/f5e6e3b5-dc52-4d14-965d-0680dd2882da/preview',
794 'categories': ['Atomic Heart'],
796 'params': {'skip_download': 'm3u8'},
798 'url': 'https://live.vkplay.ru/lebwa/record/33a4e4ce-e3ef-49db-bb14-f006cc6fabc9/records',
799 'only_matching': True,
802 def _real_extract(self, url):
803 username, video_id = self._match_valid_url(url).groups()
805 record_info = traverse_obj(self._download_json(
806 f'https://api.vkplay.live/v1/blog/{username}/public_video_stream/record/{video_id}', video_id, fatal=False),
807 ('data', 'record', {dict}))
809 record_info = self._extract_from_initial_state(url, video_id, ('record', 'currentRecord', 'data'))
812 **self._extract_common_meta(record_info),
814 'formats': self._extract_formats(record_info, video_id),
818 class VKPlayLiveIE(VKPlayBaseIE):
819 _VALID_URL = rf'{VKPlayBaseIE._BASE_URL_RE}(?P<id>[^/#?]+)/?(?:[#?]|$)'
821 'url': 'https://vkplay.live/bayda',
823 'id': 'f02c321e-427b-408d-b12f-ae34e53e0ea2',
825 'title': r're:эскапизм крута .*',
827 'uploader_id': '12279401',
828 'release_timestamp': 1687209962,
829 'release_date': '20230619',
830 'thumbnail': r're:https://[^/]+/public_video_stream/12279401/preview',
832 'concurrent_view_count': int,
834 'categories': ['EVE Online'],
835 'live_status': 'is_live',
837 'skip': 'livestream',
838 'params': {'skip_download': True},
840 'url': 'https://live.vkplay.ru/lebwa',
841 'only_matching': True,
844 def _real_extract(self, url):
845 username = self._match_id(url)
847 stream_info = self._download_json(
848 f'https://api.vkplay.live/v1/blog/{username}/public_video_stream', username, fatal=False)
850 stream_info = self._extract_from_initial_state(url, username, ('stream', 'stream', 'data', 'stream'))
852 formats = self._extract_formats(stream_info, username)
853 if not formats and not traverse_obj(stream_info, ('isOnline', {bool})):
854 raise UserNotLive(video_id=username)
857 **self._extract_common_meta(stream_info),