changed script prefix/suffix
authorJames Bunton <jamesbunton@delx.net.au>
Tue, 24 Nov 2015 14:42:02 +0000 (01:42 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Tue, 24 Nov 2015 14:42:02 +0000 (01:42 +1100)
youtube.cgi

index 7d39357..349842f 100755 (executable)
@@ -132,8 +132,8 @@ def get_player_config(doc):
                     return json.loads(line[p1:p2])
 
 def extract_js(script):
                     return json.loads(line[p1:p2])
 
 def extract_js(script):
-    PREFIX = "(function(){"
-    SUFFIX = "})();\n"
+    PREFIX = "var _yt_player={};(function(g){var window=this;"
+    SUFFIX = ";})(_yt_player);\n"
     assert script.startswith(PREFIX)
     assert script.endswith(SUFFIX)
 
     assert script.startswith(PREFIX)
     assert script.endswith(SUFFIX)
 
@@ -168,21 +168,20 @@ def decode_signature(js_url, signature):
         var vm = require('vm');
 
         var sandbox = {
         var vm = require('vm');
 
         var sandbox = {
-            window: {
-                location: {
-                    hash: '',
-                    href: ''
-                },
-                history: {
-                    pushState: function(){}
-                },
-                navigator: {}
+            location: {
+                hash: '',
+                href: '',
+                protocol: 'http:'
+            },
+            history: {
+                pushState: function(){}
             },
             document: {},
             navigator: {},
             signature: %(signature)s,
             transformed_signature: null
         };
             },
             document: {},
             navigator: {},
             signature: %(signature)s,
             transformed_signature: null
         };
+        sandbox.window = sandbox;
 
         var code_string = %(code)s + ';';
         var exec_string = 'transformed_signature = %(func_name)s(signature);';
 
         var code_string = %(code)s + ';';
         var exec_string = 'transformed_signature = %(func_name)s(signature);';