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.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_chr
  6. from ..utils import (
  7. determine_ext,
  8. encode_base_n,
  9. ExtractorError,
  10. mimetype2ext,
  11. )
  12. class OpenloadIE(InfoExtractor):
  13. _VALID_URL = r'https://openload.(?:co|io)/(?:f|embed)/(?P<id>[a-zA-Z0-9-]+)'
  14. _TESTS = [{
  15. 'url': 'https://openload.co/f/kUEfGclsU9o',
  16. 'md5': 'bf1c059b004ebc7a256f89408e65c36e',
  17. 'info_dict': {
  18. 'id': 'kUEfGclsU9o',
  19. 'ext': 'mp4',
  20. 'title': 'skyrim_no-audio_1080.mp4',
  21. 'thumbnail': 're:^https?://.*\.jpg$',
  22. },
  23. }, {
  24. 'url': 'https://openload.co/embed/kUEfGclsU9o/skyrim_no-audio_1080.mp4',
  25. 'only_matching': True,
  26. }, {
  27. 'url': 'https://openload.io/f/ZAn6oz-VZGE/',
  28. 'only_matching': True,
  29. }, {
  30. # unavailable via https://openload.co/f/Sxz5sADo82g/, different layout
  31. # for title and ext
  32. 'url': 'https://openload.co/embed/Sxz5sADo82g/',
  33. 'only_matching': True,
  34. }]
  35. @staticmethod
  36. def openload_level2_debase(m):
  37. radix, num = int(m.group(1)) + 27, int(m.group(2))
  38. return '"' + encode_base_n(num, radix) + '"'
  39. @classmethod
  40. def openload_level2(cls, txt):
  41. # The function name is ǃ \u01c3
  42. # Using escaped unicode literals does not work in Python 3.2
  43. return re.sub(r'ǃ\((\d+),(\d+)\)', cls.openload_level2_debase, txt, re.UNICODE).replace('"+"', '')
  44. # Openload uses a variant of aadecode
  45. # openload_decode and related functions are originally written by
  46. # vitas@matfyz.cz and released with public domain
  47. # See https://github.com/rg3/youtube-dl/issues/8489
  48. @classmethod
  49. def openload_decode(cls, txt):
  50. symbol_table = [
  51. ('_', '(゚Д゚) [゚Θ゚]'),
  52. ('a', '(゚Д゚) [゚ω゚ノ]'),
  53. ('b', '(゚Д゚) [゚Θ゚ノ]'),
  54. ('c', '(゚Д゚) [\'c\']'),
  55. ('d', '(゚Д゚) [゚ー゚ノ]'),
  56. ('e', '(゚Д゚) [゚Д゚ノ]'),
  57. ('f', '(゚Д゚) [1]'),
  58. ('o', '(゚Д゚) [\'o\']'),
  59. ('u', '(o゚ー゚o)'),
  60. ('c', '(゚Д゚) [\'c\']'),
  61. ('7', '((゚ー゚) + (o^_^o))'),
  62. ('6', '((o^_^o) +(o^_^o) +(c^_^o))'),
  63. ('5', '((゚ー゚) + (゚Θ゚))'),
  64. ('4', '(-~3)'),
  65. ('3', '(-~-~1)'),
  66. ('2', '(-~1)'),
  67. ('1', '(-~0)'),
  68. ('0', '((c^_^o)-(c^_^o))'),
  69. ]
  70. delim = '(゚Д゚)[゚ε゚]+'
  71. ret = ''
  72. for aachar in txt.split(delim):
  73. for val, pat in symbol_table:
  74. aachar = aachar.replace(pat, val)
  75. aachar = aachar.replace('+ ', '')
  76. m = re.match(r'^\d+', aachar)
  77. if m:
  78. ret += compat_chr(int(m.group(0), 8))
  79. else:
  80. m = re.match(r'^u([\da-f]+)', aachar)
  81. if m:
  82. ret += compat_chr(int(m.group(1), 16))
  83. return cls.openload_level2(ret)
  84. def _real_extract(self, url):
  85. video_id = self._match_id(url)
  86. webpage = self._download_webpage(url, video_id)
  87. if 'File not found' in webpage:
  88. raise ExtractorError('File not found', expected=True)
  89. code = self._search_regex(
  90. r'</video>\s*</div>\s*<script[^>]+>([^<]+)</script>',
  91. webpage, 'JS code')
  92. decoded = self.openload_decode(code)
  93. video_url = self._search_regex(
  94. r'return\s+"(https?://[^"]+)"', decoded, 'video URL')
  95. title = self._og_search_title(webpage, default=None) or self._search_regex(
  96. r'<span[^>]+class=["\']title["\'][^>]*>([^<]+)', webpage,
  97. 'title', default=None) or self._html_search_meta(
  98. 'description', webpage, 'title', fatal=True)
  99. ext = mimetype2ext(self._search_regex(
  100. r'window\.vt\s*=\s*(["\'])(?P<mimetype>.+?)\1', decoded,
  101. 'mimetype', default=None, group='mimetype')) or determine_ext(
  102. video_url, 'mp4')
  103. return {
  104. 'id': video_id,
  105. 'title': title,
  106. 'ext': ext,
  107. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  108. 'url': video_url,
  109. }