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.

96 lines
2.8 KiB

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