From 28b429f5ed7f4b6091f37e76d84847d5d87b6bca Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Thu, 4 Nov 2021 19:05:02 +0100 Subject: [PATCH] Clean up unneeded export, variables and assignment after reverse() --- play-dl/YouTube/classes/LiveStream.ts | 2 +- play-dl/YouTube/utils/cipher.ts | 11 ++++------- play-dl/YouTube/utils/extractor.ts | 5 ++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/play-dl/YouTube/classes/LiveStream.ts b/play-dl/YouTube/classes/LiveStream.ts index ce29889..4a6fc47 100644 --- a/play-dl/YouTube/classes/LiveStream.ts +++ b/play-dl/YouTube/classes/LiveStream.ts @@ -207,7 +207,7 @@ export class Stream { this.stream.push(c); }); - stream.once('error', async (err) => { + stream.once('error', async () => { this.cleanup(); await this.retry(); this.timer.reuse(); diff --git a/play-dl/YouTube/utils/cipher.ts b/play-dl/YouTube/utils/cipher.ts index b2bf2f7..d7d9434 100644 --- a/play-dl/YouTube/utils/cipher.ts +++ b/play-dl/YouTube/utils/cipher.ts @@ -42,7 +42,7 @@ const swap_regexp = new RegExp(`(?:^|,)(${key_js})${swap_function}`, 'm'); * @param body body data of html5player. * @returns Array of tokens. */ -export function js_tokens(body: string) { +function js_tokens(body: string) { const function_action = function_regexp.exec(body); const object_action = obj_regexp.exec(body); if (!function_action || !object_action) return null; @@ -104,7 +104,7 @@ function deciper_signature(tokens: string[], signature: string) { sig = swappositions(sig, pos); break; case 'rv': - sig = sig.reverse(); + sig.reverse(); break; case 'sl': pos = parseInt(token.slice(2)); @@ -137,11 +137,9 @@ function swappositions(array: string[], position: number) { * @returns void */ function download_url(format: formatOptions, sig: string) { - let decoded_url; if (!format.url) return; - decoded_url = format.url; - decoded_url = decodeURIComponent(decoded_url); + const decoded_url = decodeURIComponent(format.url); const parsed_url = new URL(decoded_url); parsed_url.searchParams.set('ratebypass', 'yes'); @@ -168,9 +166,8 @@ export async function format_decipher(formats: formatOptions[], html5player: str delete format.signatureCipher; delete format.cipher; } - let sig; if (tokens && format.s) { - sig = deciper_signature(tokens, format.s); + const sig = deciper_signature(tokens, format.s); download_url(format, sig); delete format.s; delete format.sp; diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index 30cdd49..6534d59 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -375,7 +375,6 @@ function parseDuration(duration: string): number { * @returns token */ export function getContinuationToken(data: any): string { - const continuationToken = data.find((x: any) => Object.keys(x)[0] === 'continuationItemRenderer') - ?.continuationItemRenderer.continuationEndpoint?.continuationCommand?.token; - return continuationToken; + return data.find((x: any) => Object.keys(x)[0] === 'continuationItemRenderer')?.continuationItemRenderer + .continuationEndpoint?.continuationCommand?.token; }