Added fallback ID to "Track not found at desired bitrate"

This fixes #7
This commit is contained in:
RemixDev 2020-05-30 17:31:14 +02:00
parent 54ca38e745
commit c27da21f1b
1 changed files with 52 additions and 15 deletions

View File

@ -500,22 +500,59 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
# Get the selected bitrate # Get the selected bitrate
format = getPreferredBitrate(dz, track, bitrate, settings['fallbackBitrate']) format = getPreferredBitrate(dz, track, bitrate, settings['fallbackBitrate'])
if format == -100: if format == -100:
logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not found at desired bitrate. Enable fallback to lower bitrates to fix this issue.") if track['fallbackId'] != 0:
trackCompletePercentage(trackAPI, queueItem, interface) logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Track not found at desired bitrate, using fallback id")
result['error'] = { trackNew = dz.get_track_gw(track['fallbackId'])
'message': "Track not found at desired bitrate.", if not 'MD5_ORIGIN' in trackNew:
'data': { trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
'id': track['id'], track = parseEssentialTrackData(track, trackNew)
'title': track['title'], return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
'artist': track['mainArtist']['name'] elif not 'searched' in track and settings['fallbackSearch']:
logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Track not found at desired bitrate, searching for alternative")
searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'],
track['album']['title'])
if searchedId != 0:
trackNew = dz.get_track_gw(searchedId)
if not 'MD5_ORIGIN' in trackNew:
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
track = parseEssentialTrackData(track, trackNew)
track['searched'] = True
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track,
interface=interface)
else:
logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not found at desired bitrate and no alternative found!")
trackCompletePercentage(trackAPI, queueItem, interface)
result['error'] = {
'message': "Track not found at desired bitrate and no alternative found!",
'data': {
'id': track['id'],
'title': track['title'],
'artist': track['mainArtist']['name']
}
}
queueItem['failed'] += 1
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 and no alternative found!"})
return result
else:
logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not found at desired bitrate. Enable fallback to lower bitrates to fix this issue.")
trackCompletePercentage(trackAPI, queueItem, interface)
result['error'] = {
'message': "Track not found at desired bitrate.",
'data': {
'id': track['id'],
'title': track['title'],
'artist': track['mainArtist']['name']
}
} }
} queueItem['failed'] += 1
queueItem['failed'] += 1 queueItem['errors'].append(result['error'])
queueItem['errors'].append(result['error']) if interface:
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 found at desired bitrate."})
'error': "Track not found at desired bitrate."}) return result
return result
elif format == -200: elif format == -200:
logger.error(f"[{track['mainArtist']['name']} - {track['title']}] This track is not available in 360 Reality Audio format. Please select another format.") logger.error(f"[{track['mainArtist']['name']} - {track['title']}] This track is not available in 360 Reality Audio format. Please select another format.")
trackCompletePercentage(trackAPI, queueItem, interface) trackCompletePercentage(trackAPI, queueItem, interface)