Codes made pretty
This commit is contained in:
parent
f304d6bcbd
commit
0b21c1caf9
@ -33,15 +33,15 @@ export async function soundcloud(url: string): Promise<SoundCloudTrack | SoundCl
|
|||||||
else return new SoundCloudPlaylist(json_data, soundData.client_id);
|
else return new SoundCloudPlaylist(json_data, soundData.client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function stream(url: string, quality? : number): Promise<Stream> {
|
export async function stream(url: string, quality?: number): Promise<Stream> {
|
||||||
const data = await soundcloud(url);
|
const data = await soundcloud(url);
|
||||||
|
|
||||||
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 (!quality) 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')
|
||||||
@ -50,11 +50,11 @@ export async function stream(url: string, quality? : number): Promise<Stream> {
|
|||||||
return new Stream(s_data.url, type);
|
return new Stream(s_data.url, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (!quality) 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')
|
||||||
@ -86,10 +86,10 @@ export async function so_validate(url: string): Promise<false | 'track' | 'playl
|
|||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseHlsFormats(data : SoundCloudTrackFormat[]){
|
function parseHlsFormats(data: SoundCloudTrackFormat[]) {
|
||||||
const result: SoundCloudTrackFormat[] = [];
|
const result: SoundCloudTrackFormat[] = [];
|
||||||
data.forEach((format) => {
|
data.forEach((format) => {
|
||||||
if(format.format.protocol === 'hls') result.push(format)
|
if (format.format.protocol === 'hls') result.push(format);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,9 +12,9 @@ import { SoundCloudTrack, Stream as SoStream } from './SoundCloud/classes';
|
|||||||
import { LiveStreaming, Stream as YTStream } from './YouTube/classes/LiveStream';
|
import { LiveStreaming, Stream as YTStream } from './YouTube/classes/LiveStream';
|
||||||
|
|
||||||
export async function stream(url: string, options: StreamOptions = {}): Promise<YTStream | LiveStreaming | SoStream> {
|
export async function stream(url: string, options: StreamOptions = {}): Promise<YTStream | LiveStreaming | SoStream> {
|
||||||
if(url.length === 0) throw new Error('Stream URL has a length of 0. Check your url again.')
|
if (url.length === 0) throw new Error('Stream URL has a length of 0. Check your url again.');
|
||||||
if (url.indexOf('soundcloud') !== -1) return await so_stream(url, options.quality);
|
if (url.indexOf('soundcloud') !== -1) return await so_stream(url, options.quality);
|
||||||
else return await yt_stream(url, { cookie : options.cookie });
|
else return await yt_stream(url, { cookie: options.cookie });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function stream_from_info(
|
export async function stream_from_info(
|
||||||
@ -22,7 +22,7 @@ export async function stream_from_info(
|
|||||||
options: StreamOptions = {}
|
options: StreamOptions = {}
|
||||||
): Promise<YTStream | LiveStreaming | SoStream> {
|
): Promise<YTStream | LiveStreaming | SoStream> {
|
||||||
if (info instanceof SoundCloudTrack) return await so_stream_info(info);
|
if (info instanceof SoundCloudTrack) return await so_stream_info(info);
|
||||||
else return await yt_stream_info(info, { cookie : options.cookie });
|
else return await yt_stream_info(info, { cookie: options.cookie });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function validate(url: string): Promise<string | boolean> {
|
export async function validate(url: string): Promise<string | boolean> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user