From 8809c7b900b87655adaea5d1d457da2a1fb4f6bf Mon Sep 17 00:00:00 2001 From: jmt-gh Date: Sun, 5 Jun 2022 10:36:42 -0700 Subject: [PATCH] Handle null and delete cover cases This commit adds in supporting if a cover path is null. If this is the case, we completely remove the video stream from the file, as the user either: a) uploaded a file with no video stream (so removing it is a no-op) b) removed the cover in ABS, so we should respect that on merge --- server/managers/AudioMetadataManager.js | 38 ++++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/server/managers/AudioMetadataManager.js b/server/managers/AudioMetadataManager.js index 34deaf8a..1c862dd2 100644 --- a/server/managers/AudioMetadataManager.js +++ b/server/managers/AudioMetadataManager.js @@ -32,7 +32,9 @@ class AudioMetadataMangaer { var metadataFilePath = Path.join(outputDir, 'metadata.txt') await writeMetadataFile(libraryItem, metadataFilePath) - var coverPath = libraryItem.media.coverPath.replace(/\\/g, '/') + if (libraryItem.media.coverPath != null) { + var coverPath = libraryItem.media.coverPath.replace(/\\/g, '/') + } // TODO: Split into batches const proms = audioFiles.map(af => { @@ -53,7 +55,7 @@ class AudioMetadataMangaer { this.emitter('audio_metadata_finished', itemAudioMetadataPayload) } - updateAudioFileMetadata(libraryItemId, audioFile, outputDir, metadataFilePath, coverPath) { + updateAudioFileMetadata(libraryItemId, audioFile, outputDir, metadataFilePath, coverPath = '') { return new Promise((resolve) => { const resultPayload = { libraryItemId, @@ -75,10 +77,6 @@ class AudioMetadataMangaer { }, { input: metadataFilePath - }, - { - input: coverPath, - options: ['-f image2pipe'] } ] @@ -90,7 +88,33 @@ class AudioMetadataMangaer { Ffmpeg premapped id3 tags: https://wiki.multimedia.cx/index.php/FFmpeg_Metadata */ - const ffmpegOptions = ['-c copy', '-map_chapters 1', '-map_metadata 1', `-metadata track=${audioFile.index}`, '-write_id3v2 1', '-movflags use_metadata_tags', '-c:v copy', '-map 2:v', '-map 0:a'] + const ffmpegOptions = ['-c copy', '-map_chapters 1', '-map_metadata 1', `-metadata track=${audioFile.index}`, '-write_id3v2 1', '-movflags use_metadata_tags'] + + if (coverPath != '') { + var ffmpegCoverPathInput = { + input: coverPath, + options: ['-f image2pipe'] + } + var ffmpegCoverPathOptions = [ + '-c:v copy', + '-map 2:v', + '-map 0:a' + ] + + ffmpegInputs.push(ffmpegCoverPathInput) + Logger.debug(`[AudioFileMetaDataManager] Cover found for "${audioFile.metadata.filename}". Cover will be merged to metadata`) + } else { + // remove the video stream to account for the user getting rid an existing cover in abs + var ffmpegCoverPathOptions = [ + '-map 0', + '-map -0:v' + ] + + Logger.debug(`[AudioFileMetaDataManager] No cover found for "${audioFile.metadata.filename}". Cover will be skipped or removed from metadata`) + } + + ffmpegOptions.push(...ffmpegCoverPathOptions) + var workerData = { inputs: ffmpegInputs, options: ffmpegOptions,