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.

102 lines
3.1 KiB

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