openload.py 3.0 KB

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