+ js_decode_script = ("""
+ const vm = require('vm');
+
+ const fakeGlobal = {};
+ fakeGlobal.window = fakeGlobal;
+ fakeGlobal.location = {
+ hash: '',
+ host: 'www.youtube.com',
+ hostname: 'www.youtube.com',
+ href: 'https://www.youtube.com',
+ origin: 'https://www.youtube.com',
+ pathname: '/',
+ protocol: 'https:'
+ };
+ fakeGlobal.history = {
+ pushState: function(){}
+ };
+ fakeGlobal.document = {
+ location: fakeGlobal.location
+ };
+ fakeGlobal.document = {};
+ fakeGlobal.navigator = {
+ userAgent: ''
+ };
+ fakeGlobal.XMLHttpRequest = class XMLHttpRequest {};
+ fakeGlobal.matchMedia = () => ({matches: () => {}, media: ''});
+ fakeGlobal.result_url = null;
+ fakeGlobal.g = function(){}; // this is _yt_player
+
+ const code_string = %(code)s + ';';
+ const exec_string = 'result_url = %(url_func_name)s(%(cipher_func_name)s(...%(args)s));';
+ vm.runInNewContext(code_string + exec_string, fakeGlobal);
+
+ console.log(fakeGlobal.result_url);
+ """ % params)
+
+ p.stdin.write(js_decode_script.encode("utf-8"))