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.

74 lines
2.2 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import base64
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. int_or_none,
  7. urlencode_postdata,
  8. )
  9. class SharedIE(InfoExtractor):
  10. IE_DESC = 'shared.sx and vivo.sx'
  11. _VALID_URL = r'https?://(?:shared|vivo)\.sx/(?P<id>[\da-z]{10})'
  12. _TESTS = [{
  13. 'url': 'http://shared.sx/0060718775',
  14. 'md5': '106fefed92a8a2adb8c98e6a0652f49b',
  15. 'info_dict': {
  16. 'id': '0060718775',
  17. 'ext': 'mp4',
  18. 'title': 'Bmp4',
  19. 'filesize': 1720110,
  20. },
  21. }, {
  22. 'url': 'http://vivo.sx/d7ddda0e78',
  23. 'md5': '15b3af41be0b4fe01f4df075c2678b2c',
  24. 'info_dict': {
  25. 'id': 'd7ddda0e78',
  26. 'ext': 'mp4',
  27. 'title': 'Chicken',
  28. 'filesize': 528031,
  29. },
  30. }]
  31. def _real_extract(self, url):
  32. video_id = self._match_id(url)
  33. webpage, urlh = self._download_webpage_handle(url, video_id)
  34. if '>File does not exist<' in webpage:
  35. raise ExtractorError(
  36. 'Video %s does not exist' % video_id, expected=True)
  37. download_form = self._hidden_inputs(webpage)
  38. video_page = self._download_webpage(
  39. urlh.geturl(), video_id, 'Downloading video page',
  40. data=urlencode_postdata(download_form),
  41. headers={
  42. 'Content-Type': 'application/x-www-form-urlencoded',
  43. 'Referer': urlh.geturl(),
  44. })
  45. video_url = self._html_search_regex(
  46. r'data-url=(["\'])(?P<url>(?:(?!\1).)+)\1',
  47. video_page, 'video URL', group='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=(["\'])(?P<url>(?:(?!\1).)+)\1',
  54. video_page, 'thumbnail', default=None, group='url')
  55. return {
  56. 'id': video_id,
  57. 'url': video_url,
  58. 'ext': 'mp4',
  59. 'filesize': filesize,
  60. 'title': title,
  61. 'thumbnail': thumbnail,
  62. }