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.

45 lines
1.4 KiB

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