You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

660 lines
25 KiB

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