diff options
| author | Yen Chi Hsuan <yan12125@gmail.com> | 2016-11-16 20:43:19 +0800 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-16 20:43:19 +0800 | 
| commit | eceba9f805e395429d1850ff2a339728c9dfed7f (patch) | |
| tree | 9525e38e865d08a4b7a2f9413361f8d6f4ee8c60 | |
| parent | 58355a3bf163349831b076c0fac4c09a286d5aa4 (diff) | |
| parent | 95ad9ce573033006b08c4f1a440f3ff04c20d8b3 (diff) | |
| download | hypervideo-pre-eceba9f805e395429d1850ff2a339728c9dfed7f.tar.lz hypervideo-pre-eceba9f805e395429d1850ff2a339728c9dfed7f.tar.xz hypervideo-pre-eceba9f805e395429d1850ff2a339728c9dfed7f.zip | |
Merge pull request #11122 from kasper93/openload
[openload] Fix extraction.
| -rw-r--r-- | test/test_jsinterp.py | 7 | ||||
| -rw-r--r-- | youtube_dl/extractor/openload.py | 65 | ||||
| -rw-r--r-- | youtube_dl/jsinterp.py | 4 | 
3 files changed, 67 insertions, 9 deletions
| diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index 63c350b8f..a9abae5f5 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -104,6 +104,13 @@ class TestJSInterpreter(unittest.TestCase):          }''')          self.assertEqual(jsi.call_function('x'), [20, 20, 30, 40, 50]) +    def test_call(self): +        jsi = JSInterpreter(''' +        function x() { return 2; } +        function y(a) { return x() + a; } +        function z() { return y(3); } +        ''') +        self.assertEqual(jsi.call_function('z'), 5)  if __name__ == '__main__':      unittest.main() diff --git a/youtube_dl/extractor/openload.py b/youtube_dl/extractor/openload.py index d3d4101de..7f19b1ba5 100644 --- a/youtube_dl/extractor/openload.py +++ b/youtube_dl/extractor/openload.py @@ -1,6 +1,8 @@  # coding: utf-8  from __future__ import unicode_literals, division +import re +  from .common import InfoExtractor  from ..compat import (      compat_chr, @@ -10,6 +12,10 @@ from ..utils import (      determine_ext,      ExtractorError,  ) +from ..jsinterp import ( +    JSInterpreter, +    _NAME_RE +)  class OpenloadIE(InfoExtractor): @@ -56,6 +62,44 @@ class OpenloadIE(InfoExtractor):          'only_matching': True,      }] +    def openload_decode(self, txt): +        symbol_dict = { +            '(゚Д゚) [゚Θ゚]': '_', +            '(゚Д゚) [゚ω゚ノ]': 'a', +            '(゚Д゚) [゚Θ゚ノ]': 'b', +            '(゚Д゚) [\'c\']': 'c', +            '(゚Д゚) [゚ー゚ノ]': 'd', +            '(゚Д゚) [゚Д゚ノ]': 'e', +            '(゚Д゚) [1]': 'f', +            '(゚Д゚) [\'o\']': 'o', +            '(o゚ー゚o)': 'u', +            '(゚Д゚) [\'c\']': 'c', +            '((゚ー゚) + (o^_^o))': '7', +            '((o^_^o) +(o^_^o) +(c^_^o))': '6', +            '((゚ー゚) + (゚Θ゚))': '5', +            '(-~3)': '4', +            '(-~-~1)': '3', +            '(-~1)': '2', +            '(-~0)': '1', +            '((c^_^o)-(c^_^o))': '0', +        } +        delim = '(゚Д゚)[゚ε゚]+' +        end_token = '(゚Д゚)[゚o゚]' +        symbols = '|'.join(map(re.escape, symbol_dict.keys())) +        txt = re.sub('(%s)\+\s?' % symbols, lambda m: symbol_dict[m.group(1)], txt) +        ret = '' +        for aacode in re.findall(r'{0}\+\s?{1}(.*?){0}'.format(re.escape(end_token), re.escape(delim)), txt): +            for aachar in aacode.split(delim): +                if aachar.isdigit(): +                    ret += compat_chr(int(aachar, 8)) +                else: +                    m = re.match(r'^u([\da-f]{4})$', aachar) +                    if m: +                        ret += compat_chr(int(m.group(1), 16)) +                    else: +                        self.report_warning("Cannot decode: %s" % aachar) +        return ret +      def _real_extract(self, url):          video_id = self._match_id(url)          webpage = self._download_webpage('https://openload.co/embed/%s/' % video_id, video_id) @@ -70,19 +114,26 @@ class OpenloadIE(InfoExtractor):              r'<span[^>]*>([^<]+)</span>\s*<span[^>]*>[^<]+</span>\s*<span[^>]+id="streamurl"',              webpage, 'encrypted data') -        magic = compat_ord(enc_data[-1]) +        enc_code = self._html_search_regex(r'<script[^>]+>(゚ω゚[^<]+)</script>', +                                           webpage, 'encrypted code') + +        js_code = self.openload_decode(enc_code) +        jsi = JSInterpreter(js_code) + +        m_offset_fun = self._search_regex(r'slice\(0\s*-\s*(%s)\(\)' % _NAME_RE, js_code, 'javascript offset function') +        m_diff_fun = self._search_regex(r'charCodeAt\(0\)\s*\+\s*(%s)\(\)' % _NAME_RE, js_code, 'javascript diff function') + +        offset = jsi.call_function(m_offset_fun) +        diff = jsi.call_function(m_diff_fun) +          video_url_chars = []          for idx, c in enumerate(enc_data):              j = compat_ord(c) -            if j == magic: -                j -= 1 -            elif j == magic - 1: -                j += 1              if j >= 33 and j <= 126:                  j = ((j + 14) % 94) + 33 -            if idx == len(enc_data) - 1: -                j += 3 +            if idx == len(enc_data) - offset: +                j += diff              video_url_chars += compat_chr(j)          video_url = 'https://openload.co/stream/%s?mime=true' % ''.join(video_url_chars) diff --git a/youtube_dl/jsinterp.py b/youtube_dl/jsinterp.py index 9737f7002..a8df4aef0 100644 --- a/youtube_dl/jsinterp.py +++ b/youtube_dl/jsinterp.py @@ -198,12 +198,12 @@ class JSInterpreter(object):              return opfunc(x, y)          m = re.match( -            r'^(?P<func>%s)\((?P<args>[a-zA-Z0-9_$,]+)\)$' % _NAME_RE, expr) +            r'^(?P<func>%s)\((?P<args>[a-zA-Z0-9_$,]*)\)$' % _NAME_RE, expr)          if m:              fname = m.group('func')              argvals = tuple([                  int(v) if v.isdigit() else local_vars[v] -                for v in m.group('args').split(',')]) +                for v in m.group('args').split(',')]) if len(m.group('args')) > 0 else tuple()              if fname not in self._functions:                  self._functions[fname] = self.extract_function(fname)              return self._functions[fname](argvals) | 
