]> code.delx.au - youtube-cgi/blobdiff - youtube.cgi
changed script prefix/suffix
[youtube-cgi] / youtube.cgi
index 7d3935771ebbbec6f11268b9ac75e641241413f1..349842fb24b03f22789edfd1e38603bb9583e87c 100755 (executable)
@@ -132,8 +132,8 @@ def get_player_config(doc):
                     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)
 
@@ -168,21 +168,20 @@ def decode_signature(js_url, signature):
         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
         };
+        sandbox.window = sandbox;
 
         var code_string = %(code)s + ';';
         var exec_string = 'transformed_signature = %(func_name)s(signature);';