Added errors array in queueItem for use in frontend

This commit is contained in:
RemixDev 2020-05-25 11:58:48 +02:00
parent 8fd66b1bac
commit b526486d6f
2 changed files with 74 additions and 37 deletions

View File

@ -67,8 +67,8 @@ def stream_track(dz, track, stream, trackAPI, queueItem, interface=None):
downloadPercentage += chunkProgres downloadPercentage += chunkProgres
if round(downloadPercentage) != lastPercentage and round(downloadPercentage) % 2 == 0: if round(downloadPercentage) != lastPercentage and round(downloadPercentage) % 2 == 0:
lastPercentage = round(downloadPercentage) lastPercentage = round(downloadPercentage)
if interface:
queueItem['progress'] = lastPercentage queueItem['progress'] = lastPercentage
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'progress': lastPercentage}) interface.send("updateQueue", {'uuid': queueItem['uuid'], 'progress': lastPercentage})
i += 1 i += 1
@ -81,8 +81,8 @@ def trackCompletePercentage(trackAPI, queueItem, interface):
downloadPercentage += 1 / trackAPI['SIZE'] * 100 downloadPercentage += 1 / trackAPI['SIZE'] * 100
if round(downloadPercentage) != lastPercentage and round(downloadPercentage) % 2 == 0: if round(downloadPercentage) != lastPercentage and round(downloadPercentage) % 2 == 0:
lastPercentage = round(downloadPercentage) lastPercentage = round(downloadPercentage)
if interface:
queueItem['progress'] = lastPercentage queueItem['progress'] = lastPercentage
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'progress': lastPercentage}) interface.send("updateQueue", {'uuid': queueItem['uuid'], 'progress': lastPercentage})
@ -420,11 +420,12 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
if 'SNG_TITLE' in trackAPI: if 'SNG_TITLE' in trackAPI:
result['error']['data'] = { result['error']['data'] = {
'id': trackAPI['SNG_ID'], 'id': trackAPI['SNG_ID'],
'title': trackAPI['SNG_TITLE'], 'title': trackAPI['SNG_TITLE'] + (trackAPI['VERSION'] if 'VERSION' in trackAPI and trackAPI['VERSION'] and not trackAPI['VERSION'] in trackAPI['SNG_TITLE'] else ""),
'mainArtist': {'name': trackAPI['ART_NAME']} 'artist': trackAPI['ART_NAME']
} }
if interface:
queueItem['failed'] += 1 queueItem['failed'] += 1
queueItem['errors'].append(result['error'])
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'], interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
'error': "Track not available on Deezer!"}) 'error': "Track not available on Deezer!"})
return result return result
@ -466,11 +467,16 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
trackCompletePercentage(trackAPI, queueItem, interface) trackCompletePercentage(trackAPI, queueItem, interface)
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': {
'id': track['id'],
'title': track['title'],
'artist': track['mainArtist']['name']
}
} }
if interface:
queueItem['failed'] += 1 queueItem['failed'] += 1
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, queueItem['errors'].append(result['error'])
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
'error': "Track not yet encoded and no alternative found!"}) 'error': "Track not yet encoded and no alternative found!"})
return result return result
else: else:
@ -478,11 +484,16 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
trackCompletePercentage(trackAPI, queueItem, interface) trackCompletePercentage(trackAPI, queueItem, interface)
result['error'] = { result['error'] = {
'message': "Track not yet encoded!", 'message': "Track not yet encoded!",
'data': track 'data': {
'id': track['id'],
'title': track['title'],
'artist': track['mainArtist']['name']
}
} }
if interface:
queueItem['failed'] += 1 queueItem['failed'] += 1
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, queueItem['errors'].append(result['error'])
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
'error': "Track not yet encoded!"}) 'error': "Track not yet encoded!"})
return result return result
@ -493,11 +504,16 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
trackCompletePercentage(trackAPI, queueItem, interface) trackCompletePercentage(trackAPI, queueItem, interface)
result['error'] = { result['error'] = {
'message': "Track not found at desired bitrate.", 'message': "Track not found at desired bitrate.",
'data': track 'data': {
'id': track['id'],
'title': track['title'],
'artist': track['mainArtist']['name']
}
} }
if interface:
queueItem['failed'] += 1 queueItem['failed'] += 1
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, queueItem['errors'].append(result['error'])
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
'error': "Track not found at desired bitrate."}) 'error': "Track not found at desired bitrate."})
return result return result
elif format == -200: elif format == -200:
@ -505,11 +521,16 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
trackCompletePercentage(trackAPI, queueItem, interface) trackCompletePercentage(trackAPI, queueItem, interface)
result['error'] = { result['error'] = {
'message': "Track is not available in Reality Audio 360.", 'message': "Track is not available in Reality Audio 360.",
'data': track 'data': {
'id': track['id'],
'title': track['title'],
'artist': track['mainArtist']['name']
}
} }
if interface:
queueItem['failed'] += 1 queueItem['failed'] += 1
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, queueItem['errors'].append(result['error'])
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
'error': "Track is not available in Reality Audio 360."}) 'error': "Track is not available in Reality Audio 360."})
return result return result
track['selectedFormat'] = format track['selectedFormat'] = format
@ -673,11 +694,16 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
trackCompletePercentage(trackAPI, queueItem, interface) trackCompletePercentage(trackAPI, queueItem, interface)
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': {
'id': track['id'],
'title': track['title'],
'artist': track['mainArtist']['name']
}
} }
if interface:
queueItem['failed'] += 1 queueItem['failed'] += 1
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, queueItem['errors'].append(result['error'])
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
'error': "Track not available on deezer's servers and no alternative found!"}) 'error': "Track not available on deezer's servers and no alternative found!"})
return result return result
else: else:
@ -685,11 +711,16 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
trackCompletePercentage(trackAPI, queueItem, interface) trackCompletePercentage(trackAPI, queueItem, interface)
result['error'] = { result['error'] = {
'message': "Track not available on deezer's servers!", 'message': "Track not available on deezer's servers!",
'data': track 'data': {
'id': track['id'],
'title': track['title'],
'artist': track['mainArtist']['name']
}
} }
if interface:
queueItem['failed'] += 1 queueItem['failed'] += 1
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': track, queueItem['errors'].append(result['error'])
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
'error': "Track not available on deezer's servers!"}) 'error': "Track not available on deezer's servers!"})
return result return result
else: else:
@ -704,8 +735,8 @@ 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"]}'
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Track download completed") logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Track download completed")
if interface:
queueItem['downloaded'] += 1 queueItem['downloaded'] += 1
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'downloaded': True}) interface.send("updateQueue", {'uuid': queueItem['uuid'], 'downloaded': True})
return result return result
@ -719,15 +750,16 @@ def downloadTrackObj_wrap(dz, track, settings, bitrate, queueItem, interface):
'message': str(e), 'message': str(e),
'data': { 'data': {
'id': track['SNG_ID'], 'id': track['SNG_ID'],
'title': track['SNG_TITLE'] + ( 'title': track['SNG_TITLE'] + (trackAPI['VERSION'] if 'VERSION' in trackAPI and trackAPI['VERSION'] and not trackAPI['VERSION'] in trackAPI['SNG_TITLE'] else ""),
" " + track['VERSION'] if 'VERSION' in track and track['VERSION'] else ""), 'artist': track['ART_NAME']
'mainArtist': {'name': track['ART_NAME']}
} }
} }
} }
if interface:
queueItem['failed'] += 1 queueItem['failed'] += 1
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True}) queueItem['errors'].append(result['error'])
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
'error': result['error']['message']})
return result return result
@ -746,16 +778,16 @@ def download(dz, queueItem, interface=None):
'message': str(e), 'message': str(e),
'data': { 'data': {
'id': queueItem['single']['SNG_ID'], 'id': queueItem['single']['SNG_ID'],
'title': queueItem['single']['SNG_TITLE'] + ( 'title': queueItem['single']['SNG_TITLE'] + (queueItem['single']['VERSION'] if 'VERSION' in queueItem['single'] and queueItem['single']['VERSION'] and not queueItem['single']['VERSION'] in queueItem['single']['SNG_TITLE'] else ""),
" " + queueItem['single']['VERSION'] if 'VERSION' in queueItem['single'] and
queueItem['single']['VERSION'] else ""),
'mainArtist': {'name': queueItem['single']['ART_NAME']} 'mainArtist': {'name': queueItem['single']['ART_NAME']}
} }
} }
} }
if interface:
queueItem['failed'] += 1 queueItem['failed'] += 1
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True}) queueItem['errors'].append(result['error'])
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
'error': result['error']['message']})
download_path = after_download_single(result, settings, queueItem) download_path = after_download_single(result, settings, queueItem)
elif 'collection' in queueItem: elif 'collection' in queueItem:
playlist = [None] * len(queueItem['collection']) playlist = [None] * len(queueItem['collection'])
@ -789,8 +821,8 @@ def after_download(tracks, settings, queueItem):
return None return None
if 'error' in result: if 'error' in result:
if not 'data' in result['error']: if not 'data' in result['error']:
result['error']['data'] = {'id': 0, 'title': 'Unknown', 'mainArtist': {'name': 'Unknown'}} result['error']['data'] = {'id': 0, 'title': 'Unknown', 'artist': 'Unknown'}
errors += f"{result['error']['data']['id']} | {result['error']['data']['mainArtist']['name']} - {result['error']['data']['title']} | {result['error']['message']}\r\n" errors += f"{result['error']['data']['id']} | {result['error']['data']['artist']} - {result['error']['data']['title']} | {result['error']['message']}\r\n"
if 'searched' in result: if 'searched' in result:
searched += result['searched'] + "\r\n" searched += result['searched'] + "\r\n"
if not extrasPath and 'extrasPath' in result: if not extrasPath and 'extrasPath' in result:

