const BASE_URL = "https://theaudiodb.com/api/v1/json/2/";
export class AudioDBException extends Error { constructor(message: string) { super(message); }}
export async function searchArtist(s: string): Promise<any> { try { let req = await fetch(`${BASE_URL}search.php?s=${encodeURI(s)}`); let response = await req.text(); if (response != null && typeof response !== "undefined" && response != "") { let data = JSON.parse(response); if ( data.artists != null && typeof data.artists !== "undefined" && data.artists != "" ) { return data.artists[0]; } else { throw "no results found"; } } else { throw "no results found"; } } catch(err) { throw new AudioDBException(err); }}
export async function discography(s: string): Promise<Array<any>> { try { let req = await fetch(`${BASE_URL}discography.php?s=${encodeURI(s)}`); let response = await req.text(); if (response != null && typeof response !== "undefined" && response != "") { let data = JSON.parse(response); if ( data.album != null && typeof data.album !== "undefined" && data.album != "" ) { return data.album; } else { throw "no results found"; } } else { throw "no results found"; } } catch(err) { throw new AudioDBException(err); }}
export async function searchArtistById(i: number): Promise<any> { try { let req = await fetch(`${BASE_URL}artist.php?i=${i}`); let response = await req.text(); if (response != null && typeof response !== "undefined" && response != "") { let data = JSON.parse(response); if ( data.artists != null && typeof data.artists !== "undefined" && data.artists != "" ) { return data.artists[0]; } else { throw "no results found"; } } else { throw "no results found"; } } catch(err) { throw new AudioDBException(err); }}
export async function searchAlbumById(i: number): Promise<any> { try { let req = await fetch(`${BASE_URL}album.php?m=${i}`); let response = await req.text(); if (response != null && typeof response !== "undefined" && response != "") { let data = JSON.parse(response); if ( data.album != null && typeof data.album !== "undefined" && data.album != "" ) { return data.album[0]; } else { throw "no results found"; } } else { throw "no results found"; } } catch(err) { throw new AudioDBException(err); }}
export async function searchAlbumsByArtistId(i: number): Promise<Array<any>> { try { let req = await fetch(`${BASE_URL}album.php?i=${i}`); let response = await req.text(); if (response != null && typeof response !== "undefined" && response != "") { let data = JSON.parse(response); if ( data.album != null && typeof data.album !== "undefined" && data.album != "" ) { return data.album; } else { throw "no results found"; } } else { throw "no results found"; } } catch(err) { throw new AudioDBException(err); }}
export async function searchTracksByAlbumId(i: number): Promise<Array<any>> { try { let req = await fetch(`${BASE_URL}track.php?m=${i}`); let response = await req.text(); if (response != null && typeof response !== "undefined" && response != "") { let data = JSON.parse(response); if ( data.track != null && typeof data.track !== "undefined" && data.track != "" ) { return data.track; } else { throw "no results found"; } } else { throw "no results found"; } } catch(err) { throw new AudioDBException(err); }}
export async function searchTrackById(i: number): Promise<any> { try { let req = await fetch(`${BASE_URL}track.php?h=${i}`); let response = await req.text(); if (response != null && typeof response !== "undefined" && response != "") { let data = JSON.parse(response); if ( data.track != null && typeof data.track !== "undefined" && data.track != "" ) { return data.track[0]; } else { throw "no results found"; } } else { throw "no results found"; } } catch(err) { throw new AudioDBException(err); }}
export async function searchMusicVideosByArtistId(i: number): Promise<Array<any>> { try { let req = await fetch(`${BASE_URL}mvid.php?i=${i}`); let response = await req.text(); if (response != null && typeof response !== "undefined" && response != "") { let data = JSON.parse(response); if ( data.mvids != null && typeof data.mvids !== "undefined" && data.mvids != "" ) { return data.mvids; } else { throw "no results found"; } } else { throw "no results found"; } } catch(err) { throw new AudioDBException(err); }}