mirror of
https://gitlab.com/RemixDev/deezer-js.git
synced 2025-01-29 17:48:29 +00:00
fixed get_user_artists and get_user_tracks in gw
This commit is contained in:
parent
0f0d0f91d8
commit
ad5e45f72e
25
deezer/gw.js
25
deezer/gw.js
|
@ -86,6 +86,12 @@ class GW{
|
|||
return this.api_call('deezer.pageProfile', {user_id, tab, nb: limit})
|
||||
}
|
||||
|
||||
get_user_favorite_ids(checksum = null, options={}){
|
||||
const limit = options.limit || 10000
|
||||
const start = options.start || 0
|
||||
return this.api_call('song.getFavoriteIds', {nb: limit, start, checksum})
|
||||
}
|
||||
|
||||
get_child_accounts(){
|
||||
return this.api_call('deezer.getChildAccounts')
|
||||
}
|
||||
|
@ -102,7 +108,7 @@ class GW{
|
|||
return this.api_call('song.getLyrics', {sng_id})
|
||||
}
|
||||
|
||||
async get_tracks_gw(sng_ids){
|
||||
async get_tracks(sng_ids){
|
||||
let tracks_array = []
|
||||
let body = await this.api_call('song.getListData', {sng_ids})
|
||||
let errors = 0
|
||||
|
@ -419,7 +425,7 @@ class GW{
|
|||
|
||||
async get_user_artists(user_id, options={}){
|
||||
const limit = options.limit || 25
|
||||
let data = this.get_user_profile_page(user_id, 'artists', {limit})
|
||||
let data = await this.get_user_profile_page(user_id, 'artists', {limit})
|
||||
data = data.TAB.artists.data
|
||||
let result = []
|
||||
data.forEach(artist => {
|
||||
|
@ -429,6 +435,8 @@ class GW{
|
|||
}
|
||||
|
||||
async get_user_tracks(user_id, options={}){
|
||||
let user_data = await this.get_user_data()
|
||||
if (user_data.USER.USER_ID == user_id) return this.get_my_favorite_tracks(options)
|
||||
const limit = options.limit || 25
|
||||
let data = this.get_user_profile_page(user_id, 'loved', {limit})
|
||||
data = data.TAB.loved.data
|
||||
|
@ -439,6 +447,19 @@ class GW{
|
|||
return result
|
||||
}
|
||||
|
||||
async get_my_favorite_tracks(options={}){
|
||||
const limit = options.limit || 25
|
||||
const ids_raw = await this.get_user_favorite_ids(null, {limit})
|
||||
const ids = ids_raw.data.map(x => x.SNG_ID)
|
||||
let data = await this.get_tracks(ids)
|
||||
let result = []
|
||||
data.forEach((track, i) => {
|
||||
track = {...track, ...ids_raw.data[i]}
|
||||
result.push(map_user_track(track))
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -2,6 +2,15 @@ const RELEASE_TYPE = ["single", "album", "compile", "ep", "bundle"]
|
|||
|
||||
// maps gw-light api user/tracks to standard api
|
||||
function map_user_track(track){
|
||||
let art_picture = track.ART_PICTURE
|
||||
if (!art_picture){
|
||||
for (let artist of track.ARTISTS){
|
||||
if (artist.ART_ID == track.ART_ID){
|
||||
art_picture = artist.ART_PICTURE
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
id: track.SNG_ID,
|
||||
title: track.SNG_TITLE,
|
||||
|
@ -11,7 +20,7 @@ function map_user_track(track){
|
|||
explicit_lyrics: parseInt(track.EXPLICIT_LYRICS) > 0,
|
||||
explicit_content_lyrics: track.EXPLICIT_TRACK_CONTENT.EXPLICIT_COVER_STATUS,
|
||||
explicit_content_cover: track.EXPLICIT_TRACK_CONTENT.EXPLICIT_LYRICS_STATUS,
|
||||
time_add: track.DATE_ADD,
|
||||
time_add: track.DATE_ADD || track.DATE_FAVORITE,
|
||||
album: {
|
||||
id: track.ALB_ID,
|
||||
title: track.ALB_TITLE,
|
||||
|
@ -27,10 +36,10 @@ function map_user_track(track){
|
|||
id: track.ART_ID,
|
||||
name: track.ART_NAME,
|
||||
picture: 'https://api.deezer.com/artist/'+track.ART_ID+'/image',
|
||||
picture_small: 'https://e-cdns-images.dzcdn.net/images/artist/'+track.ART_PICTURE+'/56x56-000000-80-0-0.jpg',
|
||||
picture_medium: 'https://e-cdns-images.dzcdn.net/images/artist/'+track.ART_PICTURE+'/250x250-000000-80-0-0.jpg',
|
||||
picture_big: 'https://e-cdns-images.dzcdn.net/images/artist/'+track.ART_PICTURE+'/500x500-000000-80-0-0.jpg',
|
||||
picture_xl: 'https://e-cdns-images.dzcdn.net/images/artist/'+track.ART_PICTURE+'/1000x1000-000000-80-0-0.jpg',
|
||||
picture_small: 'https://e-cdns-images.dzcdn.net/images/artist/'+art_picture+'/56x56-000000-80-0-0.jpg',
|
||||
picture_medium: 'https://e-cdns-images.dzcdn.net/images/artist/'+art_picture+'/250x250-000000-80-0-0.jpg',
|
||||
picture_big: 'https://e-cdns-images.dzcdn.net/images/artist/'+art_picture+'/500x500-000000-80-0-0.jpg',
|
||||
picture_xl: 'https://e-cdns-images.dzcdn.net/images/artist/'+art_picture+'/1000x1000-000000-80-0-0.jpg',
|
||||
tracklist: 'https://api.deezer.com/artist/'+track.ART_ID+'/top?limit=50',
|
||||
type: 'artist'
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue