Added check for generic error and auto retry

This fixes #25
This commit is contained in:
RemixDev 2020-06-12 10:48:07 +02:00
parent be93716993
commit fa6d1d8b74
1 changed files with 57 additions and 47 deletions

View File

@ -735,6 +735,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
trackAlreadyDownloaded = os.path.isfile(writepath)
if not trackAlreadyDownloaded or settings['overwriteFile'] == 'y':
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Downloading the track")
def downloadMusic(dz, track, trackAPI, queueItem, interface, writepath, result, settings):
try:
with open(writepath, 'wb') as stream:
stream_track(dz, track, stream, trackAPI, queueItem, interface)
@ -742,7 +743,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
except downloadCancelled:
remove(writepath)
result['cancel'] = True
return result
return 1
except HTTPError:
remove(writepath)
if track['fallbackId'] != 0:
@ -751,7 +752,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
if not 'MD5_ORIGIN' in trackNew:
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
track = parseEssentialTrackData(track, trackNew)
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
return 2
elif not 'searched' in track and settings['fallbackSearch']:
logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Track not available, searching for alternative")
searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'],
@ -762,8 +763,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
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)
return 2
else:
logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not available on deezer's servers and no alternative found!")
trackCompletePercentage(trackAPI, queueItem, interface)
@ -780,7 +780,7 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
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!"})
return result
return 1
else:
logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not available on deezer's servers!")
trackCompletePercentage(trackAPI, queueItem, interface)
@ -797,7 +797,17 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
if interface:
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
'error': "Track not available on deezer's servers!"})
return 1
except:
logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Error while downloading the track, trying again in 5s...")
sleep(5)
return downloadMusic(dz, track, trackAPI, queueItem, interface, writepath, result, settings)
return 0
outcome = downloadMusic(dz, track, trackAPI, queueItem, interface, writepath, result, settings)
if outcome == 1:
return result
elif outcome == 2:
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
else:
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Skipping track as it's already downloaded")
trackCompletePercentage(trackAPI, queueItem, interface)