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.

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