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.

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