From: James Bunton Date: Sat, 10 Nov 2018 12:08:33 +0000 (+1100) Subject: Fix for YouTube changes X-Git-Url: https://code.delx.au/youtube-cgi/commitdiff_plain/c7348757cc65852d4d82c7718f36a661268ab262 Fix for YouTube changes --- diff --git a/youtube.cgi b/youtube.cgi index d25a857..b57636b 100755 --- a/youtube.cgi +++ b/youtube.cgi @@ -138,7 +138,7 @@ def extract_js(script): def find_func_name(script): FUNC_NAME = R"([a-zA-Z0-9$]+)" - FUNC_PARAMS = R"(\([a-zA-Z]+\.s\))" + FUNC_PARAMS = R"(\([a-zA-Z,\.]+\.s\))" TERMINATOR = R"[,;\)]" PATTERN = FUNC_NAME + FUNC_PARAMS + TERMINATOR @@ -166,9 +166,9 @@ def decode_signature(js_url, signature): stdout=subprocess.PIPE ) js_decode_script = (""" - var vm = require('vm'); + const vm = require('vm'); - var sandbox = { + const sandbox = { location: { hash: '', href: '', @@ -188,11 +188,25 @@ def decode_signature(js_url, signature): }; sandbox.window = sandbox; - var code_string = %(code)s + ';'; - var exec_string = 'transformed_signature = %(func_name)s(signature);'; + const code_string = %(code)s + ';'; + const exec_string = 'transformed_signature = %(func_name)s("", "MARKER", signature);'; vm.runInNewContext(code_string + exec_string, sandbox); - console.log(sandbox.transformed_signature); + function findSignature(obj) { + if (typeof obj !== 'object') { + return; + } + for (const [key, value] of Object.entries(obj)) { + if (key === 'MARKER') { + return value; + } + const result = findSignature(value); + if (result) { + return result; + } + } + } + console.log(findSignature(sandbox.transformed_signature)); """ % params) p.stdin.write(js_decode_script.encode("utf-8"))