From 4b6b6435a602f0959b36ef3c4c217ffda179e297 Mon Sep 17 00:00:00 2001 From: Dylan Nugent Date: Tue, 9 Jul 2024 15:07:15 -0500 Subject: [PATCH] Copy #682 in base repo to fix nsig issues See https://github.com/LuanRT/YouTube.js/pull/682. Original author is absidue; I did not author this code, I just pulled it in here to test it. --- src/core/Player.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/core/Player.ts b/src/core/Player.ts index 4df4b8189..4728a6ac3 100644 --- a/src/core/Player.ts +++ b/src/core/Player.ts @@ -221,12 +221,20 @@ export default class Player { } static extractNSigSourceCode(data: string): string { - const sc = `function descramble_nsig(a) { let b=a.split("")${getStringBetweenStrings(data, 'b=a.split("")', '}return b.join("")}')}} return b.join(""); } descramble_nsig(nsig)`; + let sc = getStringBetweenStrings(data, 'b=a.split("")', '}return b.join("")}'); - if (!sc) - Log.warn(Player.TAG, 'Failed to extract n-token decipher algorithm'); + if (sc) + return `function descramble_nsig(a) { let b=a.split("")${sc}} return b.join(""); } descramble_nsig(nsig)`; - return sc; + sc = getStringBetweenStrings(data, 'b=String.prototype.split.call(a,"")', '}return Array.prototype.join.call(b,"")}'); + + if (sc) + return `function descramble_nsig(a) { let b=String.prototype.split.call(a, "")${sc}} return Array.prototype.join.call(b, ""); } descramble_nsig(nsig)`; + + // We really should throw an error here to avoid errors later, returning a pass-through function for backwards-compatibility + Log.warn(TAG, 'Failed to extract n-token decipher algorithm'); + + return 'function descramble_nsig(a) { return a; } descramble_nsig(nsig)'; } get url(): string { @@ -248,4 +256,4 @@ export default class Player { static get LIBRARY_VERSION(): number { return 2; } -} \ No newline at end of file +}