mirror of
https://gitlab.com/RemixDev/deezer-js.git
synced 2025-01-29 17:48:29 +00:00
Added lint
This commit is contained in:
parent
23ca85796e
commit
1de6fe00cd
13
.eslintrc.json
Normal file
13
.eslintrc.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"env": {
|
||||
"commonjs": true,
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 12
|
||||
},
|
||||
"rules": {
|
||||
}
|
||||
}
|
|
@ -306,10 +306,6 @@ class API{
|
|||
return this.api_call(`user/${user_id}/artists`, {index, limit})
|
||||
}
|
||||
|
||||
get_user_artists(user_id, index=0, limit=25){
|
||||
return this.api_call(`user/${user_id}/artists`, {index, limit})
|
||||
}
|
||||
|
||||
get_user_flow(user_id, index=0, limit=25){
|
||||
return this.api_call(`user/${user_id}/flow`, {index, limit})
|
||||
}
|
||||
|
@ -337,8 +333,8 @@ class API{
|
|||
// Extra calls
|
||||
|
||||
async get_countries_charts(){
|
||||
let temp = await this.get_user_playlists('637006841', limit=-1)['data']
|
||||
result = temp.sort((a, b) => a.title.localeCompare(b.title)) // Sort all playlists
|
||||
let temp = await this.get_user_playlists('637006841', 0, -1)['data']
|
||||
let result = temp.sort((a, b) => a.title.localeCompare(b.title)) // Sort all playlists
|
||||
if (!result[0].title.startsWith('Top')) result.shift() // Remove loved tracks playlist
|
||||
return result
|
||||
}
|
||||
|
@ -349,19 +345,19 @@ class API{
|
|||
track = track.replace("–", "-").replace("’", "'")
|
||||
album = album.replace("–", "-").replace("’", "'")
|
||||
|
||||
let resp = await this.advanced_search(artist=artist, track=track, album=album, limit=1)
|
||||
if (resp.data.length > 0) return resp.data[0].id
|
||||
let resp = await this.advanced_search(artist, track, album)
|
||||
if (resp.data.length) return resp.data[0].id
|
||||
|
||||
resp = await this.advanced_search(artist=artist, track=track, limit=1)
|
||||
if (resp.data.length > 0) return resp.data[0].id
|
||||
resp = await this.advanced_search(artist, track)
|
||||
if (resp.data.length) return resp.data[0].id
|
||||
|
||||
// Try removing version
|
||||
if ( track.indexOf("(") != -1 && track.indexOf(")") != -1 && track.indexOf("(") < track.indexOf(")") ){
|
||||
resp = await this.advanced_search(artist=artist, track=track.split("(")[0], limit=1)
|
||||
if (resp.data.length > 0) return resp.data[0].id
|
||||
resp = await this.advanced_search(artist, track.split("(")[0],)
|
||||
if (resp.data.length) return resp.data[0].id
|
||||
} else if ( track.indexOf(" - ") != -1) {
|
||||
resp = await this.advanced_search(artist=artist, track=track.split(" - ")[0], limit=1)
|
||||
if (resp.data.length > 0) return resp.data[0].id
|
||||
resp = await this.advanced_search(artist, track.split(" - ")[0])
|
||||
if (resp.data.length) return resp.data[0].id
|
||||
}
|
||||
|
||||
return "0"
|
||||
|
|
57
deezer/gw.js
57
deezer/gw.js
|
@ -40,8 +40,8 @@ class GW{
|
|||
}
|
||||
|
||||
async api_call(method, args, params){
|
||||
if (typeof args == "unasyncined") args = {}
|
||||
if (typeof params == "unasyncined") params = {}
|
||||
if (typeof args === undefined) args = {}
|
||||
if (typeof params === undefined) params = {}
|
||||
let p = {
|
||||
api_version: "1.0",
|
||||
api_token: method == 'deezer.getUserData' ? 'null' : await this._get_token(),
|
||||
|
@ -119,7 +119,7 @@ class GW{
|
|||
return this.api_call('deezer.pageAlbum', {
|
||||
alb_id,
|
||||
lang: 'en',
|
||||
header: True,
|
||||
header: true,
|
||||
tab: 0
|
||||
})
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ class GW{
|
|||
return this.api_call('deezer.pageArtist', {
|
||||
art_id,
|
||||
lang: 'en',
|
||||
header: True,
|
||||
header: true,
|
||||
tab: 0
|
||||
})
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ class GW{
|
|||
let body = await this.api_call('artist.getTopTrack', {art_id, nb: limit})
|
||||
body.data.forEach(track => {
|
||||
track.POSITION = body.data.indexOf(track)
|
||||
tracks_array.push(_track)
|
||||
tracks_array.push(track)
|
||||
})
|
||||
return tracks_array
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ class GW{
|
|||
return this.api_call('deezer.pagePlaylist', {
|
||||
playlist_id,
|
||||
lang: 'en',
|
||||
header: True,
|
||||
header: true,
|
||||
tab: 0
|
||||
})
|
||||
}
|
||||
|
@ -186,13 +186,13 @@ class GW{
|
|||
let body = await this.api_call('playlist.getSongs', {playlist_id, nb: -1})
|
||||
body.data.forEach(track => {
|
||||
track.POSITION = body.data.indexOf(track)
|
||||
tracks_array.push(_track)
|
||||
tracks_array.push(track)
|
||||
})
|
||||
return tracks_array
|
||||
}
|
||||
|
||||
create_playlist(title, status=PlaylistStatus.PUBLIC, description, songs=[]){
|
||||
newSongs = []
|
||||
let newSongs = []
|
||||
songs.forEach(song => {
|
||||
newSongs.push([song, 0])
|
||||
});
|
||||
|
@ -205,7 +205,7 @@ class GW{
|
|||
}
|
||||
|
||||
edit_playlist(playlist_id, title, status, description, songs=[]){
|
||||
newSongs = []
|
||||
let newSongs = []
|
||||
songs.forEach(song => {
|
||||
newSongs.push([song, 0])
|
||||
});
|
||||
|
@ -219,7 +219,7 @@ class GW{
|
|||
}
|
||||
|
||||
add_songs_to_playlist(playlist_id, songs, offset=-1){
|
||||
newSongs = []
|
||||
let newSongs = []
|
||||
songs.forEach(song => {
|
||||
newSongs.push([song, 0])
|
||||
});
|
||||
|
@ -235,7 +235,7 @@ class GW{
|
|||
}
|
||||
|
||||
remove_songs_from_playlist(playlist_id, songs){
|
||||
newSongs = []
|
||||
let newSongs = []
|
||||
songs.forEach(song => {
|
||||
newSongs.push([song, 0])
|
||||
});
|
||||
|
@ -302,7 +302,7 @@ class GW{
|
|||
LANG: 'en'
|
||||
})
|
||||
}
|
||||
return this.api_call('page.get', params=params)
|
||||
return this.api_call('page.get', {}, params)
|
||||
}
|
||||
|
||||
search(query, index=0, limit=10, suggest=true, artist_suggest=true, top_tracks=true){
|
||||
|
@ -335,8 +335,9 @@ class GW{
|
|||
let ids = []
|
||||
|
||||
// Get all releases
|
||||
let response
|
||||
do {
|
||||
response = await this.get_artist_discography(art_id, index=index, limit=limit)
|
||||
response = await this.get_artist_discography(art_id, index, limit)
|
||||
releases.concat(response.data)
|
||||
index += limit
|
||||
} while (index < response.total)
|
||||
|
@ -344,21 +345,21 @@ class GW{
|
|||
releases.forEach(release => {
|
||||
if (ids.indexOf(release.ALB_ID) == -1){
|
||||
ids.push(release.ALB_ID)
|
||||
obj = map_artist_album(release)
|
||||
let obj = map_artist_album(release)
|
||||
if ((release.ART_ID == art_id || release.ART_ID != art_id && release.ROLE_ID == 0) && release.ARTISTS_ALBUMS_IS_OFFICIAL){
|
||||
// Handle all base record types
|
||||
if (!result[obj.record_type]) result[obj.record_type] = []
|
||||
result[obj.record_type].push(obj)
|
||||
result.all.push(obj)
|
||||
}
|
||||
} else {
|
||||
if (release.ROLE_ID == 5) { // Handle albums where the artist is featured
|
||||
if (!result.featured) result.featured = []
|
||||
result.featured.push(obj)
|
||||
} else if (release.ROLE_ID == 0) { // Handle "more" albums
|
||||
if (!result.more) result.more = []
|
||||
result.more.push(obj)
|
||||
result.all.push(obj)
|
||||
} else {
|
||||
if (release.ROLE_ID == 5) { // Handle albums where the artist is featured
|
||||
if (!result.featured) result.featured = []
|
||||
result.featured.push(obj)
|
||||
} else if (release.ROLE_ID == 0) { // Handle "more" albums
|
||||
if (!result.more) result.more = []
|
||||
result.more.push(obj)
|
||||
result.all.push(obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -369,7 +370,7 @@ class GW{
|
|||
let body
|
||||
if (parseInt(sng_id) > 0){
|
||||
try{ body = await this.get_track_page(sng_id) }
|
||||
catch (e) {}
|
||||
catch (e) { /*nothing*/ }
|
||||
}
|
||||
|
||||
if (body){
|
||||
|
@ -382,7 +383,7 @@ class GW{
|
|||
}
|
||||
|
||||
async get_user_playlists(user_id, limit=25){
|
||||
let user_profile_page = await this.get_user_profile_page(user_id, 'playlists', limit=limit)
|
||||
let user_profile_page = await this.get_user_profile_page(user_id, 'playlists', limit)
|
||||
let blog_name = user_profile_page.DATA.USER.BLOG_NAME || "Unknown"
|
||||
let data = user_profile_page.TAB.playlists.data
|
||||
let result = []
|
||||
|
@ -393,7 +394,7 @@ class GW{
|
|||
}
|
||||
|
||||
async get_user_albums(user_id, limit=25){
|
||||
let data = await this.get_user_profile_page(user_id, 'albums', limit=limit).TAB.albums.data
|
||||
let data = await this.get_user_profile_page(user_id, 'albums', limit).TAB.albums.data
|
||||
let result = []
|
||||
data.forEach(album => {
|
||||
result.push(map_user_album(album))
|
||||
|
@ -402,7 +403,7 @@ class GW{
|
|||
}
|
||||
|
||||
async get_user_artists(user_id, limit=25){
|
||||
let data = this.get_user_profile_page(user_id, 'artists', limit=limit).TAB.artists.data
|
||||
let data = this.get_user_profile_page(user_id, 'artists', limit).TAB.artists.data
|
||||
let result = []
|
||||
data.forEach(artist => {
|
||||
result.push(map_user_artist(artist))
|
||||
|
@ -411,7 +412,7 @@ class GW{
|
|||
}
|
||||
|
||||
async get_user_tracks(user_id, limit=25){
|
||||
let data = this.get_user_profile_page(user_id, 'loved', limit=limit).TAB.loved.data
|
||||
let data = this.get_user_profile_page(user_id, 'loved', limit).TAB.loved.data
|
||||
let result = []
|
||||
data.forEach(track => {
|
||||
result.push(map_user_track(track))
|
||||
|
|
|
@ -202,6 +202,7 @@ function map_playlist(playlist){
|
|||
|
||||
// Cleanup terms that can hurt search results
|
||||
function clean_search_query(term){
|
||||
/* eslint-disable no-useless-escape */
|
||||
term = term.replaceAll(/ feat[\.]? /g, " ")
|
||||
term = term.replaceAll(/ ft[\.]? /g, " ")
|
||||
term = term.replaceAll(/\(feat[\.]? /g, " ")
|
||||
|
|
2291
package-lock.json
generated
2291
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "deezer-js",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"description": "A wrapper for all Deezer's APIs",
|
||||
"main": "deezer/index.js",
|
||||
"scripts": {
|
||||
|
@ -15,5 +15,8 @@
|
|||
"dependencies": {
|
||||
"got": "^11.8.2",
|
||||
"tough-cookie": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.23.0"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue