mirror of
https://github.com/yt-dlp/ejs.git
synced 2026-06-13 08:42:29 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd4e87f52e | ||
|
|
41ff68e6f8 | ||
|
|
5bc9811c7a | ||
|
|
1b648c34c1 | ||
|
|
d13ca53401 | ||
|
|
a3095891a9 | ||
|
|
c51d14fa61 | ||
|
|
96c417f90a |
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@@ -380,9 +380,11 @@ jobs:
|
||||
name: player-js
|
||||
- name: Run Deno tests
|
||||
run: |
|
||||
deno test \
|
||||
xargs -n 1 -P 10 deno test \
|
||||
--no-prompt \
|
||||
--allow-read=src/yt/solver/test/players/
|
||||
--no-check \
|
||||
--allow-read=src/yt/solver/test/players/ \
|
||||
--filter <<<"$(printf -- '-%s-\n' main tcc tce es5 es6 tv tv_es6 phone es6_tcc es6_tce)"
|
||||
|
||||
bun_build:
|
||||
name: Test Bun build
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"bundle": "rollup -c",
|
||||
"fmt": "prettier --write \"src/**.ts\" \"package.json\" \"rollup.config.js\" \"run.ts\" \"eslint.config.js\"",
|
||||
"fmt:check": "prettier --check \"src/**.ts\" \"package.json\" \"rollup.config.js\" \"run.ts\" \"eslint.config.js\"",
|
||||
"prettier": "prettier",
|
||||
"fmt": "prettier --write \"**/*.[jt]s\" \"package.json\"",
|
||||
"fmt:check": "prettier --check \"**/*.[jt]s\" \"package.json\"",
|
||||
"lint": "eslint src"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type ESTree } from "meriyah";
|
||||
import { parse, type ESTree } from "meriyah";
|
||||
import { type DeepPartial } from "./types.ts";
|
||||
|
||||
export function matchesStructure<T extends ESTree.Node>(
|
||||
@@ -42,3 +42,10 @@ export function matchesStructure<T extends ESTree.Node>(
|
||||
export function isOneOf<T>(value: unknown, ...of: readonly T[]): value is T {
|
||||
return of.includes(value as T);
|
||||
}
|
||||
|
||||
export function generateArrowFunction(
|
||||
data: string,
|
||||
): ESTree.ArrowFunctionExpression {
|
||||
return (parse(data).body[0] as ESTree.ExpressionStatement)
|
||||
.expression as ESTree.ArrowFunctionExpression;
|
||||
}
|
||||
|
||||
24
src/yt/solver/extract.ts
Normal file
24
src/yt/solver/extract.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { parse } from "meriyah";
|
||||
import { getIO } from "./test/io.ts";
|
||||
import { downloadCached } from "./test/utils.ts";
|
||||
import { argv } from "node:process";
|
||||
import { getSolutions, modifyPlayer } from "./solvers.ts";
|
||||
import { generate } from "astring";
|
||||
|
||||
const data = await (
|
||||
argv.length > 3
|
||||
? () => downloadCached(argv[2], argv[3])
|
||||
: async () => {
|
||||
const io = await getIO();
|
||||
return await io.read(argv[2]);
|
||||
}
|
||||
)();
|
||||
|
||||
const program = parse(data);
|
||||
const statements = modifyPlayer(program);
|
||||
const solutionMap = getSolutions(statements);
|
||||
for (const solutions of Object.values(solutionMap)) {
|
||||
for (const solution of solutions) {
|
||||
console.log(String.raw`${generate(solution)}`);
|
||||
}
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
import { type ESTree } from "meriyah";
|
||||
import { matchesStructure } from "../../utils.ts";
|
||||
import { type DeepPartial } from "../../types.ts";
|
||||
|
||||
const identifier: DeepPartial<ESTree.Node> = {
|
||||
or: [
|
||||
{
|
||||
type: "VariableDeclaration",
|
||||
kind: "var",
|
||||
declarations: {
|
||||
anykey: [
|
||||
{
|
||||
type: "VariableDeclarator",
|
||||
id: {
|
||||
type: "Identifier",
|
||||
},
|
||||
init: {
|
||||
type: "ArrayExpression",
|
||||
elements: [
|
||||
{
|
||||
type: "Identifier",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "AssignmentExpression",
|
||||
left: {
|
||||
type: "Identifier",
|
||||
},
|
||||
operator: "=",
|
||||
right: {
|
||||
type: "ArrayExpression",
|
||||
elements: [
|
||||
{
|
||||
type: "Identifier",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
} as const;
|
||||
|
||||
const catchBlockBody = [
|
||||
{
|
||||
type: "ReturnStatement",
|
||||
argument: {
|
||||
type: "BinaryExpression",
|
||||
left: {
|
||||
type: "MemberExpression",
|
||||
object: {
|
||||
type: "Identifier",
|
||||
},
|
||||
computed: true,
|
||||
property: {
|
||||
type: "Literal",
|
||||
},
|
||||
optional: false,
|
||||
},
|
||||
right: {
|
||||
type: "Identifier",
|
||||
},
|
||||
operator: "+",
|
||||
},
|
||||
},
|
||||
] as const;
|
||||
|
||||
export function extract(
|
||||
node: ESTree.Node,
|
||||
): ESTree.ArrowFunctionExpression | null {
|
||||
if (!matchesStructure(node, identifier)) {
|
||||
// Fallback search for try { } catch { return X[12] + Y }
|
||||
let name: string | undefined | null = null;
|
||||
let block: ESTree.BlockStatement | null | undefined = null;
|
||||
switch (node.type) {
|
||||
case "ExpressionStatement": {
|
||||
if (
|
||||
node.expression.type === "AssignmentExpression" &&
|
||||
node.expression.left.type === "Identifier" &&
|
||||
node.expression.right.type === "FunctionExpression" &&
|
||||
node.expression.right.params.length === 1
|
||||
) {
|
||||
name = node.expression.left.name;
|
||||
block = node.expression.right.body;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "FunctionDeclaration": {
|
||||
if (node.params.length === 1) {
|
||||
name = node.id?.name;
|
||||
block = node.body;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!block || !name) {
|
||||
return null;
|
||||
}
|
||||
const tryNode = block.body.at(-2);
|
||||
if (
|
||||
tryNode?.type !== "TryStatement" ||
|
||||
tryNode.handler?.type !== "CatchClause"
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const catchBody = tryNode.handler!.body.body;
|
||||
if (matchesStructure(catchBody, catchBlockBody)) {
|
||||
return makeSolverFuncFromName(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (node.type === "VariableDeclaration") {
|
||||
for (const declaration of node.declarations) {
|
||||
if (
|
||||
declaration.type !== "VariableDeclarator" ||
|
||||
!declaration.init ||
|
||||
declaration.init.type !== "ArrayExpression" ||
|
||||
declaration.init.elements.length !== 1
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
const [firstElement] = declaration.init.elements;
|
||||
if (firstElement && firstElement.type === "Identifier") {
|
||||
return makeSolverFuncFromName(firstElement.name);
|
||||
}
|
||||
}
|
||||
} else if (node.type === "ExpressionStatement") {
|
||||
const expr = node.expression;
|
||||
if (
|
||||
expr.type === "AssignmentExpression" &&
|
||||
expr.left.type === "Identifier" &&
|
||||
expr.operator === "=" &&
|
||||
expr.right.type === "ArrayExpression" &&
|
||||
expr.right.elements.length === 1
|
||||
) {
|
||||
const [firstElement] = expr.right.elements;
|
||||
if (firstElement && firstElement.type === "Identifier") {
|
||||
return makeSolverFuncFromName(firstElement.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function makeSolverFuncFromName(name: string): ESTree.ArrowFunctionExpression {
|
||||
return {
|
||||
type: "ArrowFunctionExpression",
|
||||
params: [
|
||||
{
|
||||
type: "Identifier",
|
||||
name: "n",
|
||||
},
|
||||
],
|
||||
body: {
|
||||
type: "CallExpression",
|
||||
callee: {
|
||||
type: "Identifier",
|
||||
name: name,
|
||||
},
|
||||
arguments: [
|
||||
{
|
||||
type: "Identifier",
|
||||
name: "n",
|
||||
},
|
||||
],
|
||||
optional: false,
|
||||
},
|
||||
async: false,
|
||||
expression: false,
|
||||
generator: false,
|
||||
};
|
||||
}
|
||||
143
src/yt/solver/nsig.ts
Normal file
143
src/yt/solver/nsig.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
import { type ESTree } from "meriyah";
|
||||
import { generate } from "astring";
|
||||
import { matchesStructure, generateArrowFunction } from "../../utils.ts";
|
||||
import { type DeepPartial } from "../../types.ts";
|
||||
|
||||
const identifier: DeepPartial<ESTree.Node> = {
|
||||
or: [
|
||||
{
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "AssignmentExpression",
|
||||
operator: "=",
|
||||
left: {
|
||||
or: [{ type: "Identifier" }, { type: "MemberExpression" }],
|
||||
},
|
||||
right: {
|
||||
type: "FunctionExpression",
|
||||
async: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "FunctionDeclaration",
|
||||
async: false,
|
||||
id: { type: "Identifier" },
|
||||
},
|
||||
{
|
||||
type: "VariableDeclaration",
|
||||
declarations: {
|
||||
anykey: [
|
||||
{
|
||||
type: "VariableDeclarator",
|
||||
init: {
|
||||
type: "FunctionExpression",
|
||||
async: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
} as const;
|
||||
|
||||
const asdasd: DeepPartial<ESTree.ExpressionStatement> = {
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "CallExpression",
|
||||
callee: {
|
||||
type: "MemberExpression",
|
||||
object: { type: "Identifier" },
|
||||
property: {},
|
||||
optional: false,
|
||||
},
|
||||
arguments: [
|
||||
{
|
||||
type: "Literal",
|
||||
value: "alr",
|
||||
},
|
||||
{
|
||||
type: "Literal",
|
||||
value: "yes",
|
||||
},
|
||||
],
|
||||
optional: false,
|
||||
},
|
||||
};
|
||||
|
||||
export function extract(
|
||||
node: ESTree.Node,
|
||||
): ESTree.ArrowFunctionExpression | null {
|
||||
if (!matchesStructure(node, identifier)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const options: {
|
||||
name: ESTree.Expression;
|
||||
statements: ESTree.Statement[];
|
||||
}[] = [];
|
||||
|
||||
if (node.type === "FunctionDeclaration") {
|
||||
if (node.id && node.body?.body) {
|
||||
options.push({
|
||||
name: node.id,
|
||||
statements: node.body?.body,
|
||||
});
|
||||
}
|
||||
} else if (node.type === "ExpressionStatement") {
|
||||
if (node.expression.type !== "AssignmentExpression") {
|
||||
return null;
|
||||
}
|
||||
const name = node.expression.left;
|
||||
const body = (node.expression.right as ESTree.FunctionExpression)?.body
|
||||
?.body;
|
||||
if (name && body) {
|
||||
options.push({
|
||||
name: name,
|
||||
statements: body,
|
||||
});
|
||||
}
|
||||
} else if (node.type === "VariableDeclaration") {
|
||||
for (const declaration of node.declarations) {
|
||||
const name = declaration.id;
|
||||
const body = (declaration.init as ESTree.FunctionExpression)?.body?.body;
|
||||
if (name && body) {
|
||||
options.push({
|
||||
name: name,
|
||||
statements: body,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const { name, statements } of options) {
|
||||
if (matchesStructure(statements, { anykey: [asdasd] })) {
|
||||
return createSolver(name);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function createSolver(
|
||||
expression: ESTree.Expression,
|
||||
): ESTree.ArrowFunctionExpression {
|
||||
return generateArrowFunction(`
|
||||
({sig, n}) => {
|
||||
const url = (${generate(expression)})("https://youtube.com/watch?v=yt-dlp-wins", "s", sig ? encodeURIComponent(sig) : undefined);
|
||||
url.set("n", n);
|
||||
const proto = Object.getPrototypeOf(url);
|
||||
const keys = Object.keys(proto).concat(Object.getOwnPropertyNames(proto));
|
||||
for (const key of keys) {
|
||||
if (!["constructor", "set", "get", "clone"].includes(key)) {
|
||||
url[key]();
|
||||
break;
|
||||
}
|
||||
}
|
||||
const s = url.get("s");
|
||||
return {
|
||||
sig: s ? decodeURIComponent(s) : null,
|
||||
n: url.get("n") ?? null,
|
||||
};
|
||||
}
|
||||
`);
|
||||
}
|
||||
@@ -1,232 +0,0 @@
|
||||
import { type ESTree } from "meriyah";
|
||||
import { matchesStructure } from "../../utils.ts";
|
||||
import { type DeepPartial } from "../../types.ts";
|
||||
|
||||
const nsigExpression: DeepPartial<ESTree.Statement> = {
|
||||
type: "VariableDeclaration",
|
||||
kind: "var",
|
||||
declarations: [
|
||||
{
|
||||
type: "VariableDeclarator",
|
||||
init: {
|
||||
type: "CallExpression",
|
||||
callee: {
|
||||
type: "Identifier",
|
||||
},
|
||||
arguments: [
|
||||
{
|
||||
type: "Literal",
|
||||
},
|
||||
{
|
||||
type: "CallExpression",
|
||||
callee: {
|
||||
type: "Identifier",
|
||||
name: "decodeURIComponent",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const logicalExpression: DeepPartial<ESTree.ExpressionStatement> = {
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "LogicalExpression",
|
||||
left: {
|
||||
type: "Identifier",
|
||||
},
|
||||
right: {
|
||||
type: "SequenceExpression",
|
||||
expressions: [
|
||||
{
|
||||
type: "AssignmentExpression",
|
||||
left: {
|
||||
type: "Identifier",
|
||||
},
|
||||
operator: "=",
|
||||
right: {
|
||||
type: "CallExpression",
|
||||
callee: {
|
||||
type: "Identifier",
|
||||
},
|
||||
arguments: {
|
||||
or: [
|
||||
[
|
||||
{ type: "Literal" },
|
||||
{
|
||||
type: "CallExpression",
|
||||
callee: {
|
||||
type: "Identifier",
|
||||
name: "decodeURIComponent",
|
||||
},
|
||||
arguments: [{ type: "Identifier" }],
|
||||
optional: false,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
type: "CallExpression",
|
||||
callee: {
|
||||
type: "Identifier",
|
||||
name: "decodeURIComponent",
|
||||
},
|
||||
arguments: [{ type: "Identifier" }],
|
||||
optional: false,
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
optional: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "CallExpression",
|
||||
},
|
||||
],
|
||||
},
|
||||
operator: "&&",
|
||||
},
|
||||
};
|
||||
|
||||
const identifier: DeepPartial<ESTree.Node> = {
|
||||
or: [
|
||||
{
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "AssignmentExpression",
|
||||
operator: "=",
|
||||
left: {
|
||||
type: "Identifier",
|
||||
},
|
||||
right: {
|
||||
type: "FunctionExpression",
|
||||
params: [{}, {}, {}],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "FunctionDeclaration",
|
||||
params: [{}, {}, {}],
|
||||
},
|
||||
{
|
||||
type: "VariableDeclaration",
|
||||
declarations: {
|
||||
anykey: [
|
||||
{
|
||||
type: "VariableDeclarator",
|
||||
init: {
|
||||
type: "FunctionExpression",
|
||||
params: [{}, {}, {}],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
} as const;
|
||||
|
||||
export function extract(
|
||||
node: ESTree.Node,
|
||||
): ESTree.ArrowFunctionExpression | null {
|
||||
if (!matchesStructure(node, identifier)) {
|
||||
return null;
|
||||
}
|
||||
let block: ESTree.BlockStatement | undefined | null;
|
||||
if (
|
||||
node.type === "ExpressionStatement" &&
|
||||
node.expression.type === "AssignmentExpression" &&
|
||||
node.expression.right.type === "FunctionExpression"
|
||||
) {
|
||||
block = node.expression.right.body;
|
||||
} else if (node.type === "VariableDeclaration") {
|
||||
for (const decl of node.declarations) {
|
||||
if (
|
||||
decl.type === "VariableDeclarator" &&
|
||||
decl.init?.type === "FunctionExpression" &&
|
||||
decl.init?.params.length === 3
|
||||
) {
|
||||
block = decl.init.body;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (node.type === "FunctionDeclaration") {
|
||||
block = node.body;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
const relevantExpression = block?.body.at(-2);
|
||||
|
||||
let call: ESTree.CallExpression | null = null;
|
||||
if (matchesStructure(relevantExpression!, logicalExpression)) {
|
||||
if (
|
||||
relevantExpression?.type !== "ExpressionStatement" ||
|
||||
relevantExpression.expression.type !== "LogicalExpression" ||
|
||||
relevantExpression.expression.right.type !== "SequenceExpression" ||
|
||||
relevantExpression.expression.right.expressions[0].type !==
|
||||
"AssignmentExpression" ||
|
||||
relevantExpression.expression.right.expressions[0].right.type !==
|
||||
"CallExpression"
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
call = relevantExpression.expression.right.expressions[0].right;
|
||||
} else if (
|
||||
relevantExpression?.type === "IfStatement" &&
|
||||
relevantExpression.consequent.type === "BlockStatement"
|
||||
) {
|
||||
for (const n of relevantExpression.consequent.body) {
|
||||
if (!matchesStructure(n, nsigExpression)) {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
n.type !== "VariableDeclaration" ||
|
||||
n.declarations[0].init?.type !== "CallExpression"
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
call = n.declarations[0].init;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (call === null) {
|
||||
return null;
|
||||
}
|
||||
// TODO: verify identifiers here
|
||||
return {
|
||||
type: "ArrowFunctionExpression",
|
||||
params: [
|
||||
{
|
||||
type: "Identifier",
|
||||
name: "sig",
|
||||
},
|
||||
],
|
||||
body: {
|
||||
type: "CallExpression",
|
||||
callee: {
|
||||
type: "Identifier",
|
||||
name: call.callee.name,
|
||||
},
|
||||
arguments:
|
||||
call.arguments.length === 1
|
||||
? [
|
||||
{
|
||||
type: "Identifier",
|
||||
name: "sig",
|
||||
},
|
||||
]
|
||||
: [
|
||||
call.arguments[0],
|
||||
{
|
||||
type: "Identifier",
|
||||
name: "sig",
|
||||
},
|
||||
],
|
||||
optional: false,
|
||||
},
|
||||
async: false,
|
||||
expression: false,
|
||||
generator: false,
|
||||
};
|
||||
}
|
||||
@@ -8,7 +8,7 @@ const io = await getIO();
|
||||
for (const test of tests) {
|
||||
for (const variant of test.variants ?? players.keys()) {
|
||||
const path = getCachePath(test.player, variant);
|
||||
await io.test(`${test.player} ${variant}`, async (assert, subtest) => {
|
||||
await io.test(`-${test.player}-${variant}-`, async (assert, subtest) => {
|
||||
const content = await io.read(path);
|
||||
const solvers = getFromPrepared(preprocessPlayer(content));
|
||||
for (const mode of ["n", "sig"] as const) {
|
||||
|
||||
@@ -1,14 +1,45 @@
|
||||
import { type ESTree, parse } from "meriyah";
|
||||
import { generate } from "astring";
|
||||
import { extract as extractSig } from "./sig.ts";
|
||||
import { extract as extractN } from "./n.ts";
|
||||
import { extract } from "./nsig.ts";
|
||||
import { setupNodes } from "./setup.ts";
|
||||
import { generateArrowFunction } from "../../utils.ts";
|
||||
|
||||
export function preprocessPlayer(data: string): string {
|
||||
const ast = parse(data);
|
||||
const body = ast.body;
|
||||
const program = parse(data);
|
||||
const plainStatements = modifyPlayer(program);
|
||||
const solutions = getSolutions(plainStatements);
|
||||
for (const [name, options] of Object.entries(solutions)) {
|
||||
plainStatements.push({
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "AssignmentExpression",
|
||||
operator: "=",
|
||||
left: {
|
||||
type: "MemberExpression",
|
||||
computed: false,
|
||||
object: {
|
||||
type: "Identifier",
|
||||
name: "_result",
|
||||
},
|
||||
property: {
|
||||
type: "Identifier",
|
||||
name: name,
|
||||
},
|
||||
optional: false,
|
||||
},
|
||||
right: multiTry(options),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const block = (() => {
|
||||
program.body.splice(0, 0, ...setupNodes);
|
||||
return generate(program);
|
||||
}
|
||||
|
||||
export function modifyPlayer(program: ESTree.Program) {
|
||||
const body = program.body;
|
||||
|
||||
const block: ESTree.BlockStatement = (() => {
|
||||
switch (body.length) {
|
||||
case 1: {
|
||||
const func = body[0];
|
||||
@@ -40,19 +71,7 @@ export function preprocessPlayer(data: string): string {
|
||||
throw "unexpected structure";
|
||||
})();
|
||||
|
||||
const found = {
|
||||
n: [] as ESTree.ArrowFunctionExpression[],
|
||||
sig: [] as ESTree.ArrowFunctionExpression[],
|
||||
};
|
||||
const plainExpressions = block.body.filter((node: ESTree.Node) => {
|
||||
const n = extractN(node);
|
||||
if (n) {
|
||||
found.n.push(n);
|
||||
}
|
||||
const sig = extractSig(node);
|
||||
if (sig) {
|
||||
found.sig.push(sig);
|
||||
}
|
||||
block.body = block.body.filter((node: ESTree.Statement) => {
|
||||
if (node.type === "ExpressionStatement") {
|
||||
if (node.expression.type === "AssignmentExpression") {
|
||||
return true;
|
||||
@@ -61,43 +80,75 @@ export function preprocessPlayer(data: string): string {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
block.body = plainExpressions;
|
||||
|
||||
for (const [name, options] of Object.entries(found)) {
|
||||
// TODO: this is cringe fix plz
|
||||
const unique = new Set(options.map((x) => JSON.stringify(x)));
|
||||
if (unique.size !== 1) {
|
||||
const message = `found ${unique.size} ${name} function possibilities`;
|
||||
throw (
|
||||
message +
|
||||
(unique.size ? `: ${options.map((x) => generate(x)).join(", ")}` : "")
|
||||
return block.body;
|
||||
}
|
||||
|
||||
export function getSolutions(
|
||||
statements: ESTree.Statement[],
|
||||
): Record<string, ESTree.ArrowFunctionExpression[]> {
|
||||
const found = {
|
||||
n: [] as ESTree.ArrowFunctionExpression[],
|
||||
sig: [] as ESTree.ArrowFunctionExpression[],
|
||||
};
|
||||
for (const statement of statements) {
|
||||
const result = extract(statement);
|
||||
if (result) {
|
||||
found.n.push(
|
||||
makeSolver(result, {
|
||||
type: "Identifier",
|
||||
name: "n",
|
||||
}),
|
||||
);
|
||||
found.sig.push(
|
||||
makeSolver(result, {
|
||||
type: "Identifier",
|
||||
name: "sig",
|
||||
}),
|
||||
);
|
||||
}
|
||||
plainExpressions.push({
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "AssignmentExpression",
|
||||
operator: "=",
|
||||
left: {
|
||||
type: "MemberExpression",
|
||||
computed: false,
|
||||
object: {
|
||||
type: "Identifier",
|
||||
name: "_result",
|
||||
},
|
||||
property: {
|
||||
type: "Identifier",
|
||||
name: name,
|
||||
},
|
||||
},
|
||||
right: options[0],
|
||||
},
|
||||
});
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
ast.body.splice(0, 0, ...setupNodes);
|
||||
|
||||
return generate(ast);
|
||||
function makeSolver(
|
||||
result: ESTree.ArrowFunctionExpression,
|
||||
ident: ESTree.Identifier,
|
||||
): ESTree.ArrowFunctionExpression {
|
||||
return {
|
||||
type: "ArrowFunctionExpression",
|
||||
params: [ident],
|
||||
body: {
|
||||
type: "MemberExpression",
|
||||
object: {
|
||||
type: "CallExpression",
|
||||
callee: result,
|
||||
arguments: [
|
||||
{
|
||||
type: "ObjectExpression",
|
||||
properties: [
|
||||
{
|
||||
type: "Property",
|
||||
key: ident,
|
||||
value: ident,
|
||||
kind: "init",
|
||||
computed: false,
|
||||
method: false,
|
||||
shorthand: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
optional: false,
|
||||
},
|
||||
computed: false,
|
||||
property: ident,
|
||||
optional: false,
|
||||
},
|
||||
async: false,
|
||||
expression: true,
|
||||
generator: false,
|
||||
};
|
||||
}
|
||||
|
||||
export function getFromPrepared(code: string): {
|
||||
@@ -108,3 +159,31 @@ export function getFromPrepared(code: string): {
|
||||
Function("_result", code)(resultObj);
|
||||
return resultObj;
|
||||
}
|
||||
|
||||
function multiTry(
|
||||
generators: ESTree.ArrowFunctionExpression[],
|
||||
): ESTree.ArrowFunctionExpression {
|
||||
return generateArrowFunction(`
|
||||
(_input) => {
|
||||
const _results = new Set();
|
||||
const errors = [];
|
||||
for (const _generator of ${generate({
|
||||
type: "ArrayExpression",
|
||||
elements: generators,
|
||||
} as ESTree.Node)}) {
|
||||
try {
|
||||
_results.add(_generator(_input));
|
||||
} catch (e) {
|
||||
errors.push(e);
|
||||
}
|
||||
}
|
||||
if (!_results.size) {
|
||||
throw \`no solutions: \${errors.join(", ")}\`;
|
||||
}
|
||||
if (_results.size !== 1) {
|
||||
throw \`invalid solutions: \${[..._results].map(x => JSON.stringify(x)).join(", ")}\`;
|
||||
}
|
||||
return _results.values().next().value;
|
||||
}
|
||||
`);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,13 @@
|
||||
import { players, tests } from "./tests.ts";
|
||||
import { getCachePath } from "./utils.ts";
|
||||
import { getIO } from "./io.ts";
|
||||
|
||||
const io = await getIO();
|
||||
import { downloadCached } from "./utils.ts";
|
||||
|
||||
for (const test of tests) {
|
||||
const variants = test.variants ?? players.keys();
|
||||
for (const variant of variants) {
|
||||
const path = getCachePath(test.player, variant);
|
||||
if (await io.exists(path)) {
|
||||
continue;
|
||||
try {
|
||||
await downloadCached(test.player, variant);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
const playerPath = players.get(variant);
|
||||
const url = `https://www.youtube.com/s/player/${test.player}/${playerPath}`;
|
||||
console.log("Requesting", url);
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
console.error(`Failed to request ${variant} player for ${test.player}`);
|
||||
continue;
|
||||
}
|
||||
await io.write(path, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,293 +10,77 @@ export const tests: {
|
||||
sig?: Step[];
|
||||
}[] = [
|
||||
{
|
||||
player: "3d3ba064",
|
||||
n: [
|
||||
{ input: "ZdZIqFPQK-Ty8wId", expected: "qmtUsIz04xxiNW" },
|
||||
{ input: "4GMrWHyKI5cEvhDO", expected: "N9gmEX7YhKTSmw" },
|
||||
],
|
||||
// 20518
|
||||
player: "edc3ba07",
|
||||
n: [{ input: "BQoJvGBkC2nj1ZZLK-", expected: "-m-se9fQVnvEofLx" }],
|
||||
sig: [
|
||||
{
|
||||
input:
|
||||
"gN7a-hudCuAuPH6fByOk1_GNXN0yNMHShjZXS2VOgsEItAJz0tipeavEOmNdYN-wUtcEqD3bCXjc0iyKfAyZxCBGgIARwsSdQfJ2CJtt",
|
||||
"NJAJEij0EwRgIhAI0KExTgjfPk-MPM9MAdzyyPRt=BM8-XO5tm5hlMCSVpAiEAv7eP3CURqZNSPow8BXXAoazVoXgeMP7gH9BdylHCwgw=gwzz",
|
||||
expected:
|
||||
"ttJC2JfQdSswRAIgGBCxZyAfKyi0cjXCb3gqEctUw-NYdNmOEvaepit0zJAtIEsgOV2SXZjhSHMNy0NXNG_1kNyBf6HPuAuCduh-a7O",
|
||||
"zwg=wgwCHlydB9zg7PMegXoVzaoAXXB8woPSNZqRUC3Pe7vAEiApVSCMlh5mt5OX-8MB=tRPyyEdAM9MPM-kPfjgTxEK0IAhIgRwE0jiz",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "5ec65609",
|
||||
n: [{ input: "0eRGgQWJGfT5rFHFj", expected: "4SvMpDQH-vBJCw" }],
|
||||
// 20521
|
||||
player: "316b61b4",
|
||||
n: [{ input: "IlLiA21ny7gqA2m4p37", expected: "GchRcsUC_WmnhOUVGV" }],
|
||||
sig: [
|
||||
{
|
||||
input:
|
||||
"AAJAJfQdSswRQIhAMG5SN7-cAFChdrE7tLA6grH0rTMICA1mmDc0HoXgW3CAiAQQ4=CspfaF_vt82XH5yewvqcuEkvzeTsbRuHssRMyJQ=I",
|
||||
"NJAJEij0EwRgIhAI0KExTgjfPk-MPM9MAdzyyPRt=BM8-XO5tm5hlMCSVpAiEAv7eP3CURqZNSPow8BXXAoazVoXgeMP7gH9BdylHCwgw=gwzz",
|
||||
expected:
|
||||
"AJfQdSswRQIhAMG5SN7-cAFChdrE7tLA6grI0rTMICA1mmDc0HoXgW3CAiAQQ4HCspfaF_vt82XH5yewvqcuEkvzeTsbRuHssRMyJQ==",
|
||||
"tJAJEij0EwRgIhAI0KExTgjfPk-MPM9MAdzyyPRN=BM8-XO5tm5hlMCSVpAiEAv7eP3CURqZNSPow8BXXAoazVoXgeMP7gH9BdylHCwgw=gwz",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "6742b2b9",
|
||||
// 20522
|
||||
player: "74edf1a3",
|
||||
n: [
|
||||
{ input: "_HPB-7GFg1VTkn9u", expected: "qUAsPryAO_ByYg" },
|
||||
{ input: "K1t_fcB6phzuq2SF", expected: "Y7PcOt3VE62mog" },
|
||||
{ input: "IlLiA21ny7gqA2m4p37", expected: "9nRTxrbM1f0yHg" },
|
||||
{ input: "eabGFpsUKuWHXGh6FR4", expected: "izmYqDEY6kl7Sg" },
|
||||
{ input: "eabGF/ps%UK=uWHXGh6FR4", expected: "LACmqlhaBpiPlgE-a" },
|
||||
],
|
||||
sig: [
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
"NJAJEij0EwRgIhAI0KExTgjfPk-MPM9MAdzyyPRt=BM8-XO5tm5hlMCSVpAiEAv7eP3CURqZNSPow8BXXAoazVoXgeMP7gH9BdylHCwgw=gwzz",
|
||||
expected:
|
||||
"AJfQdSswRAIgMVVvrovTbw6UNh99kPa4D_XQjGT4qYu7S6SHM8EjoCACIEQnz-nKN5RgG6iUTnNJC58csYPSrnS_SzricuUMJZGM",
|
||||
"NJAJEij0EwRgIhAI0KExTgjfPk-MPM9MAdzyyPRt=BM8-XO5tm5hzMCSVpAiEAv7eP3CURqZNSPow8BXXAoazVoXgeMP7gH9BdylHCwgw=gwzl",
|
||||
},
|
||||
{
|
||||
input:
|
||||
"\x00\x01\x02%\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49",
|
||||
expected:
|
||||
"\x00\x01\x02%\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x40\x41\x42\x49\x44\x45\x46\x47\x48\x43",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "23ccdd25",
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "orSsTqUaUO-j" },
|
||||
],
|
||||
// 20523
|
||||
player: "901741ab",
|
||||
n: [{ input: "BQoJvGBkC2nj1ZZLK-", expected: "UMPovvBZRh-sjb" }],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
"NJAJEij0EwRgIhAI0KExTgjfPk-MPM9MAdzyyPRt=BM8-XO5tm5hlMCSVpAiEAv7eP3CURqZNSPow8BXXAoazVoXgeMP7gH9BdylHCwgw=gwzz",
|
||||
expected:
|
||||
"ZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hAU6wbTvorvVVMgIARwsSdQfJAN",
|
||||
"wgwCHlydB9Hg7PMegXoVzaoAXXB8woPSNZqRUC3Pe7vAEiApVSCMlhwmt5ON-8MB=5RPyyzdAM9MPM-kPfjgTxEK0IAhIgRwE0jiEJA",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "3597727b",
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "PRwo5dDfisg0ejA2" },
|
||||
],
|
||||
// 20524
|
||||
player: "e7573094",
|
||||
n: [{ input: "IlLiA21ny7gqA2m4p37", expected: "3KuQ3235dojTSjo4" }],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
"NJAJEij0EwRgIhAI0KExTgjfPk-MPM9MAdzyyPRt=BM8-XO5tm5hlMCSVpAiEAv7eP3CURqZNSPow8BXXAoazVoXgeMP7gH9BdylHCwgw=gwzz",
|
||||
expected:
|
||||
"AAJfQdSswRAIgMVVvrovTbw6UNh99kPa4D_XQjGT4qYuMS6SHM8Ej7CACIEQnz-nKN5RgG6iUTnNJC58csYPSroS_SzricuUMJZG",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
// tce causes exception even in browser
|
||||
player: "3752a005",
|
||||
variants: ["main", "tcc", "es5", "es6", "tv", "tv_es6", "phone"],
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "j22ZtsqVsR0Dn" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
expected:
|
||||
"ZJM_ucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHG6S7uYq4TGjQXSD4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
// tce causes exception even in browser
|
||||
player: "afc7785b",
|
||||
variants: ["main", "tcc", "es5", "es6", "tv", "tv_es6", "phone"],
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "j22ZtsqVsR0Dn" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
expected:
|
||||
"ZJM_ucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHG6S7uYq4TGjQXSD4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
// tce causes exception even in browser
|
||||
player: "b9645327",
|
||||
variants: ["main", "tcc", "es5", "es6", "tv", "tv_es6", "phone"],
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "j22ZtsqVsR0Dn" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
expected:
|
||||
"ZJM_ucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHG6S7uYq4TGjQXSD4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
// tce causes exception even in browser
|
||||
player: "035b9195",
|
||||
variants: ["main", "tcc", "es5", "es6", "tv", "tv_es6", "phone"],
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "j22ZtsqVsR0Dn" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
expected:
|
||||
"ZJM_ucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHG6S7uYq4TGjQXSD4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "6740c111",
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "AVsXYE0uE1k8e" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
expected:
|
||||
"JfQdSswRAIgMVVvrovTbw6UNh99kPa4D_XQjGT4qYu7S6SHM8EjoCACIEQnz-MKN5RgG6iUTnNJC58csYPSrnS_SzricuUMJZGn",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "f6a4f3bc",
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "H1NKYFbhlqZ" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
expected:
|
||||
"JfQdSswRAIgMVVvrovTbw6UNh99kPa4D_XQjGT4qYM7S6SHM8EjoCACIEQnz-nKM5RgG6iUTnNJC58cNYPSrnS_SzricuUMJZGu",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "b66835e2",
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "H1NKYFbhlqZ" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
expected:
|
||||
"JfQdSswRAIgMVVvrovTbw6UNh99kPa4D_XQjGT4qYM7S6SHM8EjoCACIEQnz-nKM5RgG6iUTnNJC58cNYPSrnS_SzricuUMJZGu",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "4f8fa943",
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "JWWr7hDSRpMq5" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
expected:
|
||||
"AAJfQdSswRAIgMVVvrovTbw6UNh99kPa4D_XQjGT4qYu7S6SHr8EjoCACIEQnz-nKN5RgG6iUTnNZC58csYPSMnS_SzricuUM",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "0004de42",
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "OPd7UEsCDmCw4qD0" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJAA",
|
||||
expected:
|
||||
"ZJMUucirzS_SnrSPYsc85MJNnTUi6GgR5NCn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQ",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "2b83d2e0",
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "0eRGgQWJGfT5rFHFj", expected: "euHbygrCMLksxd" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJA",
|
||||
expected:
|
||||
"-MGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKnMznQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJ",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "638ec5c6",
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "ZdZIqFPQK-Ty8wId", expected: "1qov8-KM-yH" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"gN7a-hudCuAuPH6fByOk1_GNXN0yNMHShjZXS2VOgsEItAJz0tipeavEOmNdYN-wUtcEqD3bCXjc0iyKfAyZxCBGgIARwsSdQfJ2CJtt",
|
||||
expected:
|
||||
"MhudCuAuP-6fByOk1_GNXN7gNHHShjyXS2VOgsEItAJz0tipeav0OmNdYN-wUtcEqD3bCXjc0iyKfAyZxCBGgIARwsSdQfJ2CJtt",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
player: "87644c66",
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "ZdZIqFPQK-Ty8wId", expected: "iF5NxEm1BYk" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"gN7a-hudCuAuPH6fByOk1_GNXN0yNMHShjZXS2VOgsEItAJz0tipeavEOmNdYN-wUtcEqD3bCXjc0iyKfAyZxCBGgIARwsSdQfJ2CJtt",
|
||||
expected:
|
||||
"atJC2JfQdSswRAtgGBCxZyAfKyi0cjXCb3DqEctUw-NYdNmOEvIepit0zJAtIEsgOV2SXZjhSHMNy0NXNG_1kOyBf6HPuAuCduh-a7Ng",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
// tce variant broke sig solving; n and other variants are added only for regression testing
|
||||
player: "c1c87fb0",
|
||||
n: [
|
||||
// Synthetic test
|
||||
{ input: "ZdZIqFPQK-Ty8wId", expected: "jCHBK5GuAFNa2" },
|
||||
],
|
||||
sig: [
|
||||
// Synthetic test
|
||||
{
|
||||
input:
|
||||
"gN7a-hudCuAuPH6fByOk1_GNXN0yNMHShjZXS2VOgsEItAJz0tipeavEOmNdYN-wUtcEqD3bCXjc0iyKfAyZxCBGgIARwsSdQfJ2CJtt",
|
||||
expected:
|
||||
"ttJC2JfQdSswRAIgGBCxZyAfKyi0cjXCb3DqEctUw-NYdNmOEvaepit0zJAtIEsgOV2SXZjhSHMNy0NXNGa1kOyBf6HPuAuCduh-_",
|
||||
"yEij0EwRgIhAI0KExTgjfPk-MPM9MAdzyNPRt=BM8-XO5tm5hlMCSVNAiEAvpeP3CURqZJSPow8BXXAoazVoXgeMP7gH9BdylHCwgw=g",
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -306,11 +90,12 @@ export const players = new Map([
|
||||
["main", "player_ias.vflset/en_US/base.js"],
|
||||
["tcc", "player_ias_tcc.vflset/en_US/base.js"],
|
||||
["tce", "player_ias_tce.vflset/en_US/base.js"],
|
||||
["es5", "player_es5.vflset/en_US/base.js"],
|
||||
["es6", "player_es6.vflset/en_US/base.js"],
|
||||
["tv", "tv-player-ias.vflset/tv-player-ias.js"],
|
||||
["tv_es6", "tv-player-es6.vflset/tv-player-es6.js"],
|
||||
["phone", "player-plasma-ias-phone-en_US.vflset/base.js"],
|
||||
["es6_tcc", "player_es6_tcc.vflset/en_US/base.js"],
|
||||
["es6_tce", "player_es6_tce.vflset/en_US/base.js"],
|
||||
] as const);
|
||||
|
||||
export type Variant = typeof players extends Map<infer T, unknown> ? T : never;
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
import { type Variant } from "./tests.ts";
|
||||
import { getIO } from "./io.ts";
|
||||
import { players, type Variant } from "./tests.ts";
|
||||
|
||||
export function getCachePath(player: string, variant: Variant) {
|
||||
return `src/yt/solver/test/players/${player}-${variant}`;
|
||||
}
|
||||
|
||||
export async function downloadCached(player: string, variant: string) {
|
||||
const io = await getIO();
|
||||
|
||||
const playerPath = players.get(variant as Variant);
|
||||
if (!playerPath) {
|
||||
throw `Invalid player variant: ${variant}`;
|
||||
}
|
||||
const path = getCachePath(player, variant as Variant);
|
||||
if (!(await io.exists(path))) {
|
||||
const url = `https://www.youtube.com/s/player/${player}/${playerPath}`;
|
||||
console.log("Requesting", url);
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw `Failed to request ${variant} player for ${player}`;
|
||||
}
|
||||
await io.write(path, response);
|
||||
}
|
||||
return await io.read(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user