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.

63 lines
1.9 KiB

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