diff --git a/anime_downloader/extractors/mp4upload.py b/anime_downloader/extractors/mp4upload.py index 0e810425a..702e792e6 100644 --- a/anime_downloader/extractors/mp4upload.py +++ b/anime_downloader/extractors/mp4upload.py @@ -14,15 +14,15 @@ def _get_data(self): logger.warning('File not found (Most likely deleted)') return {'stream_url':''} - regex = r">\s*(eval\(function[\W\w]*?)" - script = re.search(regex,soup).group(1) - script = util.deobfuscate_packed_js(script) - - url = '' - if re.search(r'player\.src\("([^"]*)',script): - url = re.search(r'player\.src\("([^"]*)',script).group(1) - elif re.search(r'src:"([^"]*)',script): - url = re.search(r'src:"([^"]*)',script).group(1) + regex = r"eval\(function[\W\w]*?" + script = re.search(regex,soup).group().replace('','') + script = script + "player.source.sources[0].src;" + sandbox = """{ + player: {}, + document: { getElementById: x => x }, + $: () => ({ ready: x => x }) + }""" + url = util.eval_in_node(script, sandbox=sandbox) return { 'stream_url': url, 'referer': self.url diff --git a/anime_downloader/util.py b/anime_downloader/util.py index 6e79768e7..9b9432955 100644 --- a/anime_downloader/util.py +++ b/anime_downloader/util.py @@ -6,6 +6,7 @@ import platform import re import os +from os import path import json import errno import time @@ -390,16 +391,20 @@ def get_hcaptcha_cookies(url): return pickle.load(open(COOKIE_FILE, 'rb')) def deobfuscate_packed_js(packedjs): - return eval_in_node('eval=console.log; ' + packedjs) + return eval_in_node(packedjs) -def eval_in_node(js: str): +def eval_in_node(js: str, sandbox: str = "{}"): js = base64.b64encode(js.encode('utf-8')).decode() sandboxedScript =""" const {VM} = require('vm2'); - const js = Buffer.from('%s','base64').toString() - console.log(new VM().run(js)) - """%js - node_path = path.join(path.dirname(__file__), 'node_modules') + const js = Buffer.from('%s','base64').toString(); + const vm = new VM({ + sandbox: %s + }); + const res = vm.run(js); + console.log(res); + """%(js,sandbox) + node_path = os.path.join(path.dirname(__file__), 'node_modules') output = subprocess.check_output(['node', '-e', sandboxedScript], env={'NODE_PATH': node_path}) return output.decode('utf-8')