From 6a73fa37bae59d20abe38d5a7f215bd915c6027e Mon Sep 17 00:00:00 2001 From: sepro Date: Wed, 22 Oct 2025 20:48:45 +0200 Subject: [PATCH] Fix sig in player `638ec5c6` (#10) --- src/utils.ts | 5 +++++ src/yt/solver/sig.ts | 41 ++++++++++++++++++++++++++++++------- src/yt/solver/test/tests.ts | 18 ++++++++++++++++ 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 38e2d77..a3553a0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -22,6 +22,11 @@ export function matchesStructure( // Handle `{ or: [a, b] }` return structure.or.some((node) => matchesStructure(obj, node)); } + if ("anykey" in structure && Array.isArray(structure.anykey)) { + // Handle `{ anykey: [a, b] }` + const haystack = Array.isArray(obj) ? obj : Object.values(obj); + return structure.anykey.every(value => haystack.some((el) => matchesStructure(el, value))); + } for (const [key, value] of Object.entries(structure)) { if (!matchesStructure(obj[key as keyof typeof obj], value)) { return false; diff --git a/src/yt/solver/sig.ts b/src/yt/solver/sig.ts index 595b586..d3fc837 100644 --- a/src/yt/solver/sig.ts +++ b/src/yt/solver/sig.ts @@ -82,6 +82,20 @@ const identifier = { type: "FunctionDeclaration", params: [{}, {}, {}], }, + { + type: "VariableDeclaration", + declarations: { + anykey: [ + { + type: "VariableDeclarator", + init: { + type: "FunctionExpression", + params: [{}, {}, {}], + }, + }, + ], + }, + }, ], } as const; @@ -93,14 +107,27 @@ export function extract( ) { return null; } - const block = - node.type === "ExpressionStatement" && + let block: ESTree.BlockStatement | undefined | null; + if (node.type === "ExpressionStatement" && node.expression.type === "AssignmentExpression" && - node.expression.right.type === "FunctionExpression" - ? node.expression.right.body - : node.type === "FunctionDeclaration" - ? node.body - : null; + 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); if (!matchesStructure(relevantExpression!, logicalExpression)) { return null; diff --git a/src/yt/solver/test/tests.ts b/src/yt/solver/test/tests.ts index 7071c98..781c4e3 100644 --- a/src/yt/solver/test/tests.ts +++ b/src/yt/solver/test/tests.ts @@ -253,6 +253,24 @@ export const tests: { }, ], }, + { + // TODO: es6/tv_es6 variants currently fail + player: "638ec5c6", + variants: ["main", "tcc", "tce", "es5", "tv", "phone", "tablet"], + n: [ + // Synthetic test + { input: "ZdZIqFPQK-Ty8wId", expected: "1qov8-KM-yH" }, + ], + sig: [ + // Synthetic test + { + input: + "gN7a-hudCuAuPH6fByOk1_GNXN0yNMHShjZXS2VOgsEItAJz0tipeavEOmNdYN-wUtcEqD3bCXjc0iyKfAyZxCBGgIARwsSdQfJ2CJtt", + expected: + "MhudCuAuP-6fByOk1_GNXN7gNHHShjyXS2VOgsEItAJz0tipeav0OmNdYN-wUtcEqD3bCXjc0iyKfAyZxCBGgIARwsSdQfJ2CJtt", + }, + ], + }, ]; export const players = new Map([