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.

61 lines
1.8 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. _VALID_URL = r'http://shared\.sx/(?P<id>[\da-z]{10})'
  14. _TEST = {
  15. 'url': 'http://shared.sx/0060718775',
  16. 'md5': '106fefed92a8a2adb8c98e6a0652f49b',
  17. 'info_dict': {
  18. 'id': '0060718775',
  19. 'ext': 'mp4',
  20. 'title': 'Bmp4',
  21. },
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. webpage = self._download_webpage(url, video_id)
  26. if '>File does not exist<' in webpage:
  27. raise ExtractorError(
  28. 'Video %s does not exist' % video_id, expected=True)
  29. download_form = self._hidden_inputs(webpage)
  30. request = compat_urllib_request.Request(
  31. url, compat_urllib_parse.urlencode(download_form))
  32. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  33. video_page = self._download_webpage(
  34. request, video_id, 'Downloading video page')
  35. video_url = self._html_search_regex(
  36. r'data-url="([^"]+)"', video_page, 'video URL')
  37. title = base64.b64decode(self._html_search_meta(
  38. 'full:title', webpage, 'title').encode('utf-8')).decode('utf-8')
  39. filesize = int_or_none(self._html_search_meta(
  40. 'full:size', webpage, 'file size', fatal=False))
  41. thumbnail = self._html_search_regex(
  42. r'data-poster="([^"]+)"', video_page, 'thumbnail', default=None)
  43. return {
  44. 'id': video_id,
  45. 'url': video_url,
  46. 'ext': 'mp4',
  47. 'filesize': filesize,
  48. 'title': title,
  49. 'thumbnail': thumbnail,
  50. }