From 85dddb27c9d7edee7ba3f12c6b8a629a7062caed Mon Sep 17 00:00:00 2001 From: RemixDev Date: Fri, 5 Jun 2020 10:47:54 +0200 Subject: [PATCH] Made interface messages abstract This removes the 'toast' interface event as it is a deemix-pyweb specific event --- deemix/app/downloader.py | 3 +-- deemix/app/queuemanager.py | 27 ++++++++------------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index 245edc2..ca26123 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -844,8 +844,7 @@ def download(dz, queueItem, interface=None): download_path = after_download(playlist, settings, queueItem) if interface: if 'cancel' in queueItem: - interface.send('toast', {'msg': "Current item cancelled.", 'icon': 'done', 'dismiss': True, - 'id': 'cancelling_' + queueItem['uuid']}) + interface.send('currentItemCancelled', queueItem['uuid']) interface.send("removedFromQueue", queueItem['uuid']) else: interface.send("finishDownload", queueItem['uuid']) diff --git a/deemix/app/queuemanager.py b/deemix/app/queuemanager.py index 4861c8b..635b4b8 100644 --- a/deemix/app/queuemanager.py +++ b/deemix/app/queuemanager.py @@ -195,17 +195,13 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf elif type == "artist": artistAPI = dz.get_artist(id) if interface: - interface.send("toast", - {'msg': f"Adding {artistAPI['name']} albums to queue", 'icon': 'loading', 'dismiss': False, - 'id': 'artist_' + str(artistAPI['id'])}) + interface.send("startAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']}) artistAPITracks = dz.get_artist_albums(id) albumList = [] for album in artistAPITracks['data']: albumList.append(generateQueueItem(dz, sp, album['link'], settings, bitrate)) if interface: - interface.send("toast", - {'msg': f"Added {artistAPI['name']} albums to queue", 'icon': 'done', 'dismiss': True, - 'id': 'artist_' + str(artistAPI['id'])}) + interface.send("finishAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']}) return albumList elif type == "spotifytrack": result = {} @@ -238,16 +234,13 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf result['error'] = "Spotify Features is not setted up correctly." return result if interface: - interface.send("toast", - {'msg': f"Converting spotify tracks to deezer tracks", 'icon': 'loading', 'dismiss': False, - 'id': 'spotifyplaylist_' + str(id)}) + interface.send("startConvertingSpotifyPlaylist", str(id)) playlist = sp.convert_spotify_playlist(dz, id, settings) playlist['bitrate'] = bitrate playlist['uuid'] = f"{playlist['type']}_{id}_{bitrate}" result = playlist if interface: - interface.send("toast", {'msg': f"Spotify playlist converted", 'icon': 'done', 'dismiss': True, - 'id': 'spotifyplaylist_' + str(id)}) + interface.send("finishConvertingSpotifyPlaylist", str(id)) else: logger.warn("URL not supported yet") result['error'] = "URL not supported yet" @@ -277,17 +270,15 @@ def addToQueue(dz, sp, url, settings, bitrate=None, interface=None): if 'error' in queueItem: logger.error(f"[{url}] {queueItem['error']}") if interface: - interface.send("toast", {'msg': queueItem['error'], 'icon': 'error'}) + interface.send("errorMessage", queueItem['error']) return False if queueItem['uuid'] in list(queueList.keys()): logger.warn(f"[{queueItem['uuid']}] Already in queue, will not be added again.") if interface: - interface.send("toast", - {'msg': f"{queueItem['title']} is already in queue!", 'icon': 'playlist_add_check'}) + interface.send("alreadyInQueue", {'uuid': queueItem['uuid'], 'title': queueItem['title']}) return False if interface: interface.send("addedToQueue", slimQueueItem(queueItem)) - interface.send("toast", {'msg': f"{queueItem['title']} added to queue", 'icon': 'playlist_add'}) logger.info(f"[{queueItem['uuid']}] Added to queue.") queue.append(queueItem['uuid']) queueList[queueItem['uuid']] = queueItem @@ -339,8 +330,7 @@ def removeFromQueue(uuid, interface=None): global currentItem, queueList, queue, queueComplete if uuid == currentItem: if interface: - interface.send('toast', {'msg': "Cancelling current item.", 'icon': 'loading', 'dismiss': False, - 'id': 'cancelling_' + uuid}) + interface.send("cancellingCurrentItem", currentItem) queueList[uuid]['cancel'] = True elif uuid in queue: queue.remove(uuid) @@ -360,8 +350,7 @@ def cancelAllDownloads(interface=None): queueComplete = [] if currentItem != "": if interface: - interface.send('toast', {'msg': "Cancelling current item.", 'icon': 'loading', 'dismiss': False, - 'id': 'cancelling_' + currentItem}) + interface.send("cancellingCurrentItem", currentItem) queueList[currentItem]['cancel'] = True for uuid in list(queueList.keys()): if uuid != currentItem: