diff --git a/play-dl/SoundCloud/index.ts b/play-dl/SoundCloud/index.ts index 55efd7a..776ff8c 100644 --- a/play-dl/SoundCloud/index.ts +++ b/play-dl/SoundCloud/index.ts @@ -39,9 +39,9 @@ export async function stream(url: string, quality?: number): Promise { if (data instanceof SoundCloudPlaylist) throw new Error("Streams can't be created from Playlist url"); const HLSformats = parseHlsFormats(data.formats); - if (!quality) quality = HLSformats.length - 1; + if (typeof quality !== 'number') quality = HLSformats.length - 1; else if (quality <= 0) quality = 0; - else if (quality > HLSformats.length) quality = HLSformats.length - 1; + else if (quality >= HLSformats.length) quality = HLSformats.length - 1; const req_url = HLSformats[quality].url + '?client_id=' + soundData.client_id; const s_data = JSON.parse(await request(req_url)); const type = HLSformats[quality].format.mime_type.startsWith('audio/ogg') @@ -52,9 +52,9 @@ export async function stream(url: string, quality?: number): Promise { export async function stream_from_info(data: SoundCloudTrack, quality?: number): Promise { const HLSformats = parseHlsFormats(data.formats); - if (!quality) quality = HLSformats.length - 1; + if (typeof quality !== 'number') quality = HLSformats.length - 1; else if (quality <= 0) quality = 0; - else if (quality > HLSformats.length) quality = HLSformats.length - 1; + else if (quality >= HLSformats.length) quality = HLSformats.length - 1; const req_url = HLSformats[quality].url + '?client_id=' + soundData.client_id; const s_data = JSON.parse(await request(req_url)); const type = HLSformats[quality].format.mime_type.startsWith('audio/ogg') diff --git a/play-dl/YouTube/stream.ts b/play-dl/YouTube/stream.ts index 15f840d..02332d0 100644 --- a/play-dl/YouTube/stream.ts +++ b/play-dl/YouTube/stream.ts @@ -54,9 +54,9 @@ export async function stream(url: string, options: StreamOptions = {}): Promise< } const audioFormat = parseAudioFormats(info.format); - if (!options.quality) options.quality = audioFormat.length - 1; + if (typeof options.quality !== 'number') options.quality = audioFormat.length - 1; else if (options.quality <= 0) options.quality = 0; - else if (options.quality > audioFormat.length) options.quality = audioFormat.length - 1; + else if (options.quality >= audioFormat.length) options.quality = audioFormat.length - 1; final.push(audioFormat[options.quality]); let type: StreamType = audioFormat[options.quality].codec === 'opus' && audioFormat[options.quality].container === 'webm' @@ -87,9 +87,9 @@ export async function stream_from_info(info: InfoData, options: StreamOptions = } const audioFormat = parseAudioFormats(info.format); - if (!options.quality) options.quality = audioFormat.length - 1; + if (typeof options.quality !== 'number') options.quality = audioFormat.length - 1; else if (options.quality <= 0) options.quality = 0; - else if (options.quality > audioFormat.length) options.quality = audioFormat.length - 1; + else if (options.quality >= audioFormat.length) options.quality = audioFormat.length - 1; final.push(audioFormat[options.quality]); let type: StreamType = audioFormat[options.quality].codec === 'opus' && audioFormat[options.quality].container === 'webm'