mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-03-14 00:21:31 +01:00
Merge pull request #682 from jmt-gh/update_cover_on_merge
Support embedding cover art metadata in the embed metadata tool
This commit is contained in:
commit
b671145e73
@ -32,9 +32,13 @@ class AudioMetadataMangaer {
|
||||
var metadataFilePath = Path.join(outputDir, 'metadata.txt')
|
||||
await writeMetadataFile(libraryItem, metadataFilePath)
|
||||
|
||||
if (libraryItem.media.coverPath != null) {
|
||||
var coverPath = libraryItem.media.coverPath.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
// TODO: Split into batches
|
||||
const proms = audioFiles.map(af => {
|
||||
return this.updateAudioFileMetadata(libraryItem.id, af, outputDir, metadataFilePath)
|
||||
return this.updateAudioFileMetadata(libraryItem.id, af, outputDir, metadataFilePath, coverPath)
|
||||
})
|
||||
|
||||
const results = await Promise.all(proms)
|
||||
@ -51,7 +55,7 @@ class AudioMetadataMangaer {
|
||||
this.emitter('audio_metadata_finished', itemAudioMetadataPayload)
|
||||
}
|
||||
|
||||
updateAudioFileMetadata(libraryItemId, audioFile, outputDir, metadataFilePath) {
|
||||
updateAudioFileMetadata(libraryItemId, audioFile, outputDir, metadataFilePath, coverPath = '') {
|
||||
return new Promise((resolve) => {
|
||||
const resultPayload = {
|
||||
libraryItemId,
|
||||
@ -85,6 +89,32 @@ class AudioMetadataMangaer {
|
||||
*/
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user