SoundCloud Work Completed

This commit is contained in:
killer069
2021-09-20 17:20:15 +05:30
parent 4abe6fbdb0
commit 65026abca1
7 changed files with 143 additions and 65 deletions

View File

@@ -64,7 +64,7 @@ export async function spotify(url: string): Promise<SpotifyAlbum | SpotifyPlayli
} else throw new Error('URL is out of scope for play-dl.');
}
export function sp_validate(url: string): 'track' | 'playlist' | 'album' | boolean {
export function sp_validate(url: string): 'track' | 'playlist' | 'album' | false {
if (!url.match(pattern)) return false;
if (url.indexOf('track/') !== -1) {
return 'track';
@@ -105,12 +105,12 @@ export async function SpotifyAuthorize(data: SpotifyDataOptions): Promise<boolea
return true;
}
export function is_expired() {
export function is_expired(): boolean {
if (Date.now() >= (spotifyData.expiry as number)) return true;
else return false;
}
export async function refreshToken(): Promise<true | false> {
export async function refreshToken(): Promise<boolean> {
const response = await request(`https://accounts.spotify.com/api/token`, {
headers: {
'Authorization': `Basic ${Buffer.from(`${spotifyData.client_id}:${spotifyData.client_secret}`).toString(
@@ -123,7 +123,7 @@ export async function refreshToken(): Promise<true | false> {
}).catch((err: Error) => {
return err;
});
if (response instanceof Error) throw response;
if (response instanceof Error) return false;
const resp_json = JSON.parse(response);
spotifyData.access_token = resp_json.access_token;
spotifyData.expires_in = Number(resp_json.expires_in);