Added check if file exsists before removing

This commit is contained in:
RemixDev 2020-09-16 21:38:24 +02:00
parent e8d2bb9915
commit 9773076af3
1 changed files with 6 additions and 6 deletions

View File

@ -460,10 +460,10 @@ class DownloadJob:
with open(writepath, 'wb') as stream: with open(writepath, 'wb') as stream:
self.streamTrack(stream, track) self.streamTrack(stream, track)
except DownloadCancelled: except DownloadCancelled:
remove(writepath) if os.path.isfile(writepath): remove(writepath)
raise DownloadCancelled raise DownloadCancelled
except (request_exception.HTTPError, DownloadEmpty): except (request_exception.HTTPError, DownloadEmpty):
remove(writepath) if os.path.isfile(writepath): remove(writepath)
if track.fallbackId != "0": if track.fallbackId != "0":
logger.warn(f"[{track.mainArtist['name']} - {track.title}] Track not available, using fallback id") logger.warn(f"[{track.mainArtist['name']} - {track.title}] Track not available, using fallback id")
newTrack = self.dz.get_track_gw(track.fallbackId) newTrack = self.dz.get_track_gw(track.fallbackId)
@ -482,7 +482,7 @@ class DownloadJob:
else: else:
raise DownloadFailed("notAvailable") raise DownloadFailed("notAvailable")
except (request_exception.ConnectionError, request_exception.ChunkedEncodingError) as e: except (request_exception.ConnectionError, request_exception.ChunkedEncodingError) as e:
remove(writepath) if os.path.isfile(writepath): remove(writepath)
logger.warn(f"[{track.mainArtist['name']} - {track.title}] Error while downloading the track, trying again in 5s...") logger.warn(f"[{track.mainArtist['name']} - {track.title}] Error while downloading the track, trying again in 5s...")
eventlet.sleep(5) eventlet.sleep(5)
return downloadMusic(track, trackAPI_gw) return downloadMusic(track, trackAPI_gw)
@ -490,11 +490,11 @@ class DownloadJob:
if e.errno == errno.ENOSPC: if e.errno == errno.ENOSPC:
raise DownloadFailed("noSpaceLeft") raise DownloadFailed("noSpaceLeft")
else: else:
remove(writepath) if os.path.isfile(writepath): remove(writepath)
logger.exception(f"[{track.mainArtist['name']} - {track.title}] Error while downloading the track, you should report this to the developers: {str(e)}") logger.exception(f"[{track.mainArtist['name']} - {track.title}] Error while downloading the track, you should report this to the developers: {str(e)}")
raise e raise e
except Exception as e: except Exception as e:
remove(writepath) if os.path.isfile(writepath): remove(writepath)
logger.exception(f"[{track.mainArtist['name']} - {track.title}] Error while downloading the track, you should report this to the developers: {str(e)}") logger.exception(f"[{track.mainArtist['name']} - {track.title}] Error while downloading the track, you should report this to the developers: {str(e)}")
raise e raise e
return True return True
@ -521,7 +521,7 @@ class DownloadJob:
try: try:
tagFLAC(writepath, track, self.settings['tags']) tagFLAC(writepath, track, self.settings['tags'])
except FLACNoHeaderError: except FLACNoHeaderError:
remove(writepath) if os.path.isfile(writepath): remove(writepath)
logger.warn(f"[{track.mainArtist['name']} - {track.title}] Track not available in FLAC, falling back if necessary") logger.warn(f"[{track.mainArtist['name']} - {track.title}] Track not available in FLAC, falling back if necessary")
self.removeTrackPercentage() self.removeTrackPercentage()
track.filesizes['FILESIZE_FLAC'] = "0" track.filesizes['FILESIZE_FLAC'] = "0"