diff --git a/app.py b/app.py index 6d0db0a..a7c4155 100644 --- a/app.py +++ b/app.py @@ -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 diff --git a/server.py b/server.py index 9061db4..8dda01b 100644 --- a/server.py +++ b/server.py @@ -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