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)
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);';