4.6 KiB
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 | false
let check = dz_validate(url)
if(!check) // Invalid Deezer URL
if(check === 'track') // Deezer Track 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
dz_advanced_track_search(options: DeezerAdvancedSearchOptions)
Searches Deezer for tracks using the specified metadata.
Returns : DeezerTrack[] an array of tracks
DeezerAdvancedSearchOptions
- limit?
numberThe maximum number of results to return, maximum100, defaults to10. - artist?
stringThe name of the artist - album?
stringThe title of the album - title?
stringThe title of the track - label?
stringThe label that released the track - minDurationInSec?
numberThe minimum duration in seconds - maxDurationInSec?
numberThe maximum duration in seconds - minBpm?
numberThe minimum BPM - maxBpm?
numberThe minimum BPM
const results = await dz_advanced_track_search({
limit: 1,
artist: 'Rick Astley',
title: 'Never Gonna Give You Up'
}); // Returns an array with one track
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.