youtube: provide own JS interpreter

since the data should be side-effect free, this should
be fine for now, but maybe it might be a good idea to look
into a proper sandboxed environment in the future.
This commit is contained in:
jj
2025-10-13 23:29:30 +00:00
parent c86ab40acd
commit 1dc0aa89df

View File

@@ -7,6 +7,23 @@ import { env } from "../../config.js";
import { getCookie } from "../cookie/manager.js";
import { getYouTubeSession } from "../helpers/youtube-session.js";
// https://github.com/LuanRT/YouTube.js/pull/1052
Platform.shim.eval = async (data, env) => {
const properties = [];
if (env.n) {
properties.push(`n: exportedVars.nFunction("${env.n}")`)
}
if (env.sig) {
properties.push(`sig: exportedVars.sigFunction("${env.sig}")`)
}
const code = `${data.output}\nreturn { ${properties.join(', ')} }`;
return new Function(code)();
}
const PLAYER_REFRESH_PERIOD = 1000 * 60 * 15; // ms
let innertube, lastRefreshedAt;