Cleaned up duplicate value extrasPath

This commit is contained in:
RemixDev 2021-08-02 20:52:33 +02:00
parent 50b30c03a8
commit 1d1317c135
2 changed files with 15 additions and 18 deletions

View file

@ -208,7 +208,6 @@ class Downloader {
this.bitrate = downloadObject.bitrate this.bitrate = downloadObject.bitrate
this.listener = listener this.listener = listener
this.extrasPath = null
this.playlistCovername = null this.playlistCovername = null
this.playlistURLs = [] this.playlistURLs = []
@ -355,8 +354,7 @@ class Downloader {
let writepath = `${filepath}/${filename}${extension}` let writepath = `${filepath}/${filename}${extension}`
// Save extrasPath // Save extrasPath
if (extrasPath && !this.extrasPath) { if (extrasPath && !this.downloadObject.extrasPath) {
this.extrasPath = extrasPath
this.downloadObject.extrasPath = extrasPath this.downloadObject.extrasPath = extrasPath
} }
@ -502,7 +500,7 @@ class Downloader {
uuid: this.downloadObject.uuid, uuid: this.downloadObject.uuid,
downloaded: true, downloaded: true,
downloadPath: String(writepath), downloadPath: String(writepath),
extrasPath: String(this.extrasPath) extrasPath: String(this.downloadObject.extrasPath)
}) })
returnData.filename = writepath.slice(extrasPath.length+1) returnData.filename = writepath.slice(extrasPath.length+1)
returnData.data = itemData returnData.data = itemData
@ -598,9 +596,8 @@ class Downloader {
async afterDownloadSingle(track){ async afterDownloadSingle(track){
if (!track) return if (!track) return
if (!this.extrasPath) { if (!this.downloadObject.extrasPath) {
this.extrasPath = this.settings.downloadLocation this.downloadObject.extrasPath = this.settings.downloadLocation
this.downloadObject.extrasPath = this.extrasPath
} }
// Save local album artwork // Save local album artwork
@ -618,23 +615,22 @@ class Downloader {
// Create searched logfile // Create searched logfile
if (this.settings.logSearched && track.searched){ if (this.settings.logSearched && track.searched){
let filename = `${track.data.artist} - ${track.data.title}` let filename = `${track.data.artist} - ${track.data.title}`
let searchedFile = fs.readFileSync(`${this.extrasPath}/searched.txt`).toString() let searchedFile = fs.readFileSync(`${this.downloadObject.extrasPath}/searched.txt`).toString()
if (searchedFile.indexOf(filename) == -1){ if (searchedFile.indexOf(filename) == -1){
if (searchedFile != "") searchedFile += "\r\n" if (searchedFile != "") searchedFile += "\r\n"
searchedFile += filename + "\r\n" searchedFile += filename + "\r\n"
fs.writeFileSync(`${this.extrasPath}/searched.txt`, searchedFile) fs.writeFileSync(`${this.downloadObject.extrasPath}/searched.txt`, searchedFile)
} }
} }
// Execute command after download // Execute command after download
if (this.settings.executeCommand !== "") if (this.settings.executeCommand !== "")
exec(this.settings.executeCommand.replaceAll("%folder%", shellEscape(this.extrasPath)).replaceAll("%filename%", shellEscape(track.filename))) exec(this.settings.executeCommand.replaceAll("%folder%", shellEscape(this.downloadObject.extrasPath)).replaceAll("%filename%", shellEscape(track.filename)))
} }
async afterDownloadCollection(tracks){ async afterDownloadCollection(tracks){
if (!this.extrasPath) { if (!this.downloadObject.extrasPath) {
this.extrasPath = this.settings.downloadLocation this.downloadObject.extrasPath = this.settings.downloadLocation
this.downloadObject.extrasPath = this.extrasPath
} }
let playlist = [] let playlist = []
@ -670,27 +666,27 @@ class Downloader {
// Create errors logfile // Create errors logfile
if (this.settings.logErrors && errors != "") if (this.settings.logErrors && errors != "")
fs.writeFileSync(`${this.extrasPath}/errors.txt`, errors) fs.writeFileSync(`${this.downloadObject.extrasPath}/errors.txt`, errors)
// Create searched logfile // Create searched logfile
if (this.settings.logSearched && searched != "") if (this.settings.logSearched && searched != "")
fs.writeFileSync(`${this.extrasPath}/searched.txt`, searched) fs.writeFileSync(`${this.downloadObject.extrasPath}/searched.txt`, searched)
// Save Playlist Artwork // Save Playlist Artwork
if (this.settings.saveArtwork && this.playlistCovername && !this.settings.tags.savePlaylistAsCompilation) if (this.settings.saveArtwork && this.playlistCovername && !this.settings.tags.savePlaylistAsCompilation)
await each(this.playlistURLs, async (image) => { await each(this.playlistURLs, async (image) => {
await downloadImage(image.url, `${this.extrasPath}/${this.playlistCovername}.${image.ext}`, this.settings.overwriteFile) await downloadImage(image.url, `${this.downloadObject.extrasPath}/${this.playlistCovername}.${image.ext}`, this.settings.overwriteFile)
}) })
// Create M3U8 File // Create M3U8 File
if (this.settings.createM3U8File){ if (this.settings.createM3U8File){
let filename = generateDownloadObjectName(this.settings.playlistFilenameTemplate, this.downloadObject, this.settings) || "playlist" let filename = generateDownloadObjectName(this.settings.playlistFilenameTemplate, this.downloadObject, this.settings) || "playlist"
fs.writeFileSync(`${this.extrasPath}/${filename}.m3u8`, playlist.join('\n')) fs.writeFileSync(`${this.downloadObject.extrasPath}/${filename}.m3u8`, playlist.join('\n'))
} }
// Execute command after download // Execute command after download
if (this.settings.executeCommand !== "") if (this.settings.executeCommand !== "")
exec(this.settings.executeCommand.replaceAll("%folder%", shellEscape(this.extrasPath)).replaceAll("%filename%", '')) exec(this.settings.executeCommand.replaceAll("%folder%", shellEscape(this.downloadObject.extrasPath)).replaceAll("%filename%", ''))
} }
} }

View file

@ -13,6 +13,7 @@ class IDownloadObject{
this.progress = obj.progress || 0 this.progress = obj.progress || 0
this.errors = obj.errors || [] this.errors = obj.errors || []
this.files = obj.files || [] this.files = obj.files || []
this.extrasPath = obj.extrasPath || null
this.progressNext = 0 this.progressNext = 0
this.uuid = `${this.type}_${this.id}_${this.bitrate}` this.uuid = `${this.type}_${this.id}_${this.bitrate}`
this.isCanceled = false this.isCanceled = false