Skip to content

Commit

Permalink
Embed track number
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Jul 1, 2024
1 parent a21b1f3 commit 4732ca8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/managers/AudioMetadataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`)
}
Expand Down
7 changes: 6 additions & 1 deletion server/utils/ffmpegHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
Expand Down

0 comments on commit 4732ca8

Please sign in to comment.