added error logging after download

This commit is contained in:
RemixDev 2022-01-06 14:33:42 +01:00
parent a68af85f2e
commit a82b674cb3
No known key found for this signature in database
GPG key ID: B33962B465BDB51C

View file

@ -579,7 +579,8 @@ class Downloader {
result = {error:{ result = {error:{
message: e.message, message: e.message,
errid: e.errid, errid: e.errid,
data: itemData data: itemData,
type: "track"
}} }}
} else if (e instanceof DownloadCanceled){ } else if (e instanceof DownloadCanceled){
return return
@ -588,7 +589,8 @@ class Downloader {
result = {error:{ result = {error:{
message: e.message, message: e.message,
data: itemData, data: itemData,
stack: String(e.stack) stack: String(e.stack),
type: "track"
}} }}
} }
} }
@ -605,13 +607,34 @@ class Downloader {
data: error.data, data: error.data,
error: error.message, error: error.message,
errid: error.errid || null, errid: error.errid || null,
stack: error.stack || null stack: error.stack || null,
type: error.type
}) })
} }
} }
return result return result
} }
afterDownloadErrorReport(position, error, itemData = {}){
console.trace(error)
this.downloadObject.errors.push({
message: error.message,
stack: String(error.stack),
data: { position, ...itemData },
type: "post"
})
if (this.listener){
this.listener.send("updateQueue", {
uuid: this.downloadObject.uuid,
postFailed: true,
error: error.message,
data: { position, ...itemData },
stack: error.stack,
type: "post"
})
}
}
async afterDownloadSingle(track){ async afterDownloadSingle(track){
if (!track) return if (!track) return
if (!this.downloadObject.extrasPath) { if (!this.downloadObject.extrasPath) {
@ -619,31 +642,47 @@ class Downloader {
} }
// Save local album artwork // Save local album artwork
if (this.settings.saveArtwork && track.albumPath) try {
await each(track.albumURLs, async (image) => { if (this.settings.saveArtwork && track.albumPath)
await downloadImage(image.url, `${track.albumPath}/${track.albumFilename}.${image.ext}`, this.settings.overwriteFile) await each(track.albumURLs, async (image) => {
}) await downloadImage(image.url, `${track.albumPath}/${track.albumFilename}.${image.ext}`, this.settings.overwriteFile)
})
} catch (e){
this.afterDownloadErrorReport("SaveLocalAlbumArt", e)
}
// Save local artist artwork // Save local artist artwork
if (this.settings.saveArtworkArtist && track.artistPath) try {
await each(track.artistURLs, async (image) => { if (this.settings.saveArtworkArtist && track.artistPath)
await downloadImage(image.url, `${track.artistPath}/${track.artistFilename}.${image.ext}`, this.settings.overwriteFile) await each(track.artistURLs, async (image) => {
}) await downloadImage(image.url, `${track.artistPath}/${track.artistFilename}.${image.ext}`, this.settings.overwriteFile)
})
} catch (e){
this.afterDownloadErrorReport("SaveLocalArtistArt", e)
}
// Create searched logfile // Create searched logfile
if (this.settings.logSearched && track.searched){ try {
let filename = `${track.data.artist} - ${track.data.title}` if (this.settings.logSearched && track.searched){
let searchedFile = fs.readFileSync(`${this.downloadObject.extrasPath}/searched.txt`).toString() let filename = `${track.data.artist} - ${track.data.title}`
if (searchedFile.indexOf(filename) == -1){ let searchedFile = fs.readFileSync(`${this.downloadObject.extrasPath}/searched.txt`).toString()
if (searchedFile != "") searchedFile += "\r\n" if (searchedFile.indexOf(filename) == -1){
searchedFile += filename + "\r\n" if (searchedFile != "") searchedFile += "\r\n"
fs.writeFileSync(`${this.downloadObject.extrasPath}/searched.txt`, searchedFile) searchedFile += filename + "\r\n"
fs.writeFileSync(`${this.downloadObject.extrasPath}/searched.txt`, searchedFile)
}
} }
} catch (e){
this.afterDownloadErrorReport("CreateSearchedLog", e)
} }
// Execute command after download // Execute command after download
if (this.settings.executeCommand !== "") try {
exec(this.settings.executeCommand.replaceAll("%folder%", shellEscape(this.downloadObject.extrasPath)).replaceAll("%filename%", shellEscape(track.filename))) if (this.settings.executeCommand !== "")
exec(this.settings.executeCommand.replaceAll("%folder%", shellEscape(this.downloadObject.extrasPath)).replaceAll("%filename%", shellEscape(track.filename)))
} catch (e){
this.afterDownloadErrorReport("ExecuteCommand", e)
}
} }
async afterDownloadCollection(tracks){ async afterDownloadCollection(tracks){
@ -667,44 +706,72 @@ class Downloader {
if (track.searched) searched += `${track.data.artist} - ${track.data.title}\r\n` if (track.searched) searched += `${track.data.artist} - ${track.data.title}\r\n`
// Save local album artwork // Save local album artwork
if (this.settings.saveArtwork && track.albumPath) try{
await each(track.albumURLs, async (image) => { if (this.settings.saveArtwork && track.albumPath)
await downloadImage(image.url, `${track.albumPath}/${track.albumFilename}.${image.ext}`, this.settings.overwriteFile) await each(track.albumURLs, async (image) => {
}) await downloadImage(image.url, `${track.albumPath}/${track.albumFilename}.${image.ext}`, this.settings.overwriteFile)
})
} catch (e){
this.afterDownloadErrorReport("SaveLocalAlbumArt", e, track.data)
}
// Save local artist artwork // Save local artist artwork
if (this.settings.saveArtworkArtist && track.artistPath) try{
await each(track.artistURLs, async (image) => { if (this.settings.saveArtworkArtist && track.artistPath)
await downloadImage(image.url, `${track.artistPath}/${track.artistFilename}.${image.ext}`, this.settings.overwriteFile) await each(track.artistURLs, async (image) => {
}) await downloadImage(image.url, `${track.artistPath}/${track.artistFilename}.${image.ext}`, this.settings.overwriteFile)
})
} catch (e){
this.afterDownloadErrorReport("SaveLocalArtistArt", e, track.data)
}
// Save filename for playlist file // Save filename for playlist file
playlist[i] = track.filename || "" playlist[i] = track.filename || ""
} }
// Create errors logfile // Create errors logfile
if (this.settings.logErrors && errors != "") try{
fs.writeFileSync(`${this.downloadObject.extrasPath}/errors.txt`, errors) if (this.settings.logErrors && errors != "")
fs.writeFileSync(`${this.downloadObject.extrasPath}/errors.txt`, errors)
} catch (e){
this.afterDownloadErrorReport("CreateErrorLog", e)
}
// Create searched logfile // Create searched logfile
if (this.settings.logSearched && searched != "") try{
fs.writeFileSync(`${this.downloadObject.extrasPath}/searched.txt`, searched) if (this.settings.logSearched && searched != "")
fs.writeFileSync(`${this.downloadObject.extrasPath}/searched.txt`, searched)
} catch (e){
this.afterDownloadErrorReport("CreateSearchedLog", e)
}
// Save Playlist Artwork // Save Playlist Artwork
if (this.settings.saveArtwork && this.playlistCovername && !this.settings.tags.savePlaylistAsCompilation) try{
await each(this.playlistURLs, async (image) => { if (this.settings.saveArtwork && this.playlistCovername && !this.settings.tags.savePlaylistAsCompilation)
await downloadImage(image.url, `${this.downloadObject.extrasPath}/${this.playlistCovername}.${image.ext}`, this.settings.overwriteFile) await each(this.playlistURLs, async (image) => {
}) await downloadImage(image.url, `${this.downloadObject.extrasPath}/${this.playlistCovername}.${image.ext}`, this.settings.overwriteFile)
})
} catch (e){
this.afterDownloadErrorReport("SavePlaylistArt", e)
}
// Create M3U8 File // Create M3U8 File
if (this.settings.createM3U8File){ try{
let filename = generateDownloadObjectName(this.settings.playlistFilenameTemplate, this.downloadObject, this.settings) || "playlist" if (this.settings.createM3U8File){
fs.writeFileSync(`${this.downloadObject.extrasPath}/${filename}.m3u8`, playlist.join('\n')) let filename = generateDownloadObjectName(this.settings.playlistFilenameTemplate, this.downloadObject, this.settings) || "playlist"
fs.writeFileSync(`${this.downloadObject.extrasPath}/${filename}.m3u8`, playlist.join('\n'))
}
} catch (e){
this.afterDownloadErrorReport("CreatePlaylistFile", e)
} }
// Execute command after download // Execute command after download
if (this.settings.executeCommand !== "") try{
exec(this.settings.executeCommand.replaceAll("%folder%", shellEscape(this.downloadObject.extrasPath)).replaceAll("%filename%", '')) if (this.settings.executeCommand !== "")
exec(this.settings.executeCommand.replaceAll("%folder%", shellEscape(this.downloadObject.extrasPath)).replaceAll("%filename%", ''))
} catch (e){
this.afterDownloadErrorReport("ExecuteCommand", e)
}
} }
} }