From 1ca20836bf343c78461fab7ad3b71db2b96e65c3 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Tue, 11 Jul 2023 20:45:42 +0200 Subject: [PATCH] perf(Format): Cleanup the xtags parsing (#434) --- src/parser/classes/misc/Format.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/parser/classes/misc/Format.ts b/src/parser/classes/misc/Format.ts index c1baec99..50c60262 100644 --- a/src/parser/classes/misc/Format.ts +++ b/src/parser/classes/misc/Format.ts @@ -97,10 +97,14 @@ export default class Format { const args = new URLSearchParams(this.cipher || this.signature_cipher); const url_components = new URLSearchParams(args.get('url') || this.url); - this.language = url_components.get('xtags')?.split(':').find((x: string) => x.startsWith('lang='))?.split('=').at(1) || null; - this.is_dubbed = url_components.get('xtags')?.split(':').find((x: string) => x.startsWith('acont='))?.split('=').at(1) === 'dubbed'; - this.is_descriptive = url_components.get('xtags')?.split(':').find((x: string) => x.startsWith('acont='))?.split('=').at(1) === 'descriptive'; - this.is_original = url_components.get('xtags')?.split(':').find((x: string) => x.startsWith('acont='))?.split('=').at(1) === 'original' || !this.is_dubbed; + const xtags = url_components.get('xtags')?.split(':'); + + const audio_content = xtags?.find((x) => x.startsWith('acont='))?.split('=')[1]; + + this.language = xtags?.find((x: string) => x.startsWith('lang='))?.split('=')[1] || null; + this.is_dubbed = audio_content === 'dubbed'; + this.is_descriptive = audio_content === 'descriptive'; + this.is_original = audio_content === 'original' || !this.is_dubbed || !this.is_descriptive; if (Reflect.has(data, 'audioTrack')) { this.audio_track = {