mirror of
https://gitlab.com/RemixDev/deemix-py.git
synced 2024-12-28 02:26:14 +00:00
added error logging after download
This commit is contained in:
parent
203ec1f10f
commit
fc9a205662
|
@ -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,37 +527,71 @@ 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
|
||||||
if self.settings['saveArtwork'] and 'albumPath' in track:
|
try:
|
||||||
for image in track['albumURLs']:
|
if self.settings['saveArtwork'] and 'albumPath' in track:
|
||||||
downloadImage(image['url'], track['albumPath'] / f"{track['albumFilename']}.{image['ext']}", self.settings['overwriteFile'])
|
for image in track['albumURLs']:
|
||||||
|
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
|
||||||
if self.settings['saveArtworkArtist'] and 'artistPath' in track:
|
try:
|
||||||
for image in track['artistURLs']:
|
if self.settings['saveArtworkArtist'] and 'artistPath' in track:
|
||||||
downloadImage(image['url'], track['artistPath'] / f"{track['artistFilename']}.{image['ext']}", self.settings['overwriteFile'])
|
for image in track['artistURLs']:
|
||||||
|
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
|
||||||
if self.settings['logSearched'] and 'searched' in track:
|
try:
|
||||||
filename = f"{track.data.artist} - {track.data.title}"
|
if self.settings['logSearched'] and 'searched' in track:
|
||||||
with open(self.downloadObject.extrasPath / 'searched.txt', 'w+', encoding="utf-8") as f:
|
filename = f"{track.data.artist} - {track.data.title}"
|
||||||
searchedFile = f.read()
|
with open(self.downloadObject.extrasPath / 'searched.txt', 'w+', encoding="utf-8") as f:
|
||||||
if not filename in searchedFile:
|
searchedFile = f.read()
|
||||||
if searchedFile != "": searchedFile += "\r\n"
|
if not filename in searchedFile:
|
||||||
searchedFile += filename + "\r\n"
|
if searchedFile != "": searchedFile += "\r\n"
|
||||||
f.write(searchedFile)
|
searchedFile += filename + "\r\n"
|
||||||
|
f.write(searchedFile)
|
||||||
|
except Exception as e:
|
||||||
|
self.afterDownloadErrorReport("CreateSearchedLog", e)
|
||||||
|
|
||||||
# Execute command after download
|
# Execute command after download
|
||||||
if self.settings['executeCommand'] != "":
|
try:
|
||||||
execute(self.settings['executeCommand'].replace("%folder%", quote(str(self.downloadObject.extrasPath))).replace("%filename%", quote(track['filename'])))
|
if self.settings['executeCommand'] != "":
|
||||||
|
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
|
||||||
if self.settings['saveArtwork'] and 'albumPath' in track:
|
try:
|
||||||
for image in track['albumURLs']:
|
if self.settings['saveArtwork'] and 'albumPath' in track:
|
||||||
downloadImage(image['url'], track['albumPath'] / f"{track['albumFilename']}.{image['ext']}", self.settings['overwriteFile'])
|
for image in track['albumURLs']:
|
||||||
|
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
|
||||||
if self.settings['saveArtworkArtist'] and 'artistPath' in track:
|
try:
|
||||||
for image in track['artistURLs']:
|
if self.settings['saveArtworkArtist'] and 'artistPath' in track:
|
||||||
downloadImage(image['url'], track['artistPath'] / f"{track['artistFilename']}.{image['ext']}", self.settings['overwriteFile'])
|
for image in track['artistURLs']:
|
||||||
|
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
|
||||||
if self.settings['logErrors'] and errors != "":
|
try:
|
||||||
with open(self.downloadObject.extrasPath / 'errors.txt', 'w', encoding="utf-8") as f:
|
if self.settings['logErrors'] and errors != "":
|
||||||
f.write(errors)
|
with open(self.downloadObject.extrasPath / 'errors.txt', 'w', encoding="utf-8") as f:
|
||||||
|
f.write(errors)
|
||||||
|
except Exception as e:
|
||||||
|
self.afterDownloadErrorReport("CreateErrorLog", e)
|
||||||
|
|
||||||
# Create searched logfile
|
# Create searched logfile
|
||||||
if self.settings['logSearched'] and searched != "":
|
try:
|
||||||
with open(self.downloadObject.extrasPath / 'searched.txt', 'w', encoding="utf-8") as f:
|
if self.settings['logSearched'] and searched != "":
|
||||||
f.write(searched)
|
with open(self.downloadObject.extrasPath / 'searched.txt', 'w', encoding="utf-8") as f:
|
||||||
|
f.write(searched)
|
||||||
|
except Exception as e:
|
||||||
|
self.afterDownloadErrorReport("CreateSearchedLog", e)
|
||||||
|
|
||||||
# Save Playlist Artwork
|
# Save Playlist Artwork
|
||||||
if self.settings['saveArtwork'] and self.playlistCoverName and not self.settings['tags']['savePlaylistAsCompilation']:
|
try:
|
||||||
for image in self.playlistURLs:
|
if self.settings['saveArtwork'] and self.playlistCoverName and not self.settings['tags']['savePlaylistAsCompilation']:
|
||||||
downloadImage(image['url'], self.downloadObject.extrasPath / f"{self.playlistCoverName}.{image['ext']}", self.settings['overwriteFile'])
|
for image in self.playlistURLs:
|
||||||
|
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
|
||||||
if self.settings['createM3U8File']:
|
try:
|
||||||
filename = generateDownloadObjectName(self.settings['playlistFilenameTemplate'], self.downloadObject, self.settings) or "playlist"
|
if self.settings['createM3U8File']:
|
||||||
with open(self.downloadObject.extrasPath / f'{filename}.m3u8', 'w', encoding="utf-8") as f:
|
filename = generateDownloadObjectName(self.settings['playlistFilenameTemplate'], self.downloadObject, self.settings) or "playlist"
|
||||||
for line in playlist:
|
with open(self.downloadObject.extrasPath / f'{filename}.m3u8', 'w', encoding="utf-8") as f:
|
||||||
f.write(line + "\n")
|
for line in playlist:
|
||||||
|
f.write(line + "\n")
|
||||||
|
except Exception as e:
|
||||||
|
self.afterDownloadErrorReport("CreatePlaylistFile", e)
|
||||||
|
|
||||||
# Execute command after download
|
# Execute command after download
|
||||||
if self.settings['executeCommand'] != "":
|
try:
|
||||||
execute(self.settings['executeCommand'].replace("%folder%", quote(str(self.downloadObject.extrasPath))))
|
if self.settings['executeCommand'] != "":
|
||||||
|
execute(self.settings['executeCommand'].replace("%folder%", quote(str(self.downloadObject.extrasPath))))
|
||||||
|
except Exception as e:
|
||||||
|
self.afterDownloadErrorReport("ExecuteCommand", e)
|
||||||
|
|
Loading…
Reference in a new issue