Rename nsig -> n

This commit is contained in:
coletdjnz
2025-09-26 17:16:09 +12:00
parent 7f0e9b267e
commit f7ec2da899
8 changed files with 43 additions and 35 deletions

View File

@@ -1,11 +1,19 @@
# yt-dlp-ejs
> [!CAUTION]
> This is currently in development
External JavaScript for yt-dlp supporting many runtimes
## Installation
## Manual Installation
In the yt-dlp repository, install the python package, either directly or from url:
In the yt-dlp repository, install the python package, directly:
```console
pip install git+https://github.com/yt-dlp/ejs@main
npm install
pip install .
```
## Tests
todo

2
package-lock.json generated
View File

@@ -1,5 +1,5 @@
{
"name": "yt-dlp-jsc-deno",
"name": "ejs",
"lockfileVersion": 3,
"requires": true,
"packages": {

6
run.ts
View File

@@ -16,12 +16,12 @@ if (args.length < 2) {
const player = readFileSync(args[0], "utf-8");
const requests = {
nsig: [] as string[],
n: [] as string[],
sig: [] as string[],
};
for (const request of args.slice(1)) {
const [type, challenge] = request.split(":", 2);
if (!isOneOf(type, "sig", "nsig")) {
if (!isOneOf(type, "sig", "n")) {
console.error(`ERROR: Unsupported request type: ${type}`);
exit(1);
}
@@ -32,7 +32,7 @@ console.log(JSON.stringify(main({
player,
output_preprocessed: false,
requests: [
{ type: "nsig", challenges: requests.nsig },
{ type: "n", challenges: requests.n },
{ type: "sig", challenges: requests.sig },
],
})));

View File

@@ -9,7 +9,7 @@ export default function main(input: Input): Output {
const responses = input.requests.map(
(input): Response => {
if (!isOneOf(input.type, "nsig", "sig")) {
if (!isOneOf(input.type, "n", "sig")) {
return {
type: "error",
error: `Unknown request type: ${input.type}`,
@@ -64,7 +64,7 @@ export type Input =
};
type Request = {
type: "nsig" | "sig";
type: "n" | "sig";
challenges: string[];
};

View File

@@ -116,7 +116,7 @@ function makeSolverFuncFromName(name: string): ESTree.ArrowFunctionExpression {
params: [
{
type: "Identifier",
name: "nsig",
name: "n",
},
],
body: {
@@ -128,7 +128,7 @@ function makeSolverFuncFromName(name: string): ESTree.ArrowFunctionExpression {
arguments: [
{
type: "Identifier",
name: "nsig",
name: "n",
},
],
optional: false,

View File

@@ -11,7 +11,7 @@ for (const test of tests) {
await io.test(`${test.player} ${variant}`, async (assert, subtest) => {
const content = await io.read(path);
const solvers = getFromPrepared(preprocessPlayer(content));
for (const mode of ["nsig", "sig"] as const) {
for (const mode of ["n", "sig"] as const) {
for (const step of test[mode] || []) {
await subtest(`${step.input} (${mode})`, () => {
const got = solvers[mode]?.(step.input);

View File

@@ -1,7 +1,7 @@
import { type ESTree, parse } from "meriyah";
import { generate } from "astring";
import { extract as extractSig } from "./sig.ts";
import { extract as extractNsig } from "./nsig.ts";
import { extract as extractN } from "./n.ts";
import { setupNodes } from "./setup.ts";
export function preprocessPlayer(data: string): string {
@@ -41,13 +41,13 @@ export function preprocessPlayer(data: string): string {
})();
const found = {
nsig: [] as ESTree.ArrowFunctionExpression[],
n: [] as ESTree.ArrowFunctionExpression[],
sig: [] as ESTree.ArrowFunctionExpression[],
};
const plainExpressions = block.body.filter((node: ESTree.Node) => {
const nsig = extractNsig(node);
if (nsig) {
found.nsig.push(nsig);
const n = extractN(node);
if (n) {
found.n.push(n);
}
const sig = extractSig(node);
if (sig) {
@@ -101,10 +101,10 @@ export function preprocessPlayer(data: string): string {
}
export function getFromPrepared(code: string): {
nsig: ((val: string) => string) | null;
n: ((val: string) => string) | null;
sig: ((val: string) => string) | null;
} {
const resultObj = { nsig: null, sig: null };
const resultObj = { n: null, sig: null };
Function("_result", code)(resultObj);
return resultObj;
}

View File

@@ -6,12 +6,12 @@ type Step = {
export const tests: {
player: string;
variants?: Variant[];
nsig?: Step[];
n?: Step[];
sig?: Step[];
}[] = [
{
player: "3d3ba064",
nsig: [
n: [
{ input: "ZdZIqFPQK-Ty8wId", expected: "qmtUsIz04xxiNW" },
{ input: "4GMrWHyKI5cEvhDO", expected: "N9gmEX7YhKTSmw" },
],
@@ -26,7 +26,7 @@ export const tests: {
},
{
player: "5ec65609",
nsig: [{ input: "0eRGgQWJGfT5rFHFj", expected: "4SvMpDQH-vBJCw" }],
n: [{ input: "0eRGgQWJGfT5rFHFj", expected: "4SvMpDQH-vBJCw" }],
sig: [
{
input:
@@ -38,7 +38,7 @@ export const tests: {
},
{
player: "6742b2b9",
nsig: [
n: [
{ input: "_HPB-7GFg1VTkn9u", expected: "qUAsPryAO_ByYg" },
{ input: "K1t_fcB6phzuq2SF", expected: "Y7PcOt3VE62mog" },
],
@@ -53,7 +53,7 @@ export const tests: {
},
{
player: "23ccdd25",
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "orSsTqUaUO-j" },
],
@@ -69,7 +69,7 @@ export const tests: {
},
{
player: "3597727b",
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "PRwo5dDfisg0ejA2" },
],
@@ -87,7 +87,7 @@ export const tests: {
// tce causes exception even in browser
player: "3752a005",
variants: ["main", "tcc", "es5", "es6", "tv", "tv_es6", "phone", "tablet"],
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "j22ZtsqVsR0Dn" },
],
@@ -105,7 +105,7 @@ export const tests: {
// tce causes exception even in browser
player: "afc7785b",
variants: ["main", "tcc", "es5", "es6", "tv", "tv_es6", "phone", "tablet"],
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "j22ZtsqVsR0Dn" },
],
@@ -123,7 +123,7 @@ export const tests: {
// tce causes exception even in browser
player: "b9645327",
variants: ["main", "tcc", "es5", "es6", "tv", "tv_es6", "phone", "tablet"],
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "j22ZtsqVsR0Dn" },
],
@@ -141,7 +141,7 @@ export const tests: {
// tce causes exception even in browser
player: "035b9195",
variants: ["main", "tcc", "es5", "es6", "tv", "tv_es6", "phone", "tablet"],
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "j22ZtsqVsR0Dn" },
],
@@ -157,7 +157,7 @@ export const tests: {
},
{
player: "6740c111",
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "AVsXYE0uE1k8e" },
],
@@ -173,7 +173,7 @@ export const tests: {
},
{
player: "f6a4f3bc",
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "H1NKYFbhlqZ" },
],
@@ -189,7 +189,7 @@ export const tests: {
},
{
player: "b66835e2",
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "H1NKYFbhlqZ" },
],
@@ -205,7 +205,7 @@ export const tests: {
},
{
player: "4f8fa943",
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "JWWr7hDSRpMq5" },
],
@@ -221,7 +221,7 @@ export const tests: {
},
{
player: "0004de42",
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "OPd7UEsCDmCw4qD0" },
],
@@ -237,7 +237,7 @@ export const tests: {
},
{
player: "2b83d2e0",
nsig: [
n: [
// Synthetic test
{ input: "0eRGgQWJGfT5rFHFj", expected: "euHbygrCMLksxd" },
],