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.

127 lines
4.0 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import compat_b64decode
  4. from ..utils import (
  5. determine_ext,
  6. ExtractorError,
  7. int_or_none,
  8. KNOWN_EXTENSIONS,
  9. parse_filesize,
  10. url_or_none,
  11. urlencode_postdata,
  12. )
  13. class SharedBaseIE(InfoExtractor):
  14. def _real_extract(self, url):
  15. video_id = self._match_id(url)
  16. webpage, urlh = self._download_webpage_handle(url, video_id)
  17. if self._FILE_NOT_FOUND in webpage:
  18. raise ExtractorError(
  19. 'Video %s does not exist' % video_id, expected=True)
  20. video_url = self._extract_video_url(webpage, video_id, url)
  21. title = self._extract_title(webpage)
  22. filesize = int_or_none(self._extract_filesize(webpage))
  23. return {
  24. 'id': video_id,
  25. 'url': video_url,
  26. 'ext': 'mp4',
  27. 'filesize': filesize,
  28. 'title': title,
  29. }
  30. def _extract_title(self, webpage):
  31. return compat_b64decode(self._html_search_meta(
  32. 'full:title', webpage, 'title')).decode('utf-8')
  33. def _extract_filesize(self, webpage):
  34. return self._html_search_meta(
  35. 'full:size', webpage, 'file size', fatal=False)
  36. class SharedIE(SharedBaseIE):
  37. IE_DESC = 'shared.sx'
  38. _VALID_URL = r'https?://shared\.sx/(?P<id>[\da-z]{10})'
  39. _FILE_NOT_FOUND = '>File does not exist<'
  40. _TEST = {
  41. 'url': 'http://shared.sx/0060718775',
  42. 'md5': '106fefed92a8a2adb8c98e6a0652f49b',
  43. 'info_dict': {
  44. 'id': '0060718775',
  45. 'ext': 'mp4',
  46. 'title': 'Bmp4',
  47. 'filesize': 1720110,
  48. },
  49. }
  50. def _extract_video_url(self, webpage, video_id, url):
  51. download_form = self._hidden_inputs(webpage)
  52. video_page = self._download_webpage(
  53. url, video_id, 'Downloading video page',
  54. data=urlencode_postdata(download_form),
  55. headers={
  56. 'Content-Type': 'application/x-www-form-urlencoded',
  57. 'Referer': url,
  58. })
  59. video_url = self._html_search_regex(
  60. r'data-url=(["\'])(?P<url>(?:(?!\1).)+)\1',
  61. video_page, 'video URL', group='url')
  62. return video_url
  63. class VivoIE(SharedBaseIE):
  64. IE_DESC = 'vivo.sx'
  65. _VALID_URL = r'https?://vivo\.sx/(?P<id>[\da-z]{10})'
  66. _FILE_NOT_FOUND = '>The file you have requested does not exists or has been removed'
  67. _TEST = {
  68. 'url': 'http://vivo.sx/d7ddda0e78',
  69. 'md5': '15b3af41be0b4fe01f4df075c2678b2c',
  70. 'info_dict': {
  71. 'id': 'd7ddda0e78',
  72. 'ext': 'mp4',
  73. 'title': 'Chicken',
  74. 'filesize': 515659,
  75. },
  76. }
  77. def _extract_title(self, webpage):
  78. title = self._html_search_regex(
  79. r'data-name\s*=\s*(["\'])(?P<title>(?:(?!\1).)+)\1', webpage,
  80. 'title', default=None, group='title')
  81. if title:
  82. ext = determine_ext(title)
  83. if ext.lower() in KNOWN_EXTENSIONS:
  84. title = title.rpartition('.' + ext)[0]
  85. return title
  86. return self._og_search_title(webpage)
  87. def _extract_filesize(self, webpage):
  88. return parse_filesize(self._search_regex(
  89. r'data-type=["\']video["\'][^>]*>Watch.*?<strong>\s*\((.+?)\)',
  90. webpage, 'filesize', fatal=False))
  91. def _extract_video_url(self, webpage, video_id, url):
  92. def decode_url(encoded_url):
  93. return compat_b64decode(encoded_url).decode('utf-8')
  94. stream_url = url_or_none(decode_url(self._search_regex(
  95. r'data-stream\s*=\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  96. 'stream url', default=None, group='url')))
  97. if stream_url:
  98. return stream_url
  99. return self._parse_json(
  100. self._search_regex(
  101. r'InitializeStream\s*\(\s*(["\'])(?P<url>(?:(?!\1).)+)\1',
  102. webpage, 'stream', group='url'),
  103. video_id, transform_source=decode_url)[0]