From 4732ca811942be63b7dd2e6bafcc45291f5fb75a Mon Sep 17 00:00:00 2001 From: advplyr Date: Mon, 1 Jul 2024 16:57:14 -0500 Subject: [PATCH] Embed track number --- server/managers/AudioMetadataManager.js | 2 +- server/utils/ffmpegHelpers.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/server/managers/AudioMetadataManager.js b/server/managers/AudioMetadataManager.js index b9133de8..4d90b5df 100644 --- a/server/managers/AudioMetadataManager.js +++ b/server/managers/AudioMetadataManager.js @@ -138,7 +138,7 @@ class AudioMetadataMangaer { } } - const success = await ffmpegHelpers.addCoverAndMetadataToFile(af.path, task.data.coverPath, ffmetadataPath, task.data.mimeType) + const success = await ffmpegHelpers.addCoverAndMetadataToFile(af.path, task.data.coverPath, ffmetadataPath, af.index, task.data.mimeType) if (success) { Logger.info(`[AudioMetadataManager] Successfully tagged audio file "${af.path}"`) } diff --git a/server/utils/ffmpegHelpers.js b/server/utils/ffmpegHelpers.js index c9cddbf4..ef41b46d 100644 --- a/server/utils/ffmpegHelpers.js +++ b/server/utils/ffmpegHelpers.js @@ -225,9 +225,10 @@ module.exports.generateFFMetadata = generateFFMetadata * @param {string} audioFilePath - Path to the input audio file. * @param {string|null} coverFilePath - Path to the cover image file. * @param {string} metadataFilePath - Path to the ffmetadata file. + * @param {number} track - The track number to embed in the audio file. * @param {string} mimeType - The MIME type of the audio file. */ -async function addCoverAndMetadataToFile(audioFilePath, coverFilePath, metadataFilePath, mimeType) { +async function addCoverAndMetadataToFile(audioFilePath, coverFilePath, metadataFilePath, track, mimeType) { const isMp4 = mimeType === 'audio/mp4' const isMp3 = mimeType === 'audio/mpeg' @@ -246,6 +247,10 @@ async function addCoverAndMetadataToFile(audioFilePath, coverFilePath, metadataF '-c copy' // copy streams ]) + if (track && !isNaN(track)) { + ffmpeg.outputOptions(['-metadata track=' + track]) + } + if (isMp4) { ffmpeg.outputOptions([ '-f mp4' // force output format to mp4