chore: clean up

This commit is contained in:
Luan
2024-10-28 12:51:53 -03:00
parent 01057f6dfa
commit d84273163f
4 changed files with 59 additions and 44 deletions

View File

@@ -1,7 +1,35 @@
import type Player from '../../../core/Player.js';
import { InnertubeError } from '../../../utils/Utils.js';
import type { RawNode } from '../../index.js';
export type ProjectionType = 'RECTANGULAR' | 'EQUIRECTANGULAR' | 'EQUIRECTANGULAR_THREED_TOP_BOTTOM' | 'MESH';
export type SpatialAudioType = 'AMBISONICS_5_1' | 'AMBISONICS_QUAD' | 'FOA_WITH_NON_DIEGETIC';
export type StereoLayout = 'LEFT_RIGHT' | 'TOP_BOTTOM';
export type Range = {
start: number;
end: number;
};
export type ColorInfo = {
primaries?: string;
transfer_characteristics?: string;
matrix_coefficients?: string;
};
export type AudioTrack = {
audio_is_default: boolean;
display_name: string;
id: string;
};
export type CaptionTrack = {
display_name: string;
vss_id: string;
language_code: string;
kind?: 'asr' | 'frc';
id: string;
};
export default class Format {
#this_response_nsig_cache?: Map<string, string>;
@@ -17,13 +45,13 @@ export default class Format {
drm_families?: string[];
fps?: number;
quality_label?: string;
projection_type?: 'RECTANGULAR' | 'EQUIRECTANGULAR' | 'EQUIRECTANGULAR_THREED_TOP_BOTTOM' | 'MESH';
projection_type?: ProjectionType;
average_bitrate?: number;
bitrate: number;
spatial_audio_type?: 'AMBISONICS_5_1' | 'AMBISONICS_QUAD' | 'FOA_WITH_NON_DIEGETIC';
spatial_audio_type?: SpatialAudioType;
target_duration_dec?: number;
fair_play_key_uri?: string;
stereo_layout?: 'LEFT_RIGHT' | 'TOP_BOTTOM';
stereo_layout?: StereoLayout;
max_dvr_duration_sec?: number;
high_replication?: boolean;
audio_quality?: string;
@@ -38,20 +66,10 @@ export default class Format {
track_absolute_loudness_lkfs?: number;
mime_type: string;
is_type_otf: boolean;
init_range?: {
start: number;
end: number;
};
index_range?: {
start: number;
end: number;
};
init_range?: Range;
index_range?: Range;
cipher?: string;
audio_track?: {
audio_is_default: boolean;
display_name: string;
id: string;
};
audio_track?: AudioTrack;
has_audio: boolean;
has_video: boolean;
has_text: boolean;
@@ -60,23 +78,12 @@ export default class Format {
is_descriptive?: boolean;
is_secondary?: boolean;
is_original?: boolean;
color_info?: {
primaries?: string;
transfer_characteristics?: string;
matrix_coefficients?: string;
};
caption_track?: {
display_name: string;
vss_id: string;
language_code: string;
kind?: 'asr' | 'frc';
id: string;
};
color_info?: ColorInfo;
caption_track?: CaptionTrack;
constructor(data: RawNode, this_response_nsig_cache?: Map<string, string>) {
if (this_response_nsig_cache) {
if (this_response_nsig_cache)
this.#this_response_nsig_cache = this_response_nsig_cache;
}
this.itag = data.itag;
this.mime_type = data.mimeType;
@@ -228,11 +235,13 @@ export default class Format {
}
/**
* Deciphers the streaming url of the format.
* @returns Deciphered URL.
* Deciphers the URL using the provided player instance.
* @param player - An optional instance of the Player class used to decipher the URL.
* @returns The deciphered URL as a string. If no player is provided, returns the original URL or an empty string.
*/
decipher(player: Player | undefined): string {
if (!player) throw new InnertubeError('Cannot decipher format, this session appears to have no valid player.');
decipher(player?: Player): string {
if (!player)
return this.url || '';
return player.decipher(this.url, this.signature_cipher, this.cipher, this.#this_response_nsig_cache);
}
}