refactor(Player)!: Use AST-based JS extraction with side-effect safe code emission (#1052)

* chore(deps): Add `meriyah`

* feat(utils): Implement AST-based JS extractors

* chore(utils): Remove old ast walker code

* fix(Player): Migrate js extraction logic

* chore(JsExtractor): Fix typo in tsdoc

* perf(JsAnalyzer): Simplify main AST analysis logic

* fix(JsAnalyzer): Change `break` to `return` in AST matching logic

* chore: Update docs

* chore: Don't export `PlayerInitializationOptions`

* chore(evaluate): Update error message to include doc link

* perf: Use a `for-loop` to find iife
This commit is contained in:
Luan
2025-10-12 09:08:51 -03:00
committed by GitHub
parent bffa92d96e
commit 25d0876b91
873 changed files with 10992 additions and 8345 deletions

View File

@@ -8,7 +8,7 @@ Represents YouTube's player script. This is required to decipher signatures.
### new Player()
> **new Player**(`player_id`, `signature_timestamp`, `sig_sc`?, `nsig_sc`?): [`Player`](Player.md)
> **new Player**(`player_id`, `signature_timestamp`, `data`?): [`Player`](Player.md)
#### Parameters
@@ -16,9 +16,7 @@ Represents YouTube's player script. This is required to decipher signatures.
**signature\_timestamp**: `number`
**sig\_sc?**: `string`
**nsig\_sc?**: `string`
**data?**: [`BuildScriptResult`](../namespaces/Types/interfaces/BuildScriptResult.md)
#### Returns
@@ -26,17 +24,17 @@ Represents YouTube's player script. This is required to decipher signatures.
#### Defined in
[src/core/Player.ts:34](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L34)
[src/core/Player.ts:40](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L40)
## Properties
### nsig\_sc?
### data?
> `optional` **nsig\_sc**: `string`
> `optional` **data**: [`BuildScriptResult`](../namespaces/Types/interfaces/BuildScriptResult.md)
#### Defined in
[src/core/Player.ts:30](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L30)
[src/core/Player.ts:40](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L40)
***
@@ -46,7 +44,7 @@ Represents YouTube's player script. This is required to decipher signatures.
#### Defined in
[src/core/Player.ts:28](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L28)
[src/core/Player.ts:40](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L40)
***
@@ -56,27 +54,17 @@ Represents YouTube's player script. This is required to decipher signatures.
#### Defined in
[src/core/Player.ts:32](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L32)
[src/core/Player.ts:38](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L38)
***
### sig\_sc?
### signature\_timestamp
> `optional` **sig\_sc**: `string`
> **signature\_timestamp**: `number`
#### Defined in
[src/core/Player.ts:31](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L31)
***
### sts
> **sts**: `number`
#### Defined in
[src/core/Player.ts:29](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L29)
[src/core/Player.ts:40](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L40)
## Accessors
@@ -90,7 +78,7 @@ Represents YouTube's player script. This is required to decipher signatures.
#### Defined in
[src/core/Player.ts:324](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L324)
[src/core/Player.ts:284](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L284)
***
@@ -104,7 +92,7 @@ Represents YouTube's player script. This is required to decipher signatures.
#### Defined in
[src/core/Player.ts:328](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L328)
[src/core/Player.ts:288](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L288)
## Methods
@@ -122,13 +110,13 @@ Represents YouTube's player script. This is required to decipher signatures.
#### Defined in
[src/core/Player.ts:223](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L223)
[src/core/Player.ts:270](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L270)
***
### decipher()
> **decipher**(`url`?, `signature_cipher`?, `cipher`?, `this_response_nsig_cache`?): `string`
> **decipher**(`url`?, `signature_cipher`?, `cipher`?, `this_response_nsig_cache`?): `Promise`\<`string`\>
#### Parameters
@@ -142,11 +130,11 @@ Represents YouTube's player script. This is required to decipher signatures.
#### Returns
`string`
`Promise`\<`string`\>
#### Defined in
[src/core/Player.ts:100](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L100)
[src/core/Player.ts:134](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L134)
***
@@ -170,87 +158,7 @@ Represents YouTube's player script. This is required to decipher signatures.
#### Defined in
[src/core/Player.ts:41](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L41)
***
### extractGlobalVariable()
> `static` **extractGlobalVariable**(`data`, `ast`): `undefined` \| [`ASTLookupResult`](../namespaces/Utils/type-aliases/ASTLookupResult.md)
#### Parameters
**data**: `string`
**ast**: `ExtendNode`\<`Program`\>
#### Returns
`undefined` \| [`ASTLookupResult`](../namespaces/Utils/type-aliases/ASTLookupResult.md)
#### Defined in
[src/core/Player.ts:244](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L244)
***
### extractNSigSourceCode()
> `static` **extractNSigSourceCode**(`data`, `ast`?, `global_variable`?): `undefined` \| `string`
#### Parameters
**data**: `string`
**ast?**: `ExtendNode`\<`Program`\>
**global\_variable?**: [`ASTLookupResult`](../namespaces/Utils/type-aliases/ASTLookupResult.md)
#### Returns
`undefined` \| `string`
#### Defined in
[src/core/Player.ts:292](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L292)
***
### extractSigSourceCode()
> `static` **extractSigSourceCode**(`data`, `global_variable`?): `undefined` \| `string`
#### Parameters
**data**: `string`
**global\_variable?**: [`ASTLookupResult`](../namespaces/Utils/type-aliases/ASTLookupResult.md)
#### Returns
`undefined` \| `string`
#### Defined in
[src/core/Player.ts:263](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L263)
***
### extractSigTimestamp()
> `static` **extractSigTimestamp**(`data`): `number`
#### Parameters
**data**: `string`
#### Returns
`number`
#### Defined in
[src/core/Player.ts:240](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L240)
[src/core/Player.ts:42](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L42)
***
@@ -270,25 +178,19 @@ Represents YouTube's player script. This is required to decipher signatures.
#### Defined in
[src/core/Player.ts:195](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L195)
[src/core/Player.ts:243](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L243)
***
### fromSource()
> `static` **fromSource**(`player_id`, `sig_timestamp`, `cache`?, `sig_sc`?, `nsig_sc`?): `Promise`\<[`Player`](Player.md)\>
> `static` **fromSource**(`player_id`, `options`): `Promise`\<[`Player`](Player.md)\>
#### Parameters
**player\_id**: `string`
**sig\_timestamp**: `number`
**cache?**: [`ICache`](../namespaces/Types/interfaces/ICache.md)
**sig\_sc?**: `string`
**nsig\_sc?**: `string`
**options**: `PlayerInitializationOptions`
#### Returns
@@ -296,4 +198,4 @@ Represents YouTube's player script. This is required to decipher signatures.
#### Defined in
[src/core/Player.ts:217](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/core/Player.ts#L217)
[src/core/Player.ts:264](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/core/Player.ts#L264)