This commit is contained in:
Aryan Layes 2020-05-13 00:58:03 +02:00
parent 5720433ae8
commit a13065e1c8
2 changed files with 49 additions and 1 deletions

18
app.py
View file

@ -4,8 +4,11 @@ from deemix.utils.misc import getTypeFromLink, getIDFromLink
from deemix.app.settings import initSettings, getSettings, getDefaultSettings, saveSettings from deemix.app.settings import initSettings, getSettings, getDefaultSettings, saveSettings
from deemix.app.spotify import SpotifyHelper from deemix.app.spotify import SpotifyHelper
from spotifyadvanced import SpotifyAdvanced
settings = {} settings = {}
spotifyHelper = None spotifyHelper = None
spotifyAdvanced = None
chartsList = [] chartsList = []
@ -16,7 +19,22 @@ def initialize():
settings = initSettings() settings = initSettings()
defaultSettings = getDefaultSettings() defaultSettings = getDefaultSettings()
spotifyHelper = SpotifyHelper() spotifyHelper = SpotifyHelper()
global spotifyAdvanced
spotifyAdvanced = SpotifyAdvanced()
def initSpotifyAdvanced():
user = spotifyAdvanced.getUsername()
if user == "" or not spotifyAdvanced.spotifyAdvancedEnabled:
return []
result = spotifyAdvanced.get_user_playlists(user)
#print(result)
return result
def getTracklistFromSpotifyPlaylists(playlistIds):
return spotifyAdvanced.getTracklistFromSpotifyPlaylists(playlistIds)
def mergeSpotifyPlaylists(playlistIds):
return spotifyAdvanced.mergeSpotifyPlaylists(playlistIds)
def shutdown(interface=None): def shutdown(interface=None):
getQueue() getQueue()

View file

@ -1,4 +1,5 @@
#!/usr/env/bin python3 #!/usr/env/bin python3
import json
import logging import logging
import sys import sys
from os import path from os import path
@ -11,6 +12,8 @@ from deemix.api.deezer import Deezer
from deemix.app.MessageInterface import MessageInterface from deemix.app.MessageInterface import MessageInterface
from deemix.utils import localpaths from deemix.utils import localpaths
import spotifyadvanced
# Workaround for MIME type error in certain Windows installs # Workaround for MIME type error in certain Windows installs
# https://github.com/pallets/flask/issues/1045#issuecomment-42202749 # https://github.com/pallets/flask/issues/1045#issuecomment-42202749
import mimetypes import mimetypes
@ -97,6 +100,7 @@ def on_connect():
{'queue': queue, 'queueComplete': queueComplete, 'queueList': queueList, 'currentItem': currentItem}) {'queue': queue, 'queueComplete': queueComplete, 'queueList': queueList, 'currentItem': currentItem})
emit('init_home', session['dz'].get_charts()) emit('init_home', session['dz'].get_charts())
emit('init_charts', app.get_charts(session['dz'])) emit('init_charts', app.get_charts(session['dz']))
emit('init_spotify', app.initSpotifyAdvanced())
@socketio.on('login') @socketio.on('login')
@ -115,7 +119,6 @@ def login(arl, force=False):
emit('logged_in', {'status': result, 'arl': arl, 'user': session['dz'].user}) emit('logged_in', {'status': result, 'arl': arl, 'user': session['dz'].user})
emit('init_favorites', app.getUserFavorites(session['dz'])) emit('init_favorites', app.getUserFavorites(session['dz']))
@socketio.on('logout') @socketio.on('logout')
def logout(): def logout():
status = 0 status = 0
@ -211,6 +214,33 @@ def analyzeLink(link):
(type, data) = app.analyzeLink(session['dz'], link) (type, data) = app.analyzeLink(session['dz'], link)
emit('analyze_'+type, data) emit('analyze_'+type, data)
@socketio.on('getTracklistFromSpotifyPlaylists')
def getTracklistFromSpotifyPlaylists(data):
playlistAPI = app.getTracklistFromSpotifyPlaylists(data['playlists'])
for i in range(len(playlistAPI['tracks'])):
playlistAPI['tracks'][i] = playlistAPI['tracks'][i]['track']
playlistAPI['tracks'][i]['selected'] = False
filename = "debug_getTracklistFromSpotifyPlaylists_playlistAPI_server"
with open(filename+".json", 'w') as outfile:
json.dump(playlistAPI, outfile, indent=4)
emit('getTracklistFromSpotifyPlaylists_done', playlistAPI)
@socketio.on('mergeSpotifyPlaylists')
def mergeSpotifyPlaylists(data):
result = app.mergeSpotifyPlaylists(data['playlists'])
# returns ERROR 1 or
# returns uri of new created playlist
filename = "debug_mergeSpotifyPlaylists_result"
with open(filename+".json", 'w') as outfile:
json.dump(result, outfile, indent=4)
if result != "ERROR 1":
emit('mergeSpotifyPlaylists_done', result) # <--- sollte die neue playlists anzeigen in result steht die playlist URI
emit('init_spotify', app.initSpotify()) # analog zu updateUserSpotifyPlaylists
#emit('updated_userSpotifyPlaylists', app.updateUserSpotifyPlaylists(spotifyUser))
else:
emit('mergeSpotifyPlaylists_error', result)
@socketio.on('getChartTracks') @socketio.on('getChartTracks')
def getChartTracks(id): def getChartTracks(id):
emit('setChartTracks', session['dz'].get_playlist_tracks(id)['data']) emit('setChartTracks', session['dz'].get_playlist_tracks(id)['data'])