+ for video_id in orderedSet(re.findall(r'href="/video(-?[0-9_]+)"', webpage))]
+
+ title = unescapeHTML(self._search_regex(
+ r'<title>\s*([^<]+?)\s+\|\s+\d+\s+videos',
+ webpage, 'title', default=page_id))
+
+ return self.playlist_result(entries, page_id, title)
+
+
+class VKWallPostIE(VKBaseIE):
+ IE_NAME = 'vk:wallpost'
+ _VALID_URL = r'https?://(?:(?:(?:(?:m|new)\.)?vk\.com/(?:[^?]+\?.*\bw=)?wall(?P<id>-?\d+_\d+)))'
+ _TESTS = [{
+ # public page URL, audio playlist
+ 'url': 'https://vk.com/bs.official?w=wall-23538238_35',
+ 'info_dict': {
+ 'id': '23538238_35',
+ 'title': 'Black Shadow - Wall post 23538238_35',
+ 'description': 'md5:3f84b9c4f9ef499731cf1ced9998cc0c',
+ },
+ 'playlist': [{
+ 'md5': '5ba93864ec5b85f7ce19a9af4af080f6',
+ 'info_dict': {
+ 'id': '135220665_111806521',
+ 'ext': 'mp3',
+ 'title': 'Black Shadow - Слепое Верование',
+ 'duration': 370,
+ 'uploader': 'Black Shadow',
+ 'artist': 'Black Shadow',
+ 'track': 'Слепое Верование',
+ },
+ }, {
+ 'md5': '4cc7e804579122b17ea95af7834c9233',
+ 'info_dict': {
+ 'id': '135220665_111802303',
+ 'ext': 'mp3',
+ 'title': 'Black Shadow - Война - Негасимое Бездны Пламя!',
+ 'duration': 423,
+ 'uploader': 'Black Shadow',
+ 'artist': 'Black Shadow',
+ 'track': 'Война - Негасимое Бездны Пламя!',
+ },
+ 'params': {
+ 'skip_download': True,
+ },
+ }],
+ 'params': {
+ 'usenetrc': True,
+ },
+ 'skip': 'Requires vk account credentials',
+ }, {
+ # single YouTube embed, no leading -
+ 'url': 'https://vk.com/wall85155021_6319',
+ 'info_dict': {
+ 'id': '85155021_6319',
+ 'title': 'Sergey Gorbunov - Wall post 85155021_6319',
+ },
+ 'playlist_count': 1,
+ 'params': {
+ 'usenetrc': True,
+ },
+ 'skip': 'Requires vk account credentials',
+ }, {
+ # wall page URL
+ 'url': 'https://vk.com/wall-23538238_35',
+ 'only_matching': True,
+ }, {
+ # mobile wall page URL
+ 'url': 'https://m.vk.com/wall-23538238_35',
+ 'only_matching': True,
+ }]
+
+ def _real_extract(self, url):
+ post_id = self._match_id(url)
+
+ wall_url = 'https://vk.com/wall%s' % post_id
+
+ post_id = remove_start(post_id, '-')
+
+ webpage = self._download_webpage(wall_url, post_id)
+
+ error = self._html_search_regex(
+ r'>Error</div>\s*<div[^>]+class=["\']body["\'][^>]*>([^<]+)',
+ webpage, 'error', default=None)
+ if error:
+ raise ExtractorError('VK said: %s' % error, expected=True)
+
+ description = clean_html(get_element_by_class('wall_post_text', webpage))
+ uploader = clean_html(get_element_by_class('author', webpage))
+ thumbnail = self._og_search_thumbnail(webpage)
+
+ entries = []
+
+ audio_ids = re.findall(r'data-full-id=["\'](\d+_\d+)', webpage)
+ if audio_ids:
+ al_audio = self._download_webpage(
+ 'https://vk.com/al_audio.php', post_id,
+ note='Downloading audio info', fatal=False,
+ data=urlencode_postdata({
+ 'act': 'reload_audio',
+ 'al': '1',
+ 'ids': ','.join(audio_ids)
+ }))
+ if al_audio:
+ Audio = collections.namedtuple(
+ 'Audio', ['id', 'user_id', 'url', 'track', 'artist', 'duration'])
+ audios = self._parse_json(
+ self._search_regex(
+ r'<!json>(.+?)<!>', al_audio, 'audios', default='[]'),
+ post_id, fatal=False, transform_source=unescapeHTML)
+ if isinstance(audios, list):
+ for audio in audios:
+ a = Audio._make(audio[:6])
+ entries.append({
+ 'id': '%s_%s' % (a.user_id, a.id),
+ 'url': a.url,
+ 'title': '%s - %s' % (a.artist, a.track) if a.artist and a.track else a.id,
+ 'thumbnail': thumbnail,
+ 'duration': a.duration,
+ 'uploader': uploader,
+ 'artist': a.artist,
+ 'track': a.track,
+ })
+
+ for video in re.finditer(
+ r'<a[^>]+href=(["\'])(?P<url>/video(?:-?[\d_]+).*?)\1', webpage):
+ entries.append(self.url_result(
+ compat_urlparse.urljoin(url, video.group('url')), VKIE.ie_key()))
+
+ title = 'Wall post %s' % post_id
+
+ return self.playlist_result(
+ orderedSet(entries), post_id,
+ '%s - %s' % (uploader, title) if uploader else title,
+ description)