+ js_decode_script = ("""
+ var vm = require('vm');
+
+ var sandbox = {
+ location: {
+ hash: '',
+ href: '',
+ protocol: 'http:'
+ },
+ history: {
+ pushState: function(){}
+ },
+ document: {},
+ navigator: {
+ userAgent: ''
+ },
+ signature: %(signature)s,
+ transformed_signature: null,
+ g: function(){} // this is _yt_player
+ };
+ sandbox.window = sandbox;
+
+ var code_string = %(code)s + ';';
+ var exec_string = 'transformed_signature = %(func_name)s(signature);';
+ vm.runInNewContext(code_string + exec_string, sandbox);
+
+ console.log(sandbox.transformed_signature);
+ """ % params)
+
+ p.stdin.write(js_decode_script)