feat: improve support for dubbed content (#293)

* feat(Format): add `language`, `is_dubbed` and `is_original`

* feat: add a format filtering option to the DASH function
> And a simple language option to VideoInfo's download method.

* chore: update docs

* feat: improve audio track info parsing

* feat(Format): parse `audioTrack` prop
This commit is contained in:
LuanRT
2023-01-27 00:42:20 -03:00
committed by GitHub
parent 0fc29f0bbf
commit d6c5a9b971
9 changed files with 90 additions and 21 deletions

View File

@@ -28,12 +28,20 @@ class Format {
cipher: string | undefined;
signature_cipher: string | undefined;
audio_quality: string | undefined;
audio_track?: {
audio_is_default: boolean;
display_name: string;
id: string;
};
approx_duration_ms: number;
audio_sample_rate: number;
audio_channels: number;
loudness_db: number;
has_audio: boolean;
has_video: boolean;
language?: string | null;
is_dubbed?: boolean;
is_original?: boolean;
constructor(data: any) {
this.itag = data.itag;
@@ -68,6 +76,23 @@ class Format {
this.loudness_db = data.loudnessDb;
this.has_audio = !!data.audioBitrate || !!data.audioQuality;
this.has_video = !!data.qualityLabel;
if (this.has_audio) {
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_original = url_components.get('xtags')?.split(':').find((x: string) => x.startsWith('acont='))?.split('=').at(1) === 'original' || !this.is_dubbed;
if (data.audioTrack) {
this.audio_track = {
audio_is_default: data.audioTrack.audioIsDefault,
display_name: data.audioTrack.displayName,
id: data.audioTrack.id
};
}
}
}
/**