vshare.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from .common import InfoExtractor
  2. from ..utils import ExtractorError, decode_packed_codes
  3. class VShareIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?vshare\.io/[dv]/(?P<id>[^/?#&]+)'
  5. _EMBED_REGEX = [r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?vshare\.io/v/[^/?#&]+)']
  6. _TESTS = [{
  7. 'url': 'https://vshare.io/d/0f64ce6',
  8. 'md5': '17b39f55b5497ae8b59f5fbce8e35886',
  9. 'info_dict': {
  10. 'id': '0f64ce6',
  11. 'title': 'vl14062007715967',
  12. 'ext': 'mp4',
  13. }
  14. }, {
  15. 'url': 'https://vshare.io/v/0f64ce6/width-650/height-430/1',
  16. 'only_matching': True,
  17. }]
  18. def _extract_packed(self, webpage):
  19. packed = self._search_regex(
  20. r'(eval\(function.+)', webpage, 'packed code')
  21. unpacked = decode_packed_codes(packed)
  22. digits = self._search_regex(r'\[((?:\d+,?)+)\]', unpacked, 'digits')
  23. digits = [int(digit) for digit in digits.split(',')]
  24. key_digit = self._search_regex(
  25. r'fromCharCode\(.+?(\d+)\)}', unpacked, 'key digit')
  26. chars = [chr(d - int(key_digit)) for d in digits]
  27. return ''.join(chars)
  28. def _real_extract(self, url):
  29. video_id = self._match_id(url)
  30. webpage = self._download_webpage(
  31. 'https://vshare.io/v/%s/width-650/height-430/1' % video_id,
  32. video_id, headers={'Referer': url})
  33. title = self._html_extract_title(webpage)
  34. title = title.split(' - ')[0]
  35. error = self._html_search_regex(
  36. r'(?s)<div[^>]+\bclass=["\']xxx-error[^>]+>(.+?)</div', webpage,
  37. 'error', default=None)
  38. if error:
  39. raise ExtractorError(error, expected=True)
  40. info = self._parse_html5_media_entries(
  41. url, '<video>%s</video>' % self._extract_packed(webpage),
  42. video_id)[0]
  43. info.update({
  44. 'id': video_id,
  45. 'title': title,
  46. })
  47. return info