Updated app to work with deemix 2.0.1

This commit is contained in:
RemixDev 2020-11-19 22:09:26 +01:00
parent 4c4d22a6c5
commit 5699fb2a41
No known key found for this signature in database
GPG key ID: B33962B465BDB51C
4 changed files with 112 additions and 63 deletions

119
app.py
View file

@ -2,7 +2,8 @@
import eventlet import eventlet
requests = eventlet.import_patched('requests') requests = eventlet.import_patched('requests')
from deemix.api.deezer import Deezer from deezer import Deezer
from deezer.utils import clean_search_query
from deemix.app.settings import Settings, DEFAULT_SETTINGS from deemix.app.settings import Settings, DEFAULT_SETTINGS
from deemix.app.queuemanager import QueueManager from deemix.app.queuemanager import QueueManager
from deemix.app.spotifyhelper import SpotifyHelper, emptyPlaylist as emptySpotifyPlaylist from deemix.app.spotifyhelper import SpotifyHelper, emptyPlaylist as emptySpotifyPlaylist
@ -144,7 +145,7 @@ class deemix:
def get_charts(self, dz): def get_charts(self, dz):
if len(self.chartsList) == 0: if len(self.chartsList) == 0:
temp = dz.get_charts_countries() temp = dz.api.get_countries_charts()
countries = [] countries = []
for i in range(len(temp)): for i in range(len(temp)):
countries.append({ countries.append({
@ -159,7 +160,7 @@ class deemix:
def get_home(self, dz): def get_home(self, dz):
if not self.homeCache: if not self.homeCache:
self.homeCache = dz.get_charts() self.homeCache = dz.api.get_chart()
return self.homeCache return self.homeCache
def getDownloadFolder(self): def getDownloadFolder(self):
@ -167,8 +168,8 @@ class deemix:
def getTracklist(self, dz, data): def getTracklist(self, dz, data):
if data['type'] == 'artist': if data['type'] == 'artist':
artistAPI = dz.get_artist(data['id']) artistAPI = dz.api.get_artist(data['id'])
artistAPI['releases'] = dz.get_artist_discography_gw(data['id'], 100) artistAPI['releases'] = dz.gw.get_artist_discography_tabs(data['id'], 100)
return artistAPI return artistAPI
elif data['type'] == 'spotifyplaylist': elif data['type'] == 'spotifyplaylist':
playlistAPI = self.getSpotifyPlaylistTracklist(data['id']) playlistAPI = self.getSpotifyPlaylistTracklist(data['id'])
@ -177,8 +178,8 @@ class deemix:
playlistAPI['tracks'][i]['selected'] = False playlistAPI['tracks'][i]['selected'] = False
return playlistAPI return playlistAPI
else: else:
releaseAPI = getattr(dz, 'get_' + data['type'])(data['id']) releaseAPI = getattr(dz.api, 'get_' + data['type'])(data['id'])
releaseTracksAPI = getattr(dz, 'get_' + data['type'] + '_tracks')(data['id'])['data'] releaseTracksAPI = getattr(dz.api, 'get_' + data['type'] + '_tracks')(data['id'])['data']
tracks = [] tracks = []
showdiscs = False showdiscs = False
if data['type'] == 'album' and len(releaseTracksAPI) and releaseTracksAPI[-1]['disk_number'] != 1: if data['type'] == 'album' and len(releaseTracksAPI) and releaseTracksAPI[-1]['disk_number'] != 1:
@ -196,17 +197,17 @@ class deemix:
def getUserFavorites(self, dz): def getUserFavorites(self, dz):
result = {} result = {}
if dz.logged_in: if dz.logged_in:
user_id = dz.user['id'] user_id = dz.current_user['id']
try: try:
result['playlists'] = dz.get_user_playlists(user_id)['data'] result['playlists'] = dz.api.get_user_playlists(user_id)['data']
result['albums'] = dz.get_user_albums(user_id)['data'] result['albums'] = dz.api.get_user_albums(user_id)['data']
result['artists'] = dz.get_user_artists(user_id)['data'] result['artists'] = dz.api.get_user_artists(user_id)['data']
result['tracks'] = dz.get_user_tracks(user_id)['data'] result['tracks'] = dz.api.get_user_tracks(user_id)['data']
except: except:
result['playlists'] = dz.get_user_playlists_gw(user_id) result['playlists'] = dz.gw.get_user_playlists(user_id)
result['albums'] = dz.get_user_albums_gw(user_id) result['albums'] = dz.gw.get_user_albums(user_id)
result['artists'] = dz.get_user_artists_gw(user_id) result['artists'] = dz.gw.get_user_artists(user_id)
result['tracks'] = dz.get_user_tracks_gw(user_id) result['tracks'] = dz.gw.get_user_tracks(user_id)
return result return result
def updateUserSpotifyPlaylists(self, user): def updateUserSpotifyPlaylists(self, user):
@ -218,32 +219,32 @@ class deemix:
return [] return []
def updateUserPlaylists(self, dz): def updateUserPlaylists(self, dz):
user_id = dz.user['id'] user_id = dz.current_user['id']
try: try:
return dz.get_user_playlists(user_id)['data'] return dz.api.get_user_playlists(user_id)['data']
except: except:
return dz.get_user_playlists_gw(user_id) return dz.gw.get_user_playlists(user_id)
def updateUserAlbums(self, dz): def updateUserAlbums(self, dz):
user_id = dz.user['id'] user_id = dz.current_user['id']
try: try:
return dz.get_user_albums(user_id)['data'] return dz.api.get_user_albums(user_id)['data']
except: except:
return dz.get_user_albums_gw(user_id) return dz.gw.get_user_albums(user_id)
def updateUserArtists(self, dz): def updateUserArtists(self, dz):
user_id = dz.user['id'] user_id = dz.current_user['id']
try: try:
return dz.get_user_artists(user_id)['data'] return dz.api.get_user_artists(user_id)['data']
except: except:
return dz.get_user_artists_gw(user_id) return dz.gw.get_user_artists(user_id)
def updateUserTracks(self, dz): def updateUserTracks(self, dz):
user_id = dz.user['id'] user_id = dz.current_user['id']
try: try:
return dz.get_user_tracks(user_id)['data'] return dz.api.get_user_tracks(user_id)['data']
except: except:
return dz.get_user_tracks_gw(user_id) return dz.gw.get_user_tracks(user_id)
def getSpotifyPlaylistTracklist(self, id): def getSpotifyPlaylistTracklist(self, id):
if id == "" or not self.sp.spotifyEnabled: if id == "" or not self.sp.spotifyEnabled:
@ -252,16 +253,62 @@ class deemix:
# Search functions # Search functions
def mainSearch(self, dz, term): def mainSearch(self, dz, term):
return dz.search_main_gw(term) results = dz.gw.search(clean_search_query(term))
order = []
for x in results['ORDER']:
if x in ['TOP_RESULT', 'TRACK', 'ALBUM', 'ARTIST', 'PLAYLIST']:
order.append(x)
if 'TOP_RESULT' in results and len(results['TOP_RESULT']):
orig_top_result = results['TOP_RESULT'][0]
top_result = {}
top_result['type'] = orig_top_result['__TYPE__']
if top_result['type'] == 'artist':
top_result['id'] = orig_top_result['ART_ID']
top_result['picture'] = 'https://e-cdns-images.dzcdn.net/images/artist/' + orig_top_result['ART_PICTURE']
top_result['title'] = orig_top_result['ART_NAME']
top_result['nb_fan'] = orig_top_result['NB_FAN']
elif top_result['type'] == 'album':
top_result['id'] = orig_top_result['ALB_ID']
top_result['picture'] = 'https://e-cdns-images.dzcdn.net/images/cover/' + orig_top_result['ALB_PICTURE']
top_result['title'] = orig_top_result['ALB_TITLE']
top_result['artist'] = orig_top_result['ART_NAME']
top_result['nb_song'] = orig_top_result['NUMBER_TRACK']
elif top_result['type'] == 'playlist':
top_result['id'] = orig_top_result['PLAYLIST_ID']
top_result['picture'] = 'https://e-cdns-images.dzcdn.net/images/' + orig_top_result['PICTURE_TYPE'] + '/' + orig_top_result['PLAYLIST_PICTURE']
top_result['title'] = orig_top_result['TITLE']
top_result['artist'] = orig_top_result['PARENT_USERNAME']
top_result['nb_song'] = orig_top_result['NB_SONG']
else:
top_result['id'] = "0"
top_result['picture'] = 'https://e-cdns-images.dzcdn.net/images/cover'
top_result['picture'] += '/156x156-000000-80-0-0.jpg'
top_result['link'] = 'https://deezer.com/'+top_result['type']+'/'+str(top_result['id'])
results['TOP_RESULT'][0] = top_result
results['ORDER'] = order
return results
def search(self, dz, term, type, start, nb): def search(self, dz, term, type, start, nb):
return dz.search(term, type, nb, start) if type == "album":
return dz.api.search_album(clean_search_query(term), limit=nb, index=start)
if type == "artist":
return dz.api.search_artist(clean_search_query(term), limit=nb, index=start)
if type == "playlist":
return dz.api.search_playlist(clean_search_query(term), limit=nb, index=start)
if type == "radio":
return dz.api.search_radio(clean_search_query(term), limit=nb, index=start)
if type == "track":
return dz.api.search_track(clean_search_query(term), limit=nb, index=start)
if type == "user":
return dz.api.search_user(clean_search_query(term), limit=nb, index=start)
return dz.api.search(clean_search_query(term), limit=nb, index=start)
def searchAlbum(self, dz, term, start, nb): # Needs to be reimplemented in deezer-py
return dz.search_album_gw(term, start, nb) # def searchAlbum(self, dz, term, start, nb):
# return None #dz.search_album_gw(term, start, nb)
def newReleases(self, dz): #
return dz.get_new_releases() # def newReleases(self, dz):
# return None #dz.get_new_releases()
# Queue functions # Queue functions
def addToQueue(self, dz, url, bitrate=None, interface=None, ack=None): def addToQueue(self, dz, url, bitrate=None, interface=None, ack=None):
@ -288,7 +335,7 @@ class deemix:
type = getTypeFromLink(link) type = getTypeFromLink(link)
relID = getIDFromLink(link, type) relID = getIDFromLink(link, type)
if type in ["track", "album"]: if type in ["track", "album"]:
data = getattr(dz, 'get_' + type)(relID) data = getattr(dz.api, 'get_' + type)(relID)
else: else:
data = {} data = {}
return (type, data) return (type, data)

View file

@ -1,4 +1,5 @@
deemix>=1.5.0 deemix>=2.0.1
deezer-py
flask flask
flask-socketio flask-socketio
eventlet eventlet

View file

@ -17,9 +17,9 @@ from flask import Flask, render_template, request, session, redirect, copy_curre
from flask_socketio import SocketIO, emit from flask_socketio import SocketIO, emit
from werkzeug.middleware.proxy_fix import ProxyFix from werkzeug.middleware.proxy_fix import ProxyFix
from deezer import Deezer
from deemix import __version__ as deemix_version from deemix import __version__ as deemix_version
from app import deemix, LoginStatus, resource_path from app import deemix, LoginStatus, resource_path
from deemix.api.deezer import Deezer
from deemix.app.messageinterface import MessageInterface from deemix.app.messageinterface import MessageInterface
# Workaround for MIME type error in certain Windows installs # Workaround for MIME type error in certain Windows installs
@ -158,7 +158,7 @@ def login(arl, force=False, child=0):
global first_connection global first_connection
if not app.isDeezerAvailable: if not app.isDeezerAvailable:
emit('logged_in', {'status': LoginStatus.NOT_AVAILABLE, 'arl': arl, 'user': session['dz'].user}) emit('logged_in', {'status': LoginStatus.NOT_AVAILABLE, 'arl': arl, 'user': session['dz'].current_user})
return return
if child == None: child = 0 if child == None: child = 0
@ -169,7 +169,7 @@ def login(arl, force=False, child=0):
result = app.login(session['dz'], arl, int(child)) result = app.login(session['dz'], arl, int(child))
if force and result == LoginStatus.SUCCESS: result = LoginStatus.FORCED_SUCCESS if force and result == LoginStatus.SUCCESS: result = LoginStatus.FORCED_SUCCESS
emit('logged_in', {'status': result, 'arl': arl, 'user': session['dz'].user}) emit('logged_in', {'status': result, 'arl': arl, 'user': session['dz'].current_user})
if first_connection and result in [LoginStatus.SUCCESS, LoginStatus.FORCED_SUCCESS]: if first_connection and result in [LoginStatus.SUCCESS, LoginStatus.FORCED_SUCCESS]:
first_connection = False first_connection = False
app.restoreDownloadQueue(session['dz'], socket_interface) app.restoreDownloadQueue(session['dz'], socket_interface)
@ -203,26 +203,27 @@ def search(data):
result['ack'] = data.get('ack') result['ack'] = data.get('ack')
emit('search', result) emit('search', result)
@socketio.on('albumSearch') # Needs to be reimplemented in deezer-py
def albumSearch(data): # @socketio.on('albumSearch')
if data['term'].strip() != "": # def albumSearch(data):
albums = app.searchAlbum(session['dz'], data['term'], data['start'], data['nb']) # if data['term'].strip() != "":
output = { # albums = app.searchAlbum(session['dz'], data['term'], data['start'], data['nb'])
'data': albums, # output = {
'total': len(albums), # 'data': albums,
'ack': data.get('ack') # 'total': len(albums),
}; # 'ack': data.get('ack')
emit('albumSearch', output) # };
# emit('albumSearch', output)
@socketio.on('newReleases') #
def newReleases(data): # @socketio.on('newReleases')
result = app.newReleases(session['dz']) # def newReleases(data):
output = { # result = app.newReleases(session['dz'])
'data': result, # output = {
'total': len(result), # 'data': result,
'ack': data.get('ack') # 'total': len(result),
}; # 'ack': data.get('ack')
emit('newReleases', output) # };
# emit('newReleases', output)
@socketio.on('queueRestored') @socketio.on('queueRestored')
def queueRestored(): def queueRestored():
@ -266,7 +267,7 @@ def analyzeLink(link):
@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'].api.get_playlist_tracks(id)['data'])
@socketio.on('update_userFavorites') @socketio.on('update_userFavorites')
def update_userFavorites(): def update_userFavorites():
@ -327,7 +328,7 @@ def applogin():
if arl: if arl:
emit('applogin_arl', arl) emit('applogin_arl', arl)
else: else:
emit('logged_in', {'status': 2, 'user': session['dz'].user}) emit('logged_in', {'status': 2, 'user': session['dz'].current_user})
else: else:
print("Can't open login page, you're not running the gui") print("Can't open login page, you're not running the gui")

2
webui

@ -1 +1 @@
Subproject commit 75225ca6a35aed2cb192d9507c8d61d907ce8381 Subproject commit 4479633551e4364e1fefdc1f7c8d2bf725bfdf33