Abstractized socketio with MessageInterface
This commit is contained in:
parent
092d935ab8
commit
0473eb4aa3
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
class MessageInterface:
|
||||||
|
def send(self, message, value):
|
||||||
|
"""Implement this class to process updates and messages from the core"""
|
||||||
|
pass
|
|
@ -30,7 +30,7 @@ extensions = {
|
||||||
downloadPercentage = 0
|
downloadPercentage = 0
|
||||||
lastPercentage = 0
|
lastPercentage = 0
|
||||||
|
|
||||||
def stream_track(dz, track, stream, trackAPI, queueItem, socket=None):
|
def stream_track(dz, track, stream, trackAPI, queueItem, interface=None):
|
||||||
global downloadPercentage, lastPercentage
|
global downloadPercentage, lastPercentage
|
||||||
if 'cancel' in queueItem:
|
if 'cancel' in queueItem:
|
||||||
raise downloadCancelled
|
raise downloadCancelled
|
||||||
|
@ -38,7 +38,7 @@ def stream_track(dz, track, stream, trackAPI, queueItem, socket=None):
|
||||||
request = get(track['downloadUrl'], headers=dz.http_headers, stream=True, timeout=30)
|
request = get(track['downloadUrl'], headers=dz.http_headers, stream=True, timeout=30)
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
sleep(2)
|
sleep(2)
|
||||||
return stream_track(dz, track, stream, trackAPI, queueItem, socket)
|
return stream_track(dz, track, stream, trackAPI, queueItem, interface)
|
||||||
request.raise_for_status()
|
request.raise_for_status()
|
||||||
blowfish_key = str.encode(dz._get_blowfish_key(str(track['id'])))
|
blowfish_key = str.encode(dz._get_blowfish_key(str(track['id'])))
|
||||||
complete = track['selectedFilesize']
|
complete = track['selectedFilesize']
|
||||||
|
@ -60,9 +60,9 @@ def stream_track(dz, track, stream, trackAPI, queueItem, socket=None):
|
||||||
downloadPercentage += chunkProgres
|
downloadPercentage += chunkProgres
|
||||||
if round(downloadPercentage) != lastPercentage and round(percentage) % 5 == 0:
|
if round(downloadPercentage) != lastPercentage and round(percentage) % 5 == 0:
|
||||||
lastPercentage = round(downloadPercentage)
|
lastPercentage = round(downloadPercentage)
|
||||||
if socket:
|
if interface:
|
||||||
queueItem['progress'] = lastPercentage
|
queueItem['progress'] = lastPercentage
|
||||||
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'progress': lastPercentage})
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'progress': lastPercentage})
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
def downloadImage(url, path):
|
def downloadImage(url, path):
|
||||||
|
@ -372,7 +372,7 @@ def getTrackData(dz, trackAPI_gw, trackAPI = None, albumAPI_gw = None, albumAPI
|
||||||
|
|
||||||
return track
|
return track
|
||||||
|
|
||||||
def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None, socket=None):
|
def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None, interface=None):
|
||||||
result = {}
|
result = {}
|
||||||
if 'cancel' in queueItem:
|
if 'cancel' in queueItem:
|
||||||
result['cancel'] = True
|
result['cancel'] = True
|
||||||
|
@ -388,9 +388,9 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
'title': trackAPI['SNG_TITLE'],
|
'title': trackAPI['SNG_TITLE'],
|
||||||
'mainArtist': {'name': trackAPI['ART_NAME']}
|
'mainArtist': {'name': trackAPI['ART_NAME']}
|
||||||
}
|
}
|
||||||
if socket:
|
if interface:
|
||||||
queueItem['failed'] += 1
|
queueItem['failed'] += 1
|
||||||
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'], 'error': "Track not available on Deezer!"})
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'], 'error': "Track not available on Deezer!"})
|
||||||
return result
|
return result
|
||||||
# Get the metadata
|
# Get the metadata
|
||||||
if extraTrack:
|
if extraTrack:
|
||||||
|
@ -412,7 +412,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
if not 'MD5_ORIGIN' in trackNew:
|
if not 'MD5_ORIGIN' in trackNew:
|
||||||
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
||||||
track = parseEssentialTrackData(track, trackNew)
|
track = parseEssentialTrackData(track, trackNew)
|
||||||
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, socket=socket)
|
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
|
||||||
elif not 'searched' in track and settings['fallbackSearch']:
|
elif not 'searched' in track and settings['fallbackSearch']:
|
||||||
print("Track not yet encoded, searching for alternative")
|
print("Track not yet encoded, searching for alternative")
|
||||||
searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'], track['album']['title'])
|
searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'], track['album']['title'])
|
||||||
|
@ -422,16 +422,16 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
||||||
track = parseEssentialTrackData(track, trackNew)
|
track = parseEssentialTrackData(track, trackNew)
|
||||||
track['searched'] = True
|
track['searched'] = True
|
||||||
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, socket=socket)
|
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
|
||||||
else:
|
else:
|
||||||
print("ERROR: Track not yet encoded and no alternative found!")
|
print("ERROR: Track not yet encoded and no alternative found!")
|
||||||
result['error'] = {
|
result['error'] = {
|
||||||
'message': "Track not yet encoded and no alternative found!",
|
'message': "Track not yet encoded and no alternative found!",
|
||||||
'data': track
|
'data': track
|
||||||
}
|
}
|
||||||
if socket:
|
if interface:
|
||||||
queueItem['failed'] += 1
|
queueItem['failed'] += 1
|
||||||
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not yet encoded and no alternative found!"})
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not yet encoded and no alternative found!"})
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
print("ERROR: Track not yet encoded!")
|
print("ERROR: Track not yet encoded!")
|
||||||
|
@ -439,9 +439,9 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
'message': "Track not yet encoded!",
|
'message': "Track not yet encoded!",
|
||||||
'data': track
|
'data': track
|
||||||
}
|
}
|
||||||
if socket:
|
if interface:
|
||||||
queueItem['failed'] += 1
|
queueItem['failed'] += 1
|
||||||
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not yet encoded!"})
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not yet encoded!"})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# Get the selected bitrate
|
# Get the selected bitrate
|
||||||
|
@ -452,9 +452,9 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
'message': "Track not found at desired bitrate.",
|
'message': "Track not found at desired bitrate.",
|
||||||
'data': track
|
'data': track
|
||||||
}
|
}
|
||||||
if socket:
|
if interface:
|
||||||
queueItem['failed'] += 1
|
queueItem['failed'] += 1
|
||||||
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not found at desired bitrate."})
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not found at desired bitrate."})
|
||||||
return result
|
return result
|
||||||
elif format == -200:
|
elif format == -200:
|
||||||
print("ERROR: This track is not available in 360 Reality Audio format. Please select another format.")
|
print("ERROR: This track is not available in 360 Reality Audio format. Please select another format.")
|
||||||
|
@ -462,9 +462,9 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
'message': "Track is not available in Reality Audio 360.",
|
'message': "Track is not available in Reality Audio 360.",
|
||||||
'data': track
|
'data': track
|
||||||
}
|
}
|
||||||
if socket:
|
if interface:
|
||||||
queueItem['failed'] += 1
|
queueItem['failed'] += 1
|
||||||
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track is not available in Reality Audio 360."})
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track is not available in Reality Audio 360."})
|
||||||
return result
|
return result
|
||||||
track['selectedFormat'] = format
|
track['selectedFormat'] = format
|
||||||
track['selectedFilesize'] = filesize
|
track['selectedFilesize'] = filesize
|
||||||
|
@ -547,7 +547,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
track['downloadUrl'] = dz.get_track_stream_url(track['id'], track['MD5'], track['mediaVersion'], track['selectedFormat'])
|
track['downloadUrl'] = dz.get_track_stream_url(track['id'], track['MD5'], track['mediaVersion'], track['selectedFormat'])
|
||||||
try:
|
try:
|
||||||
with open(writepath, 'wb') as stream:
|
with open(writepath, 'wb') as stream:
|
||||||
stream_track(dz, track, stream, trackAPI, queueItem, socket)
|
stream_track(dz, track, stream, trackAPI, queueItem, interface)
|
||||||
except downloadCancelled:
|
except downloadCancelled:
|
||||||
remove(writepath)
|
remove(writepath)
|
||||||
result['cancel'] = True
|
result['cancel'] = True
|
||||||
|
@ -557,14 +557,14 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
if track['selectedFormat'] == 9 and settings['fallbackBitrate']:
|
if track['selectedFormat'] == 9 and settings['fallbackBitrate']:
|
||||||
print("Track not available in flac, trying mp3")
|
print("Track not available in flac, trying mp3")
|
||||||
track['filesize']['flac'] = 0
|
track['filesize']['flac'] = 0
|
||||||
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, socket=socket)
|
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
|
||||||
elif track['fallbackId'] != 0:
|
elif track['fallbackId'] != 0:
|
||||||
print("Track not available, using fallback id")
|
print("Track not available, using fallback id")
|
||||||
trackNew = dz.get_track_gw(track['fallbackId'])
|
trackNew = dz.get_track_gw(track['fallbackId'])
|
||||||
if not 'MD5_ORIGIN' in trackNew:
|
if not 'MD5_ORIGIN' in trackNew:
|
||||||
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
||||||
track = parseEssentialTrackData(track, trackNew)
|
track = parseEssentialTrackData(track, trackNew)
|
||||||
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, socket=socket)
|
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
|
||||||
elif not 'searched' in track and settings['fallbackSearch']:
|
elif not 'searched' in track and settings['fallbackSearch']:
|
||||||
print("Track not available, searching for alternative")
|
print("Track not available, searching for alternative")
|
||||||
searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'], track['album']['title'])
|
searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'], track['album']['title'])
|
||||||
|
@ -574,16 +574,16 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
||||||
track = parseEssentialTrackData(track, trackNew)
|
track = parseEssentialTrackData(track, trackNew)
|
||||||
track['searched'] = True
|
track['searched'] = True
|
||||||
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, socket=socket)
|
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
|
||||||
else:
|
else:
|
||||||
print("ERROR: Track not available on deezer's servers and no alternative found!")
|
print("ERROR: Track not available on deezer's servers and no alternative found!")
|
||||||
result['error'] = {
|
result['error'] = {
|
||||||
'message': "Track not available on deezer's servers and no alternative found!",
|
'message': "Track not available on deezer's servers and no alternative found!",
|
||||||
'data': track
|
'data': track
|
||||||
}
|
}
|
||||||
if socket:
|
if interface:
|
||||||
queueItem['failed'] += 1
|
queueItem['failed'] += 1
|
||||||
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not available on deezer's servers and no alternative found!"})
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not available on deezer's servers and no alternative found!"})
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
print("ERROR: Track not available on deezer's servers!")
|
print("ERROR: Track not available on deezer's servers!")
|
||||||
|
@ -591,9 +591,9 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
'message': "Track not available on deezer's servers!",
|
'message': "Track not available on deezer's servers!",
|
||||||
'data': track
|
'data': track
|
||||||
}
|
}
|
||||||
if socket:
|
if interface:
|
||||||
queueItem['failed'] += 1
|
queueItem['failed'] += 1
|
||||||
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not available on deezer's servers!"})
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, 'error': "Track not available on deezer's servers!"})
|
||||||
return result
|
return result
|
||||||
if track['selectedFormat'] in [3, 1, 8]:
|
if track['selectedFormat'] in [3, 1, 8]:
|
||||||
tagID3(writepath, track, settings['tags'])
|
tagID3(writepath, track, settings['tags'])
|
||||||
|
@ -602,14 +602,14 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
if 'searched' in track:
|
if 'searched' in track:
|
||||||
result['searched'] = f'{track["mainArtist"]["name"]} - {track["title"]}'
|
result['searched'] = f'{track["mainArtist"]["name"]} - {track["title"]}'
|
||||||
print("Done!")
|
print("Done!")
|
||||||
if socket:
|
if interface:
|
||||||
queueItem['downloaded'] += 1
|
queueItem['downloaded'] += 1
|
||||||
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'downloaded': True})
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'downloaded': True})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def downloadTrackObj_wrap(dz, track, settings, bitrate, queueItem, socket):
|
def downloadTrackObj_wrap(dz, track, settings, bitrate, queueItem, interface):
|
||||||
try:
|
try:
|
||||||
result = downloadTrackObj(dz, track, settings, bitrate, queueItem, socket=socket)
|
result = downloadTrackObj(dz, track, settings, bitrate, queueItem, interface=interface)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result = {'error': {
|
result = {'error': {
|
||||||
'message': str(e),
|
'message': str(e),
|
||||||
|
@ -620,12 +620,12 @@ def downloadTrackObj_wrap(dz, track, settings, bitrate, queueItem, socket):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if socket:
|
if interface:
|
||||||
queueItem['failed'] += 1
|
queueItem['failed'] += 1
|
||||||
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True})
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def download(dz, queueItem, socket=None):
|
def download(dz, queueItem, interface=None):
|
||||||
global downloadPercentage, lastPercentage
|
global downloadPercentage, lastPercentage
|
||||||
settings = queueItem['settings']
|
settings = queueItem['settings']
|
||||||
bitrate = queueItem['bitrate']
|
bitrate = queueItem['bitrate']
|
||||||
|
@ -633,7 +633,7 @@ def download(dz, queueItem, socket=None):
|
||||||
lastPercentage = 0
|
lastPercentage = 0
|
||||||
if 'single' in queueItem:
|
if 'single' in queueItem:
|
||||||
try:
|
try:
|
||||||
result = downloadTrackObj(dz, queueItem['single'], settings, bitrate, queueItem, socket=socket)
|
result = downloadTrackObj(dz, queueItem['single'], settings, bitrate, queueItem, interface=interface)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result = {'error': {
|
result = {'error': {
|
||||||
'message': str(e),
|
'message': str(e),
|
||||||
|
@ -644,26 +644,26 @@ def download(dz, queueItem, socket=None):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if socket:
|
if interface:
|
||||||
queueItem['failed'] += 1
|
queueItem['failed'] += 1
|
||||||
socket.emit("updateQueue", {'uuid': queueItem['uuid'], 'failed': True})
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True})
|
||||||
download_path = after_download_single(result, settings, queueItem)
|
download_path = after_download_single(result, settings, queueItem)
|
||||||
elif 'collection' in queueItem:
|
elif 'collection' in queueItem:
|
||||||
print("Downloading collection")
|
print("Downloading collection")
|
||||||
playlist = [None] * len(queueItem['collection'])
|
playlist = [None] * len(queueItem['collection'])
|
||||||
with ThreadPoolExecutor(settings['queueConcurrency']) as executor:
|
with ThreadPoolExecutor(settings['queueConcurrency']) as executor:
|
||||||
for pos, track in enumerate(queueItem['collection'], start=0):
|
for pos, track in enumerate(queueItem['collection'], start=0):
|
||||||
playlist[pos] = executor.submit(downloadTrackObj_wrap, dz, track, settings, bitrate, queueItem, socket=socket)
|
playlist[pos] = executor.submit(downloadTrackObj_wrap, dz, track, settings, bitrate, queueItem, interface=interface)
|
||||||
download_path = after_download(playlist, settings, queueItem)
|
download_path = after_download(playlist, settings, queueItem)
|
||||||
if socket:
|
if interface:
|
||||||
if 'cancel' in queueItem:
|
if 'cancel' in queueItem:
|
||||||
socket.emit('toast', {'msg': "Current item cancelled.", 'icon':'done', 'dismiss': True, 'id':'cancelling_'+queueItem['uuid']})
|
interface.send('toast', {'msg': "Current item cancelled.", 'icon':'done', 'dismiss': True, 'id':'cancelling_'+queueItem['uuid']})
|
||||||
socket.emit("removedFromQueue", queueItem['uuid'])
|
interface.send("removedFromQueue", queueItem['uuid'])
|
||||||
else:
|
else:
|
||||||
socket.emit("finishDownload", queueItem['uuid'])
|
interface.send("finishDownload", queueItem['uuid'])
|
||||||
return {
|
return {
|
||||||
'dz': dz,
|
'dz': dz,
|
||||||
'socket': socket,
|
'interface': interface,
|
||||||
'download_path': download_path
|
'download_path': download_path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ if its an album/playlist
|
||||||
collection
|
collection
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def generateQueueItem(dz, url, settings, bitrate=None, albumAPI=None, socket=None):
|
def generateQueueItem(dz, url, settings, bitrate=None, albumAPI=None, interface=None):
|
||||||
forcedBitrate = getBitrateInt(bitrate)
|
forcedBitrate = getBitrateInt(bitrate)
|
||||||
bitrate = forcedBitrate if forcedBitrate else settings['maxBitrate']
|
bitrate = forcedBitrate if forcedBitrate else settings['maxBitrate']
|
||||||
type = getTypeFromLink(url)
|
type = getTypeFromLink(url)
|
||||||
|
@ -116,14 +116,14 @@ def generateQueueItem(dz, url, settings, bitrate=None, albumAPI=None, socket=Non
|
||||||
|
|
||||||
elif type == "artist":
|
elif type == "artist":
|
||||||
artistAPI = dz.get_artist(id)
|
artistAPI = dz.get_artist(id)
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("toast", {'msg': f"Adding {artistAPI['name']} albums to queue", 'icon': 'loading', 'dismiss': False, 'id': 'artist_'+str(artistAPI['id'])})
|
interface.send("toast", {'msg': f"Adding {artistAPI['name']} albums to queue", 'icon': 'loading', 'dismiss': False, 'id': 'artist_'+str(artistAPI['id'])})
|
||||||
artistAPITracks = dz.get_artist_albums(id)
|
artistAPITracks = dz.get_artist_albums(id)
|
||||||
albumList = []
|
albumList = []
|
||||||
for album in artistAPITracks['data']:
|
for album in artistAPITracks['data']:
|
||||||
albumList.append(generateQueueItem(dz, album['link'], settings, bitrate))
|
albumList.append(generateQueueItem(dz, album['link'], settings, bitrate))
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("toast", {'msg': f"Added {artistAPI['name']} albums to queue", 'icon': 'done', 'dismiss': True, 'id': 'artist_'+str(artistAPI['id'])})
|
interface.send("toast", {'msg': f"Added {artistAPI['name']} albums to queue", 'icon': 'done', 'dismiss': True, 'id': 'artist_'+str(artistAPI['id'])})
|
||||||
return albumList
|
return albumList
|
||||||
elif type == "spotifytrack":
|
elif type == "spotifytrack":
|
||||||
track_id = get_trackid_spotify(dz, id, settings['fallbackSearch'])
|
track_id = get_trackid_spotify(dz, id, settings['fallbackSearch'])
|
||||||
|
@ -147,23 +147,23 @@ def generateQueueItem(dz, url, settings, bitrate=None, albumAPI=None, socket=Non
|
||||||
print("Album not found on deezer!")
|
print("Album not found on deezer!")
|
||||||
result['error'] = "Album not found on deezer!"
|
result['error'] = "Album not found on deezer!"
|
||||||
elif type == "spotifyplaylist":
|
elif type == "spotifyplaylist":
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("toast", {'msg': f"Converting spotify tracks to deezer tracks", 'icon': 'loading', 'dismiss': False, 'id': 'spotifyplaylist_'+str(id)})
|
interface.send("toast", {'msg': f"Converting spotify tracks to deezer tracks", 'icon': 'loading', 'dismiss': False, 'id': 'spotifyplaylist_'+str(id)})
|
||||||
result = convert_spotify_playlist(dz, id, settings)
|
result = convert_spotify_playlist(dz, id, settings)
|
||||||
result['bitrate'] = bitrate
|
result['bitrate'] = bitrate
|
||||||
result['uuid'] = f"{result['type']}_{id}_{bitrate}"
|
result['uuid'] = f"{result['type']}_{id}_{bitrate}"
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("toast", {'msg': f"Spotify playlist converted", 'icon': 'done', 'dismiss': True, 'id': 'spotifyplaylist_'+str(id)})
|
interface.send("toast", {'msg': f"Spotify playlist converted", 'icon': 'done', 'dismiss': True, 'id': 'spotifyplaylist_'+str(id)})
|
||||||
else:
|
else:
|
||||||
print("URL not supported yet")
|
print("URL not supported yet")
|
||||||
result['error'] = "URL not supported yet"
|
result['error'] = "URL not supported yet"
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def addToQueue(dz, url, settings, bitrate=None, socket=None):
|
def addToQueue(dz, url, settings, bitrate=None, interface=None):
|
||||||
global currentItem, queueList, queue
|
global currentItem, queueList, queue
|
||||||
if not dz.logged_in:
|
if not dz.logged_in:
|
||||||
return "Not logged in"
|
return "Not logged in"
|
||||||
queueItem = generateQueueItem(dz, url, settings, bitrate, socket=socket)
|
queueItem = generateQueueItem(dz, url, settings, bitrate, interface=interface)
|
||||||
if type(queueItem) is list:
|
if type(queueItem) is list:
|
||||||
for x in queueItem:
|
for x in queueItem:
|
||||||
if 'error' in x:
|
if 'error' in x:
|
||||||
|
@ -171,29 +171,29 @@ def addToQueue(dz, url, settings, bitrate=None, socket=None):
|
||||||
if x['uuid'] in list(queueList.keys()):
|
if x['uuid'] in list(queueList.keys()):
|
||||||
print("Already in queue!")
|
print("Already in queue!")
|
||||||
continue
|
continue
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("addedToQueue", x)
|
interface.send("addedToQueue", x)
|
||||||
queue.append(x['uuid'])
|
queue.append(x['uuid'])
|
||||||
queueList[x['uuid']] = x
|
queueList[x['uuid']] = x
|
||||||
else:
|
else:
|
||||||
if 'error' in queueItem:
|
if 'error' in queueItem:
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("toast", {'msg': queueItem['error'], 'icon': 'error'})
|
interface.send("toast", {'msg': queueItem['error'], 'icon': 'error'})
|
||||||
return False
|
return False
|
||||||
if queueItem['uuid'] in list(queueList.keys()):
|
if queueItem['uuid'] in list(queueList.keys()):
|
||||||
print("Already in queue!")
|
print("Already in queue!")
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("toast", {'msg': f"{queueItem['title']} is already in queue!", 'icon': 'playlist_add_check'})
|
interface.send("toast", {'msg': f"{queueItem['title']} is already in queue!", 'icon': 'playlist_add_check'})
|
||||||
return False
|
return False
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("addedToQueue", queueItem)
|
interface.send("addedToQueue", queueItem)
|
||||||
socket.emit("toast", {'msg': f"{queueItem['title']} added to queue", 'icon': 'playlist_add'})
|
interface.send("toast", {'msg': f"{queueItem['title']} added to queue", 'icon': 'playlist_add'})
|
||||||
queue.append(queueItem['uuid'])
|
queue.append(queueItem['uuid'])
|
||||||
queueList[queueItem['uuid']] = queueItem
|
queueList[queueItem['uuid']] = queueItem
|
||||||
nextItem(dz, socket)
|
nextItem(dz, interface)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def nextItem(dz, socket=None):
|
def nextItem(dz, interface=None):
|
||||||
global currentItem, queueList, queue
|
global currentItem, queueList, queue
|
||||||
if currentItem != "":
|
if currentItem != "":
|
||||||
return None
|
return None
|
||||||
|
@ -202,9 +202,9 @@ def nextItem(dz, socket=None):
|
||||||
currentItem = queue.pop(0)
|
currentItem = queue.pop(0)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("startDownload", currentItem)
|
interface.send("startDownload", currentItem)
|
||||||
result = download(dz, queueList[currentItem], socket)
|
result = download(dz, queueList[currentItem], interface)
|
||||||
callbackQueueDone(result)
|
callbackQueueDone(result)
|
||||||
|
|
||||||
def callbackQueueDone(result):
|
def callbackQueueDone(result):
|
||||||
|
@ -214,47 +214,47 @@ def callbackQueueDone(result):
|
||||||
else:
|
else:
|
||||||
queueComplete.append(currentItem)
|
queueComplete.append(currentItem)
|
||||||
currentItem = ""
|
currentItem = ""
|
||||||
nextItem(result['dz'], result['socket'])
|
nextItem(result['dz'], result['interface'])
|
||||||
|
|
||||||
def getQueue():
|
def getQueue():
|
||||||
global currentItem, queueList, queue, queueComplete
|
global currentItem, queueList, queue, queueComplete
|
||||||
return (queue, queueComplete, queueList, currentItem)
|
return (queue, queueComplete, queueList, currentItem)
|
||||||
|
|
||||||
def removeFromQueue(uuid, socket=None):
|
def removeFromQueue(uuid, interface=None):
|
||||||
global currentItem, queueList, queue, queueComplete
|
global currentItem, queueList, queue, queueComplete
|
||||||
if uuid == currentItem:
|
if uuid == currentItem:
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit('toast', {'msg': "Cancelling current item.", 'icon':'loading', 'dismiss': False, 'id':'cancelling_'+uuid})
|
interface.send('toast', {'msg': "Cancelling current item.", 'icon':'loading', 'dismiss': False, 'id':'cancelling_'+uuid})
|
||||||
queueList[uuid]['cancel'] = True
|
queueList[uuid]['cancel'] = True
|
||||||
elif uuid in queue:
|
elif uuid in queue:
|
||||||
queue.remove(uuid)
|
queue.remove(uuid)
|
||||||
del queueList[uuid]
|
del queueList[uuid]
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("removedFromQueue", uuid)
|
interface.send("removedFromQueue", uuid)
|
||||||
elif uuid in queueComplete:
|
elif uuid in queueComplete:
|
||||||
queueComplete.remove(uuid)
|
queueComplete.remove(uuid)
|
||||||
del queueList[uuid]
|
del queueList[uuid]
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("removedFromQueue", uuid)
|
interface.send("removedFromQueue", uuid)
|
||||||
|
|
||||||
def cancelAllDownloads(socket=None):
|
def cancelAllDownloads(interface=None):
|
||||||
global currentItem, queueList, queue, queueComplete
|
global currentItem, queueList, queue, queueComplete
|
||||||
queue = []
|
queue = []
|
||||||
queueComplete = []
|
queueComplete = []
|
||||||
if currentItem != "":
|
if currentItem != "":
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit('toast', {'msg': "Cancelling current item.", 'icon':'loading', 'dismiss': False, 'id':'cancelling_'+currentItem})
|
interface.send('toast', {'msg': "Cancelling current item.", 'icon':'loading', 'dismiss': False, 'id':'cancelling_'+currentItem})
|
||||||
queueList[currentItem]['cancel'] = True
|
queueList[currentItem]['cancel'] = True
|
||||||
for uuid in list(queueList.keys()):
|
for uuid in list(queueList.keys()):
|
||||||
if uuid != currentItem:
|
if uuid != currentItem:
|
||||||
del queueList[uuid]
|
del queueList[uuid]
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("removedAllDownloads", currentItem)
|
interface.send("removedAllDownloads", currentItem)
|
||||||
|
|
||||||
def removeFinishedDownloads(socket=None):
|
def removeFinishedDownloads(interface=None):
|
||||||
global queueList, queueComplete
|
global queueList, queueComplete
|
||||||
for uuid in queueComplete:
|
for uuid in queueComplete:
|
||||||
del queueList[uuid]
|
del queueList[uuid]
|
||||||
queueComplete = []
|
queueComplete = []
|
||||||
if socket:
|
if interface:
|
||||||
socket.emit("removedFinishedDownloads")
|
interface.send("removedFinishedDownloads")
|
||||||
|
|
Loading…
Reference in New Issue