Add support for fetching information from Deezer

This commit is contained in:
absidue
2021-10-27 22:09:53 +02:00
parent 2d91c2437b
commit 2aea9f0deb
7 changed files with 938 additions and 6 deletions

169
docs/Deezer/README.md Normal file
View File

@@ -0,0 +1,169 @@
# Deezer
## Main
### deezer(url : `string`)
_This returns data from a track | playlist | album url. Accepts share links as well, which it resolves first._
```js
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`
```js
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?** `number` The maximum number of results to return. Maximum `100`, defaults to `10`.
- **fuzzy?** `boolean` Whether the search should be fuzzy or only return exact matches. Defaults to `true`.
```js
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.
```js
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._
```js
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._
```js
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._
```js
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._
```js
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._

View File

@@ -12,7 +12,7 @@ For source specific commands :-
_This checks all type of urls that are supported by play-dl._
**Returns :** `so_playlist` | `so_track` | `sp_track` | `sp_album` | `sp_playlist` | `yt_video` | `yt_playlist` | `search` | `false`
**Returns :** `so_playlist` | `so_track` | `sp_track` | `sp_album` | `sp_playlist` | `dz_track` | `dz_playlist` | `dz_album` | `dz_share` | `yt_video` | `yt_playlist` | `search` | `false`
`so` = **SoundCloud**
@@ -20,6 +20,8 @@ _This checks all type of urls that are supported by play-dl._
`yt` = **YouTube**
`dz` = **Deezer**
```js
let check = await validate(url)
@@ -31,6 +33,8 @@ if(check === 'sp_track') // Spotify Track
if(check === 'so_track') // SoundCloud Track
if(check === 'dz_track') // Deezer Track
if(check === "search") // Given term is not a url. Search this term somewhere.
```
@@ -82,6 +86,8 @@ setToken({
soundcloud: `tracks` | `playlists` | `albums` ;
deezer: `track` | `playlist` | `album` ;
}
#### search(query : `string`, options? : [`SearchOptions`](https://github.com/play-dl/play-dl/tree/main/docs#searchoptions-))
@@ -98,13 +104,15 @@ let data = await search('Rick Roll', { limit : 1, source : { youtube : "video" }
let data = await search('Rick Roll', { limit: 1, source : { spotify : "track" } }) // Searches for spotify track.
let data = await search('Rick Roll', { limit: 1, source : { soundcloud : "tracks" } }) // Searches for soundcloud track.
let data = await search('Rick Roll', { limit: 1, source : { deezer : "track" } }) // Searches for a Deezer track.
```
### Stream
**Attaching events to player is important for stream to work.**
#### attachListeners(player : `AudioPlayer`, resource : `YouTubeStream | SoundCloudStream`)
#### attachListeners(player : `AudioPlayer`, resource : `YouTubeStream | SoundCloudStream`)
_This is used for attaching pause and playing events to audioPlayer._