shared.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from __future__ import unicode_literals
  2. import base64
  3. from .common import InfoExtractor
  4. from ..compat import compat_urllib_parse_urlencode
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. sanitized_Request,
  9. )
  10. class SharedIE(InfoExtractor):
  11. IE_DESC = 'shared.sx and vivo.sx'
  12. _VALID_URL = r'https?://(?:shared|vivo)\.sx/(?P<id>[\da-z]{10})'
  13. _TESTS = [{
  14. 'url': 'http://shared.sx/0060718775',
  15. 'md5': '106fefed92a8a2adb8c98e6a0652f49b',
  16. 'info_dict': {
  17. 'id': '0060718775',
  18. 'ext': 'mp4',
  19. 'title': 'Bmp4',
  20. 'filesize': 1720110,
  21. },
  22. }, {
  23. 'url': 'http://vivo.sx/d7ddda0e78',
  24. 'md5': '15b3af41be0b4fe01f4df075c2678b2c',
  25. 'info_dict': {
  26. 'id': 'd7ddda0e78',
  27. 'ext': 'mp4',
  28. 'title': 'Chicken',
  29. 'filesize': 528031,
  30. },
  31. }]
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. webpage = self._download_webpage(url, video_id)
  35. if '>File does not exist<' in webpage:
  36. raise ExtractorError(
  37. 'Video %s does not exist' % video_id, expected=True)
  38. download_form = self._hidden_inputs(webpage)
  39. request = sanitized_Request(
  40. url, compat_urllib_parse_urlencode(download_form))
  41. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  42. video_page = self._download_webpage(
  43. request, video_id, 'Downloading video page')
  44. video_url = self._html_search_regex(
  45. r'data-url="([^"]+)"', video_page, 'video URL')
  46. title = base64.b64decode(self._html_search_meta(
  47. 'full:title', webpage, 'title').encode('utf-8')).decode('utf-8')
  48. filesize = int_or_none(self._html_search_meta(
  49. 'full:size', webpage, 'file size', fatal=False))
  50. thumbnail = self._html_search_regex(
  51. r'data-poster="([^"]+)"', video_page, 'thumbnail', default=None)
  52. return {
  53. 'id': video_id,
  54. 'url': video_url,
  55. 'ext': 'mp4',
  56. 'filesize': filesize,
  57. 'title': title,
  58. 'thumbnail': thumbnail,
  59. }