View File

@ -19,6 +19,7 @@ queueItem base structure
size size
downloaded downloaded
failed failed
errors
progress progress
type type
id id
@ -38,6 +39,7 @@ def resetQueueItems(items, q):
result[item]['downloaded'] = 0 result[item]['downloaded'] = 0
result[item]['failed'] = 0 result[item]['failed'] = 0
result[item]['progress'] = 0 result[item]['progress'] = 0
result[item]['errors'] = []
return result return result
def slimQueueItems(items): def slimQueueItems(items):
@ -82,6 +84,7 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
result['size'] = 1 result['size'] = 1
result['downloaded'] = 0 result['downloaded'] = 0
result['failed'] = 0 result['failed'] = 0
result['errors'] = []
result['progress'] = 0 result['progress'] = 0
result['type'] = 'track' result['type'] = 'track'
result['id'] = id result['id'] = id
@ -109,6 +112,7 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
result['size'] = albumAPI['nb_tracks'] result['size'] = albumAPI['nb_tracks']
result['downloaded'] = 0 result['downloaded'] = 0
result['failed'] = 0 result['failed'] = 0
result['errors'] = []
result['progress'] = 0 result['progress'] = 0
result['type'] = 'album' result['type'] = 'album'
result['id'] = id result['id'] = id
@ -172,6 +176,7 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
result['size'] = playlistAPI['nb_tracks'] result['size'] = playlistAPI['nb_tracks']
result['downloaded'] = 0 result['downloaded'] = 0
result['failed'] = 0 result['failed'] = 0
result['errors'] = []
result['progress'] = 0 result['progress'] = 0
result['type'] = 'playlist' result['type'] = 'playlist'
result['id'] = id result['id'] = id