Deezer
Main
deezer(url : string)
This returns data from a track | playlist | album url. Accepts share links as well, which it resolves first.
let data = await deezer(url); //Gets the data
console.log(data.type); // Console logs the type of data that you got.
Validate
dz_validate(url : string)
This checks that given url is Deezer url or not.
Returns : track | album | playlist | search | share | false
let check = dz_validate(url)
if(!check) // Invalid Deezer URL
if(check === 'track') // Deezer Track URL
if(check === 'share') // Deezer Share URL
if(check === "search") // Given term is a search query. Search it somewhere.
Search
dz_search(query: string, options: DeezerSearchOptions)
Searches for tracks, playlists and albums.
Returns : Deezer[] an array of tracks, playlists or albums
DeezerSearchOptions
- type?
'track'|'playlist'|'album'The type to search for. Defaults to'track'. - limit?
numberThe maximum number of results to return. Maximum100, defaults to10. - fuzzy?
booleanWhether the search should be fuzzy or only return exact matches. Defaults totrue.
const results = await dz_search(query, {
limit: 1,
type: 'track',
fuzzy: false
}); // Returns an array with one track, using exact matching
Resolving a share URL
dz_resolve_share_url(url: string)
Resolves a Deezer share link (deezer.page.link) returning the deezer.com URL.
Returns : string the resolved URL. Warning the returned URL might not be a track, album or playlist URL.
const resolvedURL = await dz_resolve_share_url(url);
Classes [ Returned by deezer(url) function ]
DeezerTrack
This is the class for a Deezer track.
type property
This will always return as "track" for this class.
partial property
Will return true for tracks in search results and false for tracks fetched directly or if the fetch function has been called. This being true means that the optional properties are undefined.
toJSON() function
Converts the object to JSON
fetch() function
Fetches the missing data for a partial track.
const track = await deezer(track_url);
await track.fetch() // Fetches the missing data
DeezerPlaylist
This is the class for a Deezer playlist.
fetch() function
This will fetch up to 1000 tracks in a playlist as well as the missing data for a partial playlist.
let data = await deezer(playlist_url)
await data.fetch() // Fetches tracks more than 100 tracks in playlist
tracksCount property
This will return the total number of tracks in a playlist.
const data = await deezer(playlist_url)
console.log(data.tracksCount) // Total number of tracks in the playlist.
type property
This will always return as "playlist" for this class.
partial property
Will return true for playlists in search results and false for playlists fetched directly or if the fetch function has been called. This being true means that the optional properties are undefined and tracks may be empty or partially filled.
tracks property
The array of tracks in this album, this is always empty (length of 0) for partial playlists.
const data = await deezer(playlist_url);
if (data.tracks.length !== data.tracksCount) {
await data.fetch();
}
console.log(data.tracks); // returns all tracks in the playlist
toJSON() function
Converts the object to JSON
DeezerAlbum
This is the class for a Deezer album.
type property
This will always return as "track" for this class.
tracks property
The array of tracks in this album, this is always empty (length of 0) for partial albums.
partial property
Will return true for albums in search results and false for albums fetched directly or if the fetch function has been called. This being true means that the optional properties are undefined.
toJSON() function
Converts the object to JSON
fetch() function
Fetches the missing data for a partial album.