mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-28 09:06:51 +00:00
fix(Player): Fix global variable extraction in the deciphering code (#1029)
This commit is contained in:
@@ -286,7 +286,7 @@ export default class Player {
|
||||
if (!functions || !var_name)
|
||||
Log.warn(TAG, 'Failed to extract signature decipher algorithm.');
|
||||
|
||||
return `${global_variable?.result || ''} function descramble_sig(${var_name}) { let ${obj_name}={${functions}}; ${match[2]} } descramble_sig(sig);`;
|
||||
return `${global_variable?.result ? `var ${global_variable.result};` : ''} function descramble_sig(${var_name}) { let ${obj_name}={${functions}}; ${match[2]} } descramble_sig(sig);`;
|
||||
}
|
||||
|
||||
static extractNSigSourceCode(data: string, ast?: ReturnType<typeof Jinter.parseScript>, global_variable?: ASTLookupResult): string | undefined {
|
||||
@@ -303,7 +303,7 @@ export default class Player {
|
||||
nsig_function = findFunction(data, { includes: '.reverse().forEach(function', ast });
|
||||
|
||||
if (nsig_function)
|
||||
return `${global_variable.result} var ${nsig_function.result} ${nsig_function.name}(nsig);`;
|
||||
return `var ${global_variable.result}; var ${nsig_function.result} ${nsig_function.name}(nsig);`;
|
||||
}
|
||||
|
||||
// This is the suffix of the error tag.
|
||||
|
||||
@@ -353,7 +353,7 @@ export function findFunction(source: string, args: ASTLookupArgs): ASTLookupResu
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for a variable declaration in the given code based on specified criteria.
|
||||
* Searches for a variable declarator in the given code based on specified criteria.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
@@ -381,23 +381,21 @@ export function findVariable(code: string, options: ASTLookupArgs): ASTLookupRes
|
||||
function walk(node: Node): void {
|
||||
if (found) return;
|
||||
|
||||
if (node.type === 'VariableDeclaration') {
|
||||
if (node.type === 'VariableDeclarator') {
|
||||
const [ start, end ] = node.range!;
|
||||
const node_source = code.slice(start, end);
|
||||
|
||||
for (const declarator of node.declarations) {
|
||||
if (declarator.id.type === 'Identifier') {
|
||||
const var_name = declarator.id.name;
|
||||
if (options.name && var_name === options.name) {
|
||||
found = { start, end, name: var_name, node, result: node_source };
|
||||
return;
|
||||
}
|
||||
if (node.id.type === 'Identifier') {
|
||||
const var_name = node.id.name;
|
||||
if (options.name && var_name === options.name) {
|
||||
found = { start, end, name: var_name, node, result: node_source };
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (
|
||||
(options.includes && node_source.includes(options.includes)) ||
|
||||
(options.regexp && options.regexp.test(node_source))) {
|
||||
found = { start, end, name: (node.declarations?.[0]?.id as any)?.name, node, result: node_source };
|
||||
found = { start, end, name: (node?.id as any)?.name, node, result: node_source };
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user