added error logging after download

This commit is contained in:
RemixDev 2022-01-11 17:02:19 +01:00
parent 203ec1f10f
commit fc9a205662
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
1 changed files with 99 additions and 42 deletions

View File

@ -504,14 +504,16 @@ class Downloader:
result = {'error': { result = {'error': {
'message': error.message, 'message': error.message,
'errid': error.errid, 'errid': error.errid,
'data': itemData 'data': itemData,
'type': "track"
}} }}
except Exception as e: except Exception as e:
logger.exception("%s %s", f"{itemData['artist']} - {itemData['title']}", e) logger.exception("%s %s", f"{itemData['artist']} - {itemData['title']}", e)
result = {'error': { result = {'error': {
'message': str(e), 'message': str(e),
'data': itemData, 'data': itemData,
'stack': traceback.format_exc() 'stack': traceback.format_exc(),
'type': "track"
}} }}
if 'error' in result: if 'error' in result:
@ -525,25 +527,54 @@ class Downloader:
'failed': True, 'failed': True,
'data': error['data'], 'data': error['data'],
'error': error['message'], 'error': error['message'],
'errid': error['errid'] if 'errid' in error else None, 'errid': error.get('errid'),
'stack': error['stack'] if 'stack' in error else None 'stack': error.get('stack'),
'type': error['type']
}) })
return result return result
def afterDownloadErrorReport(self, position, error, itemData=None):
if not itemData: itemData = {}
data = {'position': position }
data.update(itemData)
logger.exception("%s %s", position, error)
self.downloadObject.errors.append({
'message': str(error),
'stack': traceback.format_exc(),
'data': data,
'type': "post"
})
if self.listener:
self.listener.send("updateQueue", {
'uuid': self.downloadObject.uuid,
'postFailed': True,
'data': data,
'error': str(error),
'stack': traceback.format_exc(),
'type': "post"
})
def afterDownloadSingle(self, track): def afterDownloadSingle(self, track):
if not self.downloadObject.extrasPath: self.downloadObject.extrasPath = Path(self.settings['downloadLocation']) if not self.downloadObject.extrasPath: self.downloadObject.extrasPath = Path(self.settings['downloadLocation'])
# Save Album Cover # Save Album Cover
try:
if self.settings['saveArtwork'] and 'albumPath' in track: if self.settings['saveArtwork'] and 'albumPath' in track:
for image in track['albumURLs']: for image in track['albumURLs']:
downloadImage(image['url'], track['albumPath'] / f"{track['albumFilename']}.{image['ext']}", self.settings['overwriteFile']) downloadImage(image['url'], track['albumPath'] / f"{track['albumFilename']}.{image['ext']}", self.settings['overwriteFile'])
except Exception as e:
self.afterDownloadErrorReport("SaveLocalAlbumArt", e)
# Save Artist Artwork # Save Artist Artwork
try:
if self.settings['saveArtworkArtist'] and 'artistPath' in track: if self.settings['saveArtworkArtist'] and 'artistPath' in track:
for image in track['artistURLs']: for image in track['artistURLs']:
downloadImage(image['url'], track['artistPath'] / f"{track['artistFilename']}.{image['ext']}", self.settings['overwriteFile']) downloadImage(image['url'], track['artistPath'] / f"{track['artistFilename']}.{image['ext']}", self.settings['overwriteFile'])
except Exception as e:
self.afterDownloadErrorReport("SaveLocalArtistArt", e)
# Create searched logfile # Create searched logfile
try:
if self.settings['logSearched'] and 'searched' in track: if self.settings['logSearched'] and 'searched' in track:
filename = f"{track.data.artist} - {track.data.title}" filename = f"{track.data.artist} - {track.data.title}"
with open(self.downloadObject.extrasPath / 'searched.txt', 'w+', encoding="utf-8") as f: with open(self.downloadObject.extrasPath / 'searched.txt', 'w+', encoding="utf-8") as f:
@ -552,10 +583,15 @@ class Downloader:
if searchedFile != "": searchedFile += "\r\n" if searchedFile != "": searchedFile += "\r\n"
searchedFile += filename + "\r\n" searchedFile += filename + "\r\n"
f.write(searchedFile) f.write(searchedFile)
except Exception as e:
self.afterDownloadErrorReport("CreateSearchedLog", e)
# Execute command after download # Execute command after download
try:
if self.settings['executeCommand'] != "": if self.settings['executeCommand'] != "":
execute(self.settings['executeCommand'].replace("%folder%", quote(str(self.downloadObject.extrasPath))).replace("%filename%", quote(track['filename']))) execute(self.settings['executeCommand'].replace("%folder%", quote(str(self.downloadObject.extrasPath))).replace("%filename%", quote(track['filename'])))
except Exception as e:
self.afterDownloadErrorReport("ExecuteCommand", e)
def afterDownloadCollection(self, tracks): def afterDownloadCollection(self, tracks):
if not self.downloadObject.extrasPath: self.downloadObject.extrasPath = Path(self.settings['downloadLocation']) if not self.downloadObject.extrasPath: self.downloadObject.extrasPath = Path(self.settings['downloadLocation'])
@ -576,40 +612,61 @@ class Downloader:
if 'searched' in track: searched += track['searched'] + "\r\n" if 'searched' in track: searched += track['searched'] + "\r\n"
# Save Album Cover # Save Album Cover
try:
if self.settings['saveArtwork'] and 'albumPath' in track: if self.settings['saveArtwork'] and 'albumPath' in track:
for image in track['albumURLs']: for image in track['albumURLs']:
downloadImage(image['url'], track['albumPath'] / f"{track['albumFilename']}.{image['ext']}", self.settings['overwriteFile']) downloadImage(image['url'], track['albumPath'] / f"{track['albumFilename']}.{image['ext']}", self.settings['overwriteFile'])
except Exception as e:
self.afterDownloadErrorReport("SaveLocalAlbumArt", e, track['data'])
# Save Artist Artwork # Save Artist Artwork
try:
if self.settings['saveArtworkArtist'] and 'artistPath' in track: if self.settings['saveArtworkArtist'] and 'artistPath' in track:
for image in track['artistURLs']: for image in track['artistURLs']:
downloadImage(image['url'], track['artistPath'] / f"{track['artistFilename']}.{image['ext']}", self.settings['overwriteFile']) downloadImage(image['url'], track['artistPath'] / f"{track['artistFilename']}.{image['ext']}", self.settings['overwriteFile'])
except Exception as e:
self.afterDownloadErrorReport("SaveLocalArtistArt", e, track['data'])
# Save filename for playlist file # Save filename for playlist file
playlist[i] = track.get('filename', "") playlist[i] = track.get('filename', "")
# Create errors logfile # Create errors logfile
try:
if self.settings['logErrors'] and errors != "": if self.settings['logErrors'] and errors != "":
with open(self.downloadObject.extrasPath / 'errors.txt', 'w', encoding="utf-8") as f: with open(self.downloadObject.extrasPath / 'errors.txt', 'w', encoding="utf-8") as f:
f.write(errors) f.write(errors)
except Exception as e:
self.afterDownloadErrorReport("CreateErrorLog", e)
# Create searched logfile # Create searched logfile
try:
if self.settings['logSearched'] and searched != "": if self.settings['logSearched'] and searched != "":
with open(self.downloadObject.extrasPath / 'searched.txt', 'w', encoding="utf-8") as f: with open(self.downloadObject.extrasPath / 'searched.txt', 'w', encoding="utf-8") as f:
f.write(searched) f.write(searched)
except Exception as e:
self.afterDownloadErrorReport("CreateSearchedLog", e)
# Save Playlist Artwork # Save Playlist Artwork
try:
if self.settings['saveArtwork'] and self.playlistCoverName and not self.settings['tags']['savePlaylistAsCompilation']: if self.settings['saveArtwork'] and self.playlistCoverName and not self.settings['tags']['savePlaylistAsCompilation']:
for image in self.playlistURLs: for image in self.playlistURLs:
downloadImage(image['url'], self.downloadObject.extrasPath / f"{self.playlistCoverName}.{image['ext']}", self.settings['overwriteFile']) downloadImage(image['url'], self.downloadObject.extrasPath / f"{self.playlistCoverName}.{image['ext']}", self.settings['overwriteFile'])
except Exception as e:
self.afterDownloadErrorReport("SavePlaylistArt", e)
# Create M3U8 File # Create M3U8 File
try:
if self.settings['createM3U8File']: if self.settings['createM3U8File']:
filename = generateDownloadObjectName(self.settings['playlistFilenameTemplate'], self.downloadObject, self.settings) or "playlist" filename = generateDownloadObjectName(self.settings['playlistFilenameTemplate'], self.downloadObject, self.settings) or "playlist"
with open(self.downloadObject.extrasPath / f'{filename}.m3u8', 'w', encoding="utf-8") as f: with open(self.downloadObject.extrasPath / f'{filename}.m3u8', 'w', encoding="utf-8") as f:
for line in playlist: for line in playlist:
f.write(line + "\n") f.write(line + "\n")
except Exception as e:
self.afterDownloadErrorReport("CreatePlaylistFile", e)
# Execute command after download # Execute command after download
try:
if self.settings['executeCommand'] != "": if self.settings['executeCommand'] != "":
execute(self.settings['executeCommand'].replace("%folder%", quote(str(self.downloadObject.extrasPath)))) execute(self.settings['executeCommand'].replace("%folder%", quote(str(self.downloadObject.extrasPath))))
except Exception as e:
self.afterDownloadErrorReport("ExecuteCommand", e)