mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-23 23:09:28 +00:00
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:
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user