Skip to content

Commit

Permalink
perf(Format): Cleanup the xtags parsing (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Jul 11, 2023
1 parent 5f058e6 commit 1ca2083
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/parser/classes/misc/Format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 1ca2083

Please sign in to comment.