Quality process updated
This commit is contained in:
parent
76b5c6c272
commit
5befd9a4f4
@ -39,9 +39,9 @@ export async function stream(url: string, quality?: number): Promise<Stream> {
|
|||||||
if (data instanceof SoundCloudPlaylist) throw new Error("Streams can't be created from Playlist url");
|
if (data instanceof SoundCloudPlaylist) throw new Error("Streams can't be created from Playlist url");
|
||||||
|
|
||||||
const HLSformats = parseHlsFormats(data.formats);
|
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 <= 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 req_url = HLSformats[quality].url + '?client_id=' + soundData.client_id;
|
||||||
const s_data = JSON.parse(await request(req_url));
|
const s_data = JSON.parse(await request(req_url));
|
||||||
const type = HLSformats[quality].format.mime_type.startsWith('audio/ogg')
|
const type = HLSformats[quality].format.mime_type.startsWith('audio/ogg')
|
||||||
@ -52,9 +52,9 @@ export async function stream(url: string, quality?: number): Promise<Stream> {
|
|||||||
|
|
||||||
export async function stream_from_info(data: SoundCloudTrack, quality?: number): Promise<Stream> {
|
export async function stream_from_info(data: SoundCloudTrack, quality?: number): Promise<Stream> {
|
||||||
const HLSformats = parseHlsFormats(data.formats);
|
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 <= 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 req_url = HLSformats[quality].url + '?client_id=' + soundData.client_id;
|
||||||
const s_data = JSON.parse(await request(req_url));
|
const s_data = JSON.parse(await request(req_url));
|
||||||
const type = HLSformats[quality].format.mime_type.startsWith('audio/ogg')
|
const type = HLSformats[quality].format.mime_type.startsWith('audio/ogg')
|
||||||
|
|||||||
@ -54,9 +54,9 @@ export async function stream(url: string, options: StreamOptions = {}): Promise<
|
|||||||
}
|
}
|
||||||
|
|
||||||
const audioFormat = parseAudioFormats(info.format);
|
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 <= 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]);
|
final.push(audioFormat[options.quality]);
|
||||||
let type: StreamType =
|
let type: StreamType =
|
||||||
audioFormat[options.quality].codec === 'opus' && audioFormat[options.quality].container === 'webm'
|
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);
|
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 <= 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]);
|
final.push(audioFormat[options.quality]);
|
||||||
let type: StreamType =
|
let type: StreamType =
|
||||||
audioFormat[options.quality].codec === 'opus' && audioFormat[options.quality].container === 'webm'
|
audioFormat[options.quality].codec === 'opus' && audioFormat[options.quality].container === 'webm'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user