Fix for YouTube changes
authorJames Bunton <jamesbunton@delx.net.au>
Sat, 10 Nov 2018 12:08:33 +0000 (23:08 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Sat, 10 Nov 2018 12:08:33 +0000 (23:08 +1100)
youtube.cgi

index d25a857..b57636b 100755 (executable)
@@ -138,7 +138,7 @@ def extract_js(script):
 
 def find_func_name(script):
     FUNC_NAME = R"([a-zA-Z0-9$]+)"
 
 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
 
     TERMINATOR = R"[,;\)]"
     PATTERN = FUNC_NAME + FUNC_PARAMS + TERMINATOR
 
@@ -166,9 +166,9 @@ def decode_signature(js_url, signature):
         stdout=subprocess.PIPE
     )
     js_decode_script = ("""
         stdout=subprocess.PIPE
     )
     js_decode_script = ("""
-        var vm = require('vm');
+        const vm = require('vm');
 
 
-        var sandbox = {
+        const sandbox = {
             location: {
                 hash: '',
                 href: '',
             location: {
                 hash: '',
                 href: '',
@@ -188,11 +188,25 @@ def decode_signature(js_url, signature):
         };
         sandbox.window = sandbox;
 
         };
         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);
 
         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"))
     """ % params)
 
     p.stdin.write(js_decode_script.encode("utf-8"))