shared.py 2.1 KB

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