]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/vk.py
[vk] Capture `clip` URLs
[yt-dlp.git] / yt_dlp / extractor / vk.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import collections
5 import functools
6 import re
7
8 from .common import InfoExtractor
9 from ..compat import compat_urlparse
10 from ..utils import (
11 clean_html,
12 ExtractorError,
13 get_element_by_class,
14 int_or_none,
15 OnDemandPagedList,
16 orderedSet,
17 str_or_none,
18 str_to_int,
19 unescapeHTML,
20 unified_timestamp,
21 url_or_none,
22 urlencode_postdata,
23 )
24 from .dailymotion import DailymotionIE
25 from .odnoklassniki import OdnoklassnikiIE
26 from .pladform import PladformIE
27 from .vimeo import VimeoIE
28 from .youtube import YoutubeIE
29
30
31 class VKBaseIE(InfoExtractor):
32 _NETRC_MACHINE = 'vk'
33
34 def _login(self):
35 username, password = self._get_login_info()
36 if username is None:
37 return
38
39 login_page, url_handle = self._download_webpage_handle(
40 'https://vk.com', None, 'Downloading login page')
41
42 login_form = self._hidden_inputs(login_page)
43
44 login_form.update({
45 'email': username.encode('cp1251'),
46 'pass': password.encode('cp1251'),
47 })
48
49 # vk serves two same remixlhk cookies in Set-Cookie header and expects
50 # first one to be actually set
51 self._apply_first_set_cookie_header(url_handle, 'remixlhk')
52
53 login_page = self._download_webpage(
54 'https://vk.com/login', None,
55 note='Logging in',
56 data=urlencode_postdata(login_form))
57
58 if re.search(r'onLoginFailed', login_page):
59 raise ExtractorError(
60 'Unable to login, incorrect username and/or password', expected=True)
61
62 def _real_initialize(self):
63 self._login()
64
65 def _download_payload(self, path, video_id, data, fatal=True):
66 data['al'] = 1
67 code, payload = self._download_json(
68 'https://vk.com/%s.php' % path, video_id,
69 data=urlencode_postdata(data), fatal=fatal,
70 headers={'X-Requested-With': 'XMLHttpRequest'})['payload']
71 if code == '3':
72 self.raise_login_required()
73 elif code == '8':
74 raise ExtractorError(clean_html(payload[0][1:-1]), expected=True)
75 return payload
76
77
78 class VKIE(VKBaseIE):
79 IE_NAME = 'vk'
80 IE_DESC = 'VK'
81 _VALID_URL = r'''(?x)
82 https?://
83 (?:
84 (?:
85 (?:(?:m|new)\.)?vk\.com/video_|
86 (?:www\.)?daxab.com/
87 )
88 ext\.php\?(?P<embed_query>.*?\boid=(?P<oid>-?\d+).*?\bid=(?P<id>\d+).*)|
89 (?:
90 (?:(?:m|new)\.)?vk\.com/(?:.+?\?.*?z=)?(?:video|clip)|
91 (?:www\.)?daxab.com/embed/
92 )
93 (?P<videoid>-?\d+_\d+)(?:.*\blist=(?P<list_id>([\da-f]+)|(ln-[\da-zA-Z]+)))?
94 )
95 '''
96 _TESTS = [
97 {
98 'url': 'http://vk.com/videos-77521?z=video-77521_162222515%2Fclub77521',
99 'md5': '7babad3b85ea2e91948005b1b8b0cb84',
100 'info_dict': {
101 'id': '-77521_162222515',
102 'ext': 'mp4',
103 'title': 'ProtivoGunz - Хуёвая песня',
104 'uploader': 're:(?:Noize MC|Alexander Ilyashenko).*',
105 'uploader_id': '-77521',
106 'duration': 195,
107 'timestamp': 1329049880,
108 'upload_date': '20120212',
109 },
110 },
111 {
112 'url': 'http://vk.com/video205387401_165548505',
113 'info_dict': {
114 'id': '205387401_165548505',
115 'ext': 'mp4',
116 'title': 'No name',
117 'uploader': 'Tom Cruise',
118 'uploader_id': '205387401',
119 'duration': 9,
120 'timestamp': 1374364108,
121 'upload_date': '20130720',
122 }
123 },
124 {
125 'note': 'Embedded video',
126 'url': 'https://vk.com/video_ext.php?oid=-77521&id=162222515&hash=87b046504ccd8bfa',
127 'md5': '7babad3b85ea2e91948005b1b8b0cb84',
128 'info_dict': {
129 'id': '-77521_162222515',
130 'ext': 'mp4',
131 'uploader': 're:(?:Noize MC|Alexander Ilyashenko).*',
132 'title': 'ProtivoGunz - Хуёвая песня',
133 'duration': 195,
134 'upload_date': '20120212',
135 'timestamp': 1329049880,
136 'uploader_id': '-77521',
137 },
138 },
139 {
140 # VIDEO NOW REMOVED
141 # please update if you find a video whose URL follows the same pattern
142 'url': 'http://vk.com/video-8871596_164049491',
143 'md5': 'a590bcaf3d543576c9bd162812387666',
144 'note': 'Only available for registered users',
145 'info_dict': {
146 'id': '-8871596_164049491',
147 'ext': 'mp4',
148 'uploader': 'Триллеры',
149 'title': '► Бойцовский клуб / Fight Club 1999 [HD 720]',
150 'duration': 8352,
151 'upload_date': '20121218',
152 'view_count': int,
153 },
154 'skip': 'Removed',
155 },
156 {
157 'url': 'http://vk.com/hd_kino_mania?z=video-43215063_168067957%2F15c66b9b533119788d',
158 'info_dict': {
159 'id': '-43215063_168067957',
160 'ext': 'mp4',
161 'uploader': 'Bro Mazter',
162 'title': ' ',
163 'duration': 7291,
164 'upload_date': '20140328',
165 'uploader_id': '223413403',
166 'timestamp': 1396018030,
167 },
168 'skip': 'Requires vk account credentials',
169 },
170 {
171 'url': 'http://m.vk.com/video-43215063_169084319?list=125c627d1aa1cebb83&from=wall-43215063_2566540',
172 'md5': '0c45586baa71b7cb1d0784ee3f4e00a6',
173 'note': 'ivi.ru embed',
174 'info_dict': {
175 'id': '-43215063_169084319',
176 'ext': 'mp4',
177 'title': 'Книга Илая',
178 'duration': 6771,
179 'upload_date': '20140626',
180 'view_count': int,
181 },
182 'skip': 'Removed',
183 },
184 {
185 'url': 'https://vk.com/video-93049196_456239755?list=ln-cBjJ7S4jYYx3ADnmDT',
186 'info_dict': {
187 'id': '-93049196_456239755',
188 'ext': 'mp4',
189 'title': '8 серия (озвучка)',
190 'duration': 8383,
191 'upload_date': '20211222',
192 'view_count': int,
193 },
194 },
195 {
196 # video (removed?) only available with list id
197 'url': 'https://vk.com/video30481095_171201961?list=8764ae2d21f14088d4',
198 'md5': '091287af5402239a1051c37ec7b92913',
199 'info_dict': {
200 'id': '30481095_171201961',
201 'ext': 'mp4',
202 'title': 'ТюменцевВВ_09.07.2015',
203 'uploader': 'Anton Ivanov',
204 'duration': 109,
205 'upload_date': '20150709',
206 'view_count': int,
207 },
208 'skip': 'Removed',
209 },
210 {
211 # youtube embed
212 'url': 'https://vk.com/video276849682_170681728',
213 'info_dict': {
214 'id': 'V3K4mi0SYkc',
215 'ext': 'mp4',
216 'title': "DSWD Awards 'Children's Joy Foundation, Inc.' Certificate of Registration and License to Operate",
217 'description': 'md5:bf9c26cfa4acdfb146362682edd3827a',
218 'duration': 178,
219 'upload_date': '20130116',
220 'uploader': "Children's Joy Foundation Inc.",
221 'uploader_id': 'thecjf',
222 'view_count': int,
223 },
224 },
225 {
226 # dailymotion embed
227 'url': 'https://vk.com/video-37468416_456239855',
228 'info_dict': {
229 'id': 'k3lz2cmXyRuJQSjGHUv',
230 'ext': 'mp4',
231 'title': 'md5:d52606645c20b0ddbb21655adaa4f56f',
232 'description': 'md5:424b8e88cc873217f520e582ba28bb36',
233 'uploader': 'AniLibria.Tv',
234 'upload_date': '20160914',
235 'uploader_id': 'x1p5vl5',
236 'timestamp': 1473877246,
237 },
238 'params': {
239 'skip_download': True,
240 },
241 },
242 {
243 # video key is extra_data not url\d+
244 'url': 'http://vk.com/video-110305615_171782105',
245 'md5': 'e13fcda136f99764872e739d13fac1d1',
246 'info_dict': {
247 'id': '-110305615_171782105',
248 'ext': 'mp4',
249 'title': 'S-Dance, репетиции к The way show',
250 'uploader': 'THE WAY SHOW | 17 апреля',
251 'uploader_id': '-110305615',
252 'timestamp': 1454859345,
253 'upload_date': '20160207',
254 },
255 'params': {
256 'skip_download': True,
257 },
258 },
259 {
260 # finished live stream, postlive_mp4
261 'url': 'https://vk.com/videos-387766?z=video-387766_456242764%2Fpl_-387766_-2',
262 'info_dict': {
263 'id': '-387766_456242764',
264 'ext': 'mp4',
265 'title': 'ИгроМир 2016 День 1 — Игромания Утром',
266 'uploader': 'Игромания',
267 'duration': 5239,
268 # TODO: use act=show to extract view_count
269 # 'view_count': int,
270 'upload_date': '20160929',
271 'uploader_id': '-387766',
272 'timestamp': 1475137527,
273 },
274 'params': {
275 'skip_download': True,
276 },
277 },
278 {
279 # live stream, hls and rtmp links, most likely already finished live
280 # stream by the time you are reading this comment
281 'url': 'https://vk.com/video-140332_456239111',
282 'only_matching': True,
283 },
284 {
285 # removed video, just testing that we match the pattern
286 'url': 'http://vk.com/feed?z=video-43215063_166094326%2Fbb50cacd3177146d7a',
287 'only_matching': True,
288 },
289 {
290 # age restricted video, requires vk account credentials
291 'url': 'https://vk.com/video205387401_164765225',
292 'only_matching': True,
293 },
294 {
295 # pladform embed
296 'url': 'https://vk.com/video-76116461_171554880',
297 'only_matching': True,
298 },
299 {
300 'url': 'http://new.vk.com/video205387401_165548505',
301 'only_matching': True,
302 },
303 {
304 # This video is no longer available, because its author has been blocked.
305 'url': 'https://vk.com/video-10639516_456240611',
306 'only_matching': True,
307 },
308 {
309 # The video is not available in your region.
310 'url': 'https://vk.com/video-51812607_171445436',
311 'only_matching': True,
312 },
313 {
314 'url': 'https://vk.com/clip30014565_456240946',
315 'only_matching': True,
316 }]
317
318 @staticmethod
319 def _extract_sibnet_urls(webpage):
320 # https://help.sibnet.ru/?sibnet_video_embed
321 return [unescapeHTML(mobj.group('url')) for mobj in re.finditer(
322 r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//video\.sibnet\.ru/shell\.php\?.*?\bvideoid=\d+.*?)\1',
323 webpage)]
324
325 def _real_extract(self, url):
326 mobj = self._match_valid_url(url)
327 video_id = mobj.group('videoid')
328
329 mv_data = {}
330 if video_id:
331 data = {
332 'act': 'show_inline',
333 'video': video_id,
334 }
335 # Some videos (removed?) can only be downloaded with list id specified
336 list_id = mobj.group('list_id')
337 if list_id:
338 data['list'] = list_id
339
340 payload = self._download_payload('al_video', video_id, data)
341 info_page = payload[1]
342 opts = payload[-1]
343 mv_data = opts.get('mvData') or {}
344 player = opts.get('player') or {}
345 else:
346 video_id = '%s_%s' % (mobj.group('oid'), mobj.group('id'))
347
348 info_page = self._download_webpage(
349 'http://vk.com/video_ext.php?' + mobj.group('embed_query'), video_id)
350
351 error_message = self._html_search_regex(
352 [r'(?s)<!><div[^>]+class="video_layer_message"[^>]*>(.+?)</div>',
353 r'(?s)<div[^>]+id="video_ext_msg"[^>]*>(.+?)</div>'],
354 info_page, 'error message', default=None)
355 if error_message:
356 raise ExtractorError(error_message, expected=True)
357
358 if re.search(r'<!>/login\.php\?.*\bact=security_check', info_page):
359 raise ExtractorError(
360 'You are trying to log in from an unusual location. You should confirm ownership at vk.com to log in with this IP.',
361 expected=True)
362
363 ERROR_COPYRIGHT = 'Video %s has been removed from public access due to rightholder complaint.'
364
365 ERRORS = {
366 r'>Видеозапись .*? была изъята из публичного доступа в связи с обращением правообладателя.<':
367 ERROR_COPYRIGHT,
368
369 r'>The video .*? was removed from public access by request of the copyright holder.<':
370 ERROR_COPYRIGHT,
371
372 r'<!>Please log in or <':
373 'Video %s is only available for registered users, '
374 'use --username and --password options to provide account credentials.',
375
376 r'<!>Unknown error':
377 'Video %s does not exist.',
378
379 r'<!>Видео временно недоступно':
380 'Video %s is temporarily unavailable.',
381
382 r'<!>Access denied':
383 'Access denied to video %s.',
384
385 r'<!>Видеозапись недоступна, так как её автор был заблокирован.':
386 'Video %s is no longer available, because its author has been blocked.',
387
388 r'<!>This video is no longer available, because its author has been blocked.':
389 'Video %s is no longer available, because its author has been blocked.',
390
391 r'<!>This video is no longer available, because it has been deleted.':
392 'Video %s is no longer available, because it has been deleted.',
393
394 r'<!>The video .+? is not available in your region.':
395 'Video %s is not available in your region.',
396 }
397
398 for error_re, error_msg in ERRORS.items():
399 if re.search(error_re, info_page):
400 raise ExtractorError(error_msg % video_id, expected=True)
401
402 player = self._parse_json(self._search_regex(
403 r'var\s+playerParams\s*=\s*({.+?})\s*;\s*\n',
404 info_page, 'player params'), video_id)
405
406 youtube_url = YoutubeIE._extract_url(info_page)
407 if youtube_url:
408 return self.url_result(youtube_url, YoutubeIE.ie_key())
409
410 vimeo_url = VimeoIE._extract_url(url, info_page)
411 if vimeo_url is not None:
412 return self.url_result(vimeo_url, VimeoIE.ie_key())
413
414 pladform_url = PladformIE._extract_url(info_page)
415 if pladform_url:
416 return self.url_result(pladform_url, PladformIE.ie_key())
417
418 m_rutube = re.search(
419 r'\ssrc="((?:https?:)?//rutube\.ru\\?/(?:video|play)\\?/embed(?:.*?))\\?"', info_page)
420 if m_rutube is not None:
421 rutube_url = self._proto_relative_url(
422 m_rutube.group(1).replace('\\', ''))
423 return self.url_result(rutube_url)
424
425 dailymotion_urls = DailymotionIE._extract_urls(info_page)
426 if dailymotion_urls:
427 return self.url_result(dailymotion_urls[0], DailymotionIE.ie_key())
428
429 odnoklassniki_url = OdnoklassnikiIE._extract_url(info_page)
430 if odnoklassniki_url:
431 return self.url_result(odnoklassniki_url, OdnoklassnikiIE.ie_key())
432
433 sibnet_urls = self._extract_sibnet_urls(info_page)
434 if sibnet_urls:
435 return self.url_result(sibnet_urls[0])
436
437 m_opts = re.search(r'(?s)var\s+opts\s*=\s*({.+?});', info_page)
438 if m_opts:
439 m_opts_url = re.search(r"url\s*:\s*'((?!/\b)[^']+)", m_opts.group(1))
440 if m_opts_url:
441 opts_url = m_opts_url.group(1)
442 if opts_url.startswith('//'):
443 opts_url = 'http:' + opts_url
444 return self.url_result(opts_url)
445
446 data = player['params'][0]
447 title = unescapeHTML(data['md_title'])
448
449 # 2 = live
450 # 3 = post live (finished live)
451 is_live = data.get('live') == 2
452
453 timestamp = unified_timestamp(self._html_search_regex(
454 r'class=["\']mv_info_date[^>]+>([^<]+)(?:<|from)', info_page,
455 'upload date', default=None)) or int_or_none(data.get('date'))
456
457 view_count = str_to_int(self._search_regex(
458 r'class=["\']mv_views_count[^>]+>\s*([\d,.]+)',
459 info_page, 'view count', default=None))
460
461 formats = []
462 for format_id, format_url in data.items():
463 format_url = url_or_none(format_url)
464 if not format_url or not format_url.startswith(('http', '//', 'rtmp')):
465 continue
466 if (format_id.startswith(('url', 'cache'))
467 or format_id in ('extra_data', 'live_mp4', 'postlive_mp4')):
468 height = int_or_none(self._search_regex(
469 r'^(?:url|cache)(\d+)', format_id, 'height', default=None))
470 formats.append({
471 'format_id': format_id,
472 'url': format_url,
473 'height': height,
474 })
475 elif format_id == 'hls':
476 formats.extend(self._extract_m3u8_formats(
477 format_url, video_id, 'mp4', 'm3u8_native',
478 m3u8_id=format_id, fatal=False, live=is_live))
479 elif format_id == 'rtmp':
480 formats.append({
481 'format_id': format_id,
482 'url': format_url,
483 'ext': 'flv',
484 })
485 self._sort_formats(formats)
486
487 subtitles = {}
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')),
492 })
493
494 return {
495 'id': video_id,
496 'formats': formats,
497 'title': title,
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')),
506 'is_live': is_live,
507 'subtitles': subtitles,
508 }
509
510
511 class VKUserVideosIE(VKBaseIE):
512 IE_NAME = 'vk:uservideos'
513 IE_DESC = "VK - User's Videos"
514 _VALID_URL = r'https?://(?:(?:m|new)\.)?vk\.com/videos(?P<id>-?[0-9]+)(?!\?.*\bz=video)(?:[/?#&](?:.*?\bsection=(?P<section>\w+))?|$)'
515 _TEMPLATE_URL = 'https://vk.com/videos'
516 _TESTS = [{
517 'url': 'https://vk.com/videos-767561',
518 'info_dict': {
519 'id': '-767561_all',
520 },
521 'playlist_mincount': 1150,
522 }, {
523 'url': 'https://vk.com/videos-767561?section=uploaded',
524 'info_dict': {
525 'id': '-767561_uploaded',
526 },
527 'playlist_mincount': 425,
528 }, {
529 'url': 'http://vk.com/videos205387401',
530 'only_matching': True,
531 }, {
532 'url': 'http://vk.com/videos-77521',
533 'only_matching': True,
534 }, {
535 'url': 'http://vk.com/videos-97664626?section=all',
536 'only_matching': True,
537 }, {
538 'url': 'http://m.vk.com/videos205387401',
539 'only_matching': True,
540 }, {
541 'url': 'http://new.vk.com/videos205387401',
542 'only_matching': True,
543 }]
544 _PAGE_SIZE = 1000
545 _VIDEO = collections.namedtuple('Video', ['owner_id', 'id'])
546
547 def _fetch_page(self, page_id, section, page):
548 l = self._download_payload('al_video', page_id, {
549 'act': 'load_videos_silent',
550 'offset': page * self._PAGE_SIZE,
551 'oid': page_id,
552 'section': section,
553 })[0][section]['list']
554
555 for video in l:
556 v = self._VIDEO._make(video[:2])
557 video_id = '%d_%d' % (v.owner_id, v.id)
558 yield self.url_result(
559 'http://vk.com/video' + video_id, VKIE.ie_key(), video_id)
560
561 def _real_extract(self, url):
562 page_id, section = self._match_valid_url(url).groups()
563 if not section:
564 section = 'all'
565
566 entries = OnDemandPagedList(
567 functools.partial(self._fetch_page, page_id, section),
568 self._PAGE_SIZE)
569
570 return self.playlist_result(entries, '%s_%s' % (page_id, section))
571
572
573 class VKWallPostIE(VKBaseIE):
574 IE_NAME = 'vk:wallpost'
575 _VALID_URL = r'https?://(?:(?:(?:(?:m|new)\.)?vk\.com/(?:[^?]+\?.*\bw=)?wall(?P<id>-?\d+_\d+)))'
576 _TESTS = [{
577 # public page URL, audio playlist
578 'url': 'https://vk.com/bs.official?w=wall-23538238_35',
579 'info_dict': {
580 'id': '-23538238_35',
581 'title': 'Black Shadow - Wall post -23538238_35',
582 'description': 'md5:3f84b9c4f9ef499731cf1ced9998cc0c',
583 },
584 'playlist': [{
585 'md5': '5ba93864ec5b85f7ce19a9af4af080f6',
586 'info_dict': {
587 'id': '135220665_111806521',
588 'ext': 'mp4',
589 'title': 'Black Shadow - Слепое Верование',
590 'duration': 370,
591 'uploader': 'Black Shadow',
592 'artist': 'Black Shadow',
593 'track': 'Слепое Верование',
594 },
595 }, {
596 'md5': '4cc7e804579122b17ea95af7834c9233',
597 'info_dict': {
598 'id': '135220665_111802303',
599 'ext': 'mp4',
600 'title': 'Black Shadow - Война - Негасимое Бездны Пламя!',
601 'duration': 423,
602 'uploader': 'Black Shadow',
603 'artist': 'Black Shadow',
604 'track': 'Война - Негасимое Бездны Пламя!',
605 },
606 }],
607 'params': {
608 'skip_download': True,
609 'usenetrc': True,
610 },
611 'skip': 'Requires vk account credentials',
612 }, {
613 # single YouTube embed, no leading -
614 'url': 'https://vk.com/wall85155021_6319',
615 'info_dict': {
616 'id': '85155021_6319',
617 'title': 'Сергей Горбунов - Wall post 85155021_6319',
618 },
619 'playlist_count': 1,
620 'params': {
621 'usenetrc': True,
622 },
623 'skip': 'Requires vk account credentials',
624 }, {
625 # wall page URL
626 'url': 'https://vk.com/wall-23538238_35',
627 'only_matching': True,
628 }, {
629 # mobile wall page URL
630 'url': 'https://m.vk.com/wall-23538238_35',
631 'only_matching': True,
632 }]
633 _BASE64_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN0PQRSTUVWXYZO123456789+/='
634 _AUDIO = collections.namedtuple('Audio', ['id', 'owner_id', 'url', 'title', 'performer', 'duration', 'album_id', 'unk', 'author_link', 'lyrics', 'flags', 'context', 'extra', 'hashes', 'cover_url', 'ads'])
635
636 def _decode(self, enc):
637 dec = ''
638 e = n = 0
639 for c in enc:
640 r = self._BASE64_CHARS.index(c)
641 cond = n % 4
642 e = 64 * e + r if cond else r
643 n += 1
644 if cond:
645 dec += chr(255 & e >> (-2 * n & 6))
646 return dec
647
648 def _unmask_url(self, mask_url, vk_id):
649 if 'audio_api_unavailable' in mask_url:
650 extra = mask_url.split('?extra=')[1].split('#')
651 func, base = self._decode(extra[1]).split(chr(11))
652 mask_url = list(self._decode(extra[0]))
653 url_len = len(mask_url)
654 indexes = [None] * url_len
655 index = int(base) ^ vk_id
656 for n in range(url_len - 1, -1, -1):
657 index = (url_len * (n + 1) ^ index + n) % url_len
658 indexes[n] = index
659 for n in range(1, url_len):
660 c = mask_url[n]
661 index = indexes[url_len - 1 - n]
662 mask_url[n] = mask_url[index]
663 mask_url[index] = c
664 mask_url = ''.join(mask_url)
665 return mask_url
666
667 def _real_extract(self, url):
668 post_id = self._match_id(url)
669
670 webpage = self._download_payload('wkview', post_id, {
671 'act': 'show',
672 'w': 'wall' + post_id,
673 })[1]
674
675 description = clean_html(get_element_by_class('wall_post_text', webpage))
676 uploader = clean_html(get_element_by_class('author', webpage))
677
678 entries = []
679
680 for audio in re.findall(r'data-audio="([^"]+)', webpage):
681 audio = self._parse_json(unescapeHTML(audio), post_id)
682 a = self._AUDIO._make(audio[:16])
683 if not a.url:
684 continue
685 title = unescapeHTML(a.title)
686 performer = unescapeHTML(a.performer)
687 entries.append({
688 'id': '%s_%s' % (a.owner_id, a.id),
689 'url': self._unmask_url(a.url, a.ads['vk_id']),
690 'title': '%s - %s' % (performer, title) if performer else title,
691 'thumbnails': [{'url': c_url} for c_url in a.cover_url.split(',')] if a.cover_url else None,
692 'duration': int_or_none(a.duration),
693 'uploader': uploader,
694 'artist': performer,
695 'track': title,
696 'ext': 'mp4',
697 'protocol': 'm3u8',
698 })
699
700 for video in re.finditer(
701 r'<a[^>]+href=(["\'])(?P<url>/video(?:-?[\d_]+).*?)\1', webpage):
702 entries.append(self.url_result(
703 compat_urlparse.urljoin(url, video.group('url')), VKIE.ie_key()))
704
705 title = 'Wall post %s' % post_id
706
707 return self.playlist_result(
708 orderedSet(entries), post_id,
709 '%s - %s' % (uploader, title) if uploader else title,
710 description)