]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vk.py
debian/control: Add dependency on python-pkg-resources.
[youtubedl] / youtube_dl / extractor / vk.py
1 # encoding: utf-8
2 import re
3 import json
4
5 from .common import InfoExtractor
6 from ..utils import (
7 compat_str,
8 unescapeHTML,
9 )
10
11
12 class VKIE(InfoExtractor):
13 IE_NAME = u'vk.com'
14 _VALID_URL = r'https?://vk\.com/(?:videos.*?\?.*?z=)?video(?P<id>.*?)(?:\?|%2F|$)'
15
16 _TEST = {
17 u'url': u'http://vk.com/videos-77521?z=video-77521_162222515%2Fclub77521',
18 u'md5': u'0deae91935c54e00003c2a00646315f0',
19 u'info_dict': {
20 u'id': u'162222515',
21 u'ext': u'flv',
22 u'title': u'ProtivoGunz - Хуёвая песня',
23 u'uploader': u'Noize MC',
24 },
25 }
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
30 info_url = 'http://vk.com/al_video.php?act=show&al=1&video=%s' % video_id
31 info_page = self._download_webpage(info_url, video_id)
32 m_yt = re.search(r'src="(http://www.youtube.com/.*?)"', info_page)
33 if m_yt is not None:
34 self.to_screen(u'Youtube video detected')
35 return self.url_result(m_yt.group(1), 'Youtube')
36 vars_json = self._search_regex(r'var vars = ({.*?});', info_page, u'vars')
37 vars = json.loads(vars_json)
38
39 return {
40 'id': compat_str(vars['vid']),
41 'url': vars['url240'],
42 'title': unescapeHTML(vars['md_title']),
43 'thumbnail': vars['jpg'],
44 'uploader': vars['md_author'],
45 }