Added 'get_favorites_data' and 'get_settings_data'

for future use in the webui
This commit is contained in:
RemixDev 2020-09-21 19:35:08 +02:00
parent d13e3ad27d
commit d14f708b3d
2 changed files with 24 additions and 14 deletions

26
app.py
View file

@ -74,18 +74,19 @@ class deemix:
return self.set.settings['downloadLocation']
def getUserFavorites(self, dz):
user_id = dz.user['id']
result = {}
try:
result['playlists'] = dz.get_user_playlists(user_id)['data']
result['albums'] = dz.get_user_albums(user_id)['data']
result['artists'] = dz.get_user_artists(user_id)['data']
result['tracks'] = dz.get_user_tracks(user_id)['data']
except:
result['playlists'] = dz.get_user_playlists_gw(user_id)
result['albums'] = dz.get_user_albums_gw(user_id)
result['artists'] = dz.get_user_artists_gw(user_id)
result['tracks'] = dz.get_user_tracks_gw(user_id)
if dz.logged_in:
user_id = dz.user['id']
try:
result['playlists'] = dz.get_user_playlists(user_id)['data']
result['albums'] = dz.get_user_albums(user_id)['data']
result['artists'] = dz.get_user_artists(user_id)['data']
result['tracks'] = dz.get_user_tracks(user_id)['data']
except:
result['playlists'] = dz.get_user_playlists_gw(user_id)
result['albums'] = dz.get_user_albums_gw(user_id)
result['artists'] = dz.get_user_artists_gw(user_id)
result['tracks'] = dz.get_user_tracks_gw(user_id)
return result
def updateUserSpotifyPlaylists(self, user):
@ -169,6 +170,9 @@ class deemix:
return (type, data)
# Settings functions
def getAllSettings(self):
return (self.set.settings, self.sp.getCredentials(), self.set.defaultSettings)
def getDefaultSettings(self):
return self.set.defaultSettings

View file

@ -160,10 +160,8 @@ if serverwide_arl:
@socketio.on('connect')
def on_connect():
session['dz'] = Deezer()
settings = app.getSettings()
(settings, spotifyCredentials, defaultSettings) = app.getAllSettings()
session['dz'].set_accept_language(settings.get('tagsLanguage'))
spotifyCredentials = app.getSpotifyCredentials()
defaultSettings = app.getDefaultSettings()
emit('init_settings', (settings, spotifyCredentials, defaultSettings))
emit('init_update',
{'currentCommit': currentVersion,
@ -198,6 +196,14 @@ def get_home_data():
def get_charts_data():
emit('init_charts', app.get_charts(session['dz']))
@socketio.on('get_favorites_data')
def get_favorites_data():
emit('init_favorites', app.getUserFavorites(session['dz']))
@socketio.on('get_settings_data')
def get_settings_data():
emit('init_settings', app.getAllSettings())
@socketio.on('login')
def login(arl, force=False, child=0):
global firstConnection, is_deezer_available