vshare.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 (
  7. decode_packed_codes,
  8. ExtractorError,
  9. )
  10. class VShareIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?vshare\.io/[dv]/(?P<id>[^/?#&]+)'
  12. _TESTS = [{
  13. 'url': 'https://vshare.io/d/0f64ce6',
  14. 'md5': '17b39f55b5497ae8b59f5fbce8e35886',
  15. 'info_dict': {
  16. 'id': '0f64ce6',
  17. 'title': 'vl14062007715967',
  18. 'ext': 'mp4',
  19. }
  20. }, {
  21. 'url': 'https://vshare.io/v/0f64ce6/width-650/height-430/1',
  22. 'only_matching': True,
  23. }]
  24. def _extract_packed(self, webpage):
  25. packed = self._search_regex(r'(eval\(function.+)', webpage, 'packed code')
  26. unpacked = decode_packed_codes(packed)
  27. digits = self._search_regex(r'\[((?:\d+,?)+)\]', unpacked, 'digits')
  28. digits = digits.split(',')
  29. digits = [int(digit) for digit in digits]
  30. key_digit = self._search_regex(r'fromCharCode\(.+?(\d+)\)}', unpacked, 'key digit')
  31. chars = [compat_chr(d - int(key_digit)) for d in digits]
  32. return ''.join(chars)
  33. def _real_extract(self, url):
  34. video_id = self._match_id(url)
  35. webpage = self._download_webpage(
  36. 'https://vshare.io/v/%s/width-650/height-430/1' % video_id, video_id)
  37. title = self._html_search_regex(r'<title>([^<]+)</title>', webpage, 'title')
  38. title = title.split(' - ')[0]
  39. error = self._html_search_regex(
  40. r'(?s)<div[^>]+\bclass=["\']xxx-error[^>]+>(.+?)</div', webpage,
  41. 'error', default=None)
  42. if error:
  43. raise ExtractorError(error, expected=True)
  44. unpacked = self._extract_packed(webpage)
  45. video_urls = re.findall(r'<source src="([^"]+)', unpacked)
  46. formats = [{'url': video_url} for video_url in video_urls]
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'formats': formats,
  51. }
  52. @staticmethod
  53. def _extract_urls(webpage):
  54. return re.findall(
  55. r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?vshare\.io/v/[^/?#&]+)',
  56. webpage)