vshare.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_chr
  6. from ..utils import decode_packed_codes
  7. class VShareIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?vshare\.io/[dv]/(?P<id>[^/?#&]+)'
  9. _TESTS = [{
  10. 'url': 'https://vshare.io/d/0f64ce6',
  11. 'md5': '17b39f55b5497ae8b59f5fbce8e35886',
  12. 'info_dict': {
  13. 'id': '0f64ce6',
  14. 'title': 'vl14062007715967',
  15. 'ext': 'mp4',
  16. }
  17. }, {
  18. 'url': 'https://vshare.io/v/0f64ce6/width-650/height-430/1',
  19. 'only_matching': True,
  20. }]
  21. def _extract_packed(self, webpage):
  22. packed = self._search_regex(r'(eval\(function.+)', webpage, 'packed code')
  23. unpacked = decode_packed_codes(packed)
  24. digits = self._search_regex(r'\[((?:\d+,?)+)\]', unpacked, 'digits')
  25. digits = digits.split(',')
  26. digits = [int(digit) for digit in digits]
  27. key_digit = self._search_regex(r'fromCharCode\(.+?(\d+)\)}', unpacked, 'key digit')
  28. chars = [compat_chr(d - int(key_digit)) for d in digits]
  29. return ''.join(chars)
  30. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(
  33. 'https://vshare.io/v/%s/width-650/height-430/1' % video_id, video_id)
  34. title = self._html_search_regex(r'<title>([^<]+)</title>', webpage, 'title')
  35. title = title.split(' - ')[0]
  36. unpacked = self._extract_packed(webpage)
  37. video_urls = re.findall(r'<source src="([^"]+)', unpacked)
  38. formats = [{'url': video_url} for video_url in video_urls]
  39. return {
  40. 'id': video_id,
  41. 'title': title,
  42. 'formats': formats,
  43. }
  44. @staticmethod
  45. def _extract_urls(webpage):
  46. return re.findall(
  47. r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?vshare\.io/v/[^/?#&]+)',
  48. webpage)