From 0aae672e197d785e10110978b8b1061def8c5514 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 17 Sep 2023 14:53:25 -0500 Subject: [PATCH] Fix:Scanner purge cover cache when extracting from audio file --- server/managers/CoverManager.js | 35 ++------------------------------ server/scanner/BookScanner.js | 4 ++-- server/scanner/PodcastScanner.js | 4 ++-- 3 files changed, 6 insertions(+), 37 deletions(-) diff --git a/server/managers/CoverManager.js b/server/managers/CoverManager.js index 1a83b7cc..cd792428 100644 --- a/server/managers/CoverManager.js +++ b/server/managers/CoverManager.js @@ -229,38 +229,6 @@ class CoverManager { } } - async saveEmbeddedCoverArt(libraryItem) { - let audioFileWithCover = null - if (libraryItem.mediaType === 'book') { - audioFileWithCover = libraryItem.media.audioFiles.find(af => af.embeddedCoverArt) - } else if (libraryItem.mediaType == 'podcast') { - const episodeWithCover = libraryItem.media.episodes.find(ep => ep.audioFile.embeddedCoverArt) - if (episodeWithCover) audioFileWithCover = episodeWithCover.audioFile - } else if (libraryItem.mediaType === 'music') { - audioFileWithCover = libraryItem.media.audioFile - } - if (!audioFileWithCover) return false - - const coverDirPath = this.getCoverDirectory(libraryItem) - await fs.ensureDir(coverDirPath) - - const coverFilename = audioFileWithCover.embeddedCoverArt === 'png' ? 'cover.png' : 'cover.jpg' - const coverFilePath = Path.join(coverDirPath, coverFilename) - - const coverAlreadyExists = await fs.pathExists(coverFilePath) - if (coverAlreadyExists) { - Logger.warn(`[CoverManager] Extract embedded cover art but cover already exists for "${libraryItem.media.metadata.title}" - bail`) - return false - } - - const success = await extractCoverArt(audioFileWithCover.metadata.path, coverFilePath) - if (success) { - libraryItem.updateMediaCover(coverFilePath) - return coverFilePath - } - return false - } - /** * Extract cover art from audio file and save for library item * @param {import('../models/Book').AudioFileObject[]} audioFiles @@ -268,7 +236,7 @@ class CoverManager { * @param {string} [libraryItemPath] null for isFile library items * @returns {Promise} returns cover path */ - async saveEmbeddedCoverArtNew(audioFiles, libraryItemId, libraryItemPath) { + async saveEmbeddedCoverArt(audioFiles, libraryItemId, libraryItemPath) { let audioFileWithCover = audioFiles.find(af => af.embeddedCoverArt) if (!audioFileWithCover) return null @@ -291,6 +259,7 @@ class CoverManager { const success = await extractCoverArt(audioFileWithCover.metadata.path, coverFilePath) if (success) { + await CacheManager.purgeCoverCache(libraryItemId) return coverFilePath } return null diff --git a/server/scanner/BookScanner.js b/server/scanner/BookScanner.js index 190bd69f..c5916b25 100644 --- a/server/scanner/BookScanner.js +++ b/server/scanner/BookScanner.js @@ -313,7 +313,7 @@ class BookScanner { // If no cover then extract cover from audio file if available OR search for cover if enabled in server settings if (!media.coverPath) { const libraryItemDir = existingLibraryItem.isFile ? null : existingLibraryItem.path - const extractedCoverPath = await CoverManager.saveEmbeddedCoverArtNew(media.audioFiles, existingLibraryItem.id, libraryItemDir) + const extractedCoverPath = await CoverManager.saveEmbeddedCoverArt(media.audioFiles, existingLibraryItem.id, libraryItemDir) if (extractedCoverPath) { libraryScan.addLog(LogLevel.DEBUG, `Updating book "${bookMetadata.title}" extracted embedded cover art from audio file to path "${extractedCoverPath}"`) media.coverPath = extractedCoverPath @@ -461,7 +461,7 @@ class BookScanner { if (!bookObject.coverPath) { const libraryItemDir = libraryItemObj.isFile ? null : libraryItemObj.path // Extract and save embedded cover art - const extractedCoverPath = await CoverManager.saveEmbeddedCoverArtNew(scannedAudioFiles, libraryItemObj.id, libraryItemDir) + const extractedCoverPath = await CoverManager.saveEmbeddedCoverArt(scannedAudioFiles, libraryItemObj.id, libraryItemDir) if (extractedCoverPath) { bookObject.coverPath = extractedCoverPath } else if (Database.serverSettings.scannerFindCovers) { diff --git a/server/scanner/PodcastScanner.js b/server/scanner/PodcastScanner.js index 4a80d40a..d5a799cf 100644 --- a/server/scanner/PodcastScanner.js +++ b/server/scanner/PodcastScanner.js @@ -178,7 +178,7 @@ class PodcastScanner { // If no cover then extract cover from audio file if available if (!media.coverPath && existingPodcastEpisodes.length) { const audioFiles = existingPodcastEpisodes.map(ep => ep.audioFile) - const extractedCoverPath = await CoverManager.saveEmbeddedCoverArtNew(audioFiles, existingLibraryItem.id, existingLibraryItem.path) + const extractedCoverPath = await CoverManager.saveEmbeddedCoverArt(audioFiles, existingLibraryItem.id, existingLibraryItem.path) if (extractedCoverPath) { libraryScan.addLog(LogLevel.DEBUG, `Updating podcast "${podcastMetadata.title}" extracted embedded cover art from audio file to path "${extractedCoverPath}"`) media.coverPath = extractedCoverPath @@ -279,7 +279,7 @@ class PodcastScanner { // If cover was not found in folder then check embedded covers in audio files if (!podcastObject.coverPath && scannedAudioFiles.length) { // Extract and save embedded cover art - podcastObject.coverPath = await CoverManager.saveEmbeddedCoverArtNew(scannedAudioFiles, libraryItemObj.id, libraryItemObj.path) + podcastObject.coverPath = await CoverManager.saveEmbeddedCoverArt(scannedAudioFiles, libraryItemObj.id, libraryItemObj.path) } libraryItemObj.podcast = podcastObject