You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB

10 years ago
  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. 'filesize': 1720110,
  23. },
  24. }, {
  25. 'url': 'http://vivo.sx/d7ddda0e78',
  26. 'md5': '15b3af41be0b4fe01f4df075c2678b2c',
  27. 'info_dict': {
  28. 'id': 'd7ddda0e78',
  29. 'ext': 'mp4',
  30. 'title': 'Chicken',
  31. 'filesize': 528031,
  32. },
  33. }]
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url)
  36. webpage = self._download_webpage(url, video_id)
  37. if '>File does not exist<' in webpage:
  38. raise ExtractorError(
  39. 'Video %s does not exist' % video_id, expected=True)
  40. download_form = self._hidden_inputs(webpage)
  41. request = compat_urllib_request.Request(
  42. url, compat_urllib_parse.urlencode(download_form))
  43. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  44. video_page = self._download_webpage(
  45. request, video_id, 'Downloading video page')
  46. video_url = self._html_search_regex(
  47. r'data-url="([^"]+)"', video_page, 'video URL')
  48. title = base64.b64decode(self._html_search_meta(
  49. 'full:title', webpage, 'title').encode('utf-8')).decode('utf-8')
  50. filesize = int_or_none(self._html_search_meta(
  51. 'full:size', webpage, 'file size', fatal=False))
  52. thumbnail = self._html_search_regex(
  53. r'data-poster="([^"]+)"', video_page, 'thumbnail', default=None)
  54. return {
  55. 'id': video_id,
  56. 'url': video_url,
  57. 'ext': 'mp4',
  58. 'filesize': filesize,
  59. 'title': title,
  60. 'thumbnail': thumbnail,
  61. }