mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-05 08:51:33 +00:00
Revert ASIN changes - moved to separate PR #4959
This commit is contained in:
parent
194f0189fc
commit
47f6f4e18a
2 changed files with 12 additions and 13 deletions
|
|
@ -295,18 +295,19 @@ module.exports.writeFFMetadataFile = writeFFMetadataFile
|
||||||
* @returns {Promise<void>} A promise that resolves if the operation is successful, rejects otherwise.
|
* @returns {Promise<void>} A promise that resolves if the operation is successful, rejects otherwise.
|
||||||
*/
|
*/
|
||||||
async function addCoverAndMetadataToFile(audioFilePath, coverFilePath, metadataFilePath, track, mimeType, progressCB = null, ffmpeg = Ffmpeg(), copyFunc = copyToExisting) {
|
async function addCoverAndMetadataToFile(audioFilePath, coverFilePath, metadataFilePath, track, mimeType, progressCB = null, ffmpeg = Ffmpeg(), copyFunc = copyToExisting) {
|
||||||
|
const isMp4 = mimeType === 'audio/mp4'
|
||||||
|
const isMp3 = mimeType === 'audio/mpeg'
|
||||||
|
|
||||||
const audioFileDir = Path.dirname(audioFilePath)
|
const audioFileDir = Path.dirname(audioFilePath)
|
||||||
const audioFileExt = Path.extname(audioFilePath)
|
const audioFileExt = Path.extname(audioFilePath)
|
||||||
const audioFileBaseName = Path.basename(audioFilePath, audioFileExt)
|
const audioFileBaseName = Path.basename(audioFilePath, audioFileExt)
|
||||||
const tempFilePath = filePathToPOSIX(Path.join(audioFileDir, `${audioFileBaseName}.tmp${audioFileExt}`))
|
const tempFilePath = filePathToPOSIX(Path.join(audioFileDir, `${audioFileBaseName}.tmp${audioFileExt}`))
|
||||||
|
|
||||||
const isMp4 = mimeType === 'audio/mp4' || audioFileExt.toLowerCase() === '.m4b'
|
|
||||||
const isMp3 = mimeType === 'audio/mpeg'
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ffmpeg.input(audioFilePath).input(metadataFilePath).outputOptions([
|
ffmpeg.input(audioFilePath).input(metadataFilePath).outputOptions([
|
||||||
'-map 0:a', // map audio stream from input file
|
'-map 0:a', // map audio stream from input file
|
||||||
'-map_metadata 1', // map metadata tags from metadata file (contains all desired metadata)
|
'-map_metadata 1', // map metadata tags from metadata file first
|
||||||
|
'-map_metadata 0', // add additional metadata tags from input file
|
||||||
'-map_chapters 1', // map chapters from metadata file
|
'-map_chapters 1', // map chapters from metadata file
|
||||||
'-c copy' // copy streams
|
'-c copy' // copy streams
|
||||||
])
|
])
|
||||||
|
|
@ -317,8 +318,7 @@ async function addCoverAndMetadataToFile(audioFilePath, coverFilePath, metadataF
|
||||||
|
|
||||||
if (isMp4) {
|
if (isMp4) {
|
||||||
ffmpeg.outputOptions([
|
ffmpeg.outputOptions([
|
||||||
'-f mp4', // force output format to mp4
|
'-f mp4' // force output format to mp4
|
||||||
'-movflags use_metadata_tags' // preserve custom tags like AUDIBLE_ASIN
|
|
||||||
])
|
])
|
||||||
} else if (isMp3) {
|
} else if (isMp3) {
|
||||||
ffmpeg.outputOptions([
|
ffmpeg.outputOptions([
|
||||||
|
|
@ -414,8 +414,7 @@ function getFFMetadataObject(libraryItem, audioFilesLength) {
|
||||||
copyright: libraryItem.media.publisher,
|
copyright: libraryItem.media.publisher,
|
||||||
publisher: libraryItem.media.publisher, // mp3 only
|
publisher: libraryItem.media.publisher, // mp3 only
|
||||||
TRACKTOTAL: `${audioFilesLength}`, // mp3 only
|
TRACKTOTAL: `${audioFilesLength}`, // mp3 only
|
||||||
grouping: libraryItem.media.series?.map((s) => s.name + (s.bookSeries.sequence ? ` #${s.bookSeries.sequence}` : '')).join('; '),
|
grouping: libraryItem.media.series?.map((s) => s.name + (s.bookSeries.sequence ? ` #${s.bookSeries.sequence}` : '')).join('; ')
|
||||||
AUDIBLE_ASIN: libraryItem.media.asin // Audible ASIN tag for m4b/mp4 files
|
|
||||||
}
|
}
|
||||||
Object.keys(ffmetadata).forEach((key) => {
|
Object.keys(ffmetadata).forEach((key) => {
|
||||||
if (!ffmetadata[key]) {
|
if (!ffmetadata[key]) {
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ describe('addCoverAndMetadataToFile', () => {
|
||||||
expect(ffmpegStub.input.getCall(2).args[0]).to.equal(coverFilePath)
|
expect(ffmpegStub.input.getCall(2).args[0]).to.equal(coverFilePath)
|
||||||
|
|
||||||
expect(ffmpegStub.outputOptions.callCount).to.equal(4)
|
expect(ffmpegStub.outputOptions.callCount).to.equal(4)
|
||||||
expect(ffmpegStub.outputOptions.getCall(0).args[0]).to.deep.equal(['-map 0:a', '-map_metadata 1', '-map_chapters 1', '-c copy'])
|
expect(ffmpegStub.outputOptions.getCall(0).args[0]).to.deep.equal(['-map 0:a', '-map_metadata 1', '-map_metadata 0', '-map_chapters 1', '-c copy'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(1).args[0]).to.deep.equal(['-metadata track=1'])
|
expect(ffmpegStub.outputOptions.getCall(1).args[0]).to.deep.equal(['-metadata track=1'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(2).args[0]).to.deep.equal(['-id3v2_version 3'])
|
expect(ffmpegStub.outputOptions.getCall(2).args[0]).to.deep.equal(['-id3v2_version 3'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(3).args[0]).to.deep.equal(['-map 2:v', '-disposition:v:0 attached_pic', '-metadata:s:v', 'title=Cover', '-metadata:s:v', 'comment=Cover'])
|
expect(ffmpegStub.outputOptions.getCall(3).args[0]).to.deep.equal(['-map 2:v', '-disposition:v:0 attached_pic', '-metadata:s:v', 'title=Cover', '-metadata:s:v', 'comment=Cover'])
|
||||||
|
|
@ -153,7 +153,7 @@ describe('addCoverAndMetadataToFile', () => {
|
||||||
expect(ffmpegStub.input.getCall(1).args[0]).to.equal(metadataFilePath)
|
expect(ffmpegStub.input.getCall(1).args[0]).to.equal(metadataFilePath)
|
||||||
|
|
||||||
expect(ffmpegStub.outputOptions.callCount).to.equal(4)
|
expect(ffmpegStub.outputOptions.callCount).to.equal(4)
|
||||||
expect(ffmpegStub.outputOptions.getCall(0).args[0]).to.deep.equal(['-map 0:a', '-map_metadata 1', '-map_chapters 1', '-c copy'])
|
expect(ffmpegStub.outputOptions.getCall(0).args[0]).to.deep.equal(['-map 0:a', '-map_metadata 1', '-map_metadata 0', '-map_chapters 1', '-c copy'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(1).args[0]).to.deep.equal(['-metadata track=1'])
|
expect(ffmpegStub.outputOptions.getCall(1).args[0]).to.deep.equal(['-metadata track=1'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(2).args[0]).to.deep.equal(['-id3v2_version 3'])
|
expect(ffmpegStub.outputOptions.getCall(2).args[0]).to.deep.equal(['-id3v2_version 3'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(3).args[0]).to.deep.equal(['-map 0:v?'])
|
expect(ffmpegStub.outputOptions.getCall(3).args[0]).to.deep.equal(['-map 0:v?'])
|
||||||
|
|
@ -195,7 +195,7 @@ describe('addCoverAndMetadataToFile', () => {
|
||||||
expect(ffmpegStub.input.getCall(2).args[0]).to.equal(coverFilePath)
|
expect(ffmpegStub.input.getCall(2).args[0]).to.equal(coverFilePath)
|
||||||
|
|
||||||
expect(ffmpegStub.outputOptions.callCount).to.equal(4)
|
expect(ffmpegStub.outputOptions.callCount).to.equal(4)
|
||||||
expect(ffmpegStub.outputOptions.getCall(0).args[0]).to.deep.equal(['-map 0:a', '-map_metadata 1', '-map_chapters 1', '-c copy'])
|
expect(ffmpegStub.outputOptions.getCall(0).args[0]).to.deep.equal(['-map 0:a', '-map_metadata 1', '-map_metadata 0', '-map_chapters 1', '-c copy'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(1).args[0]).to.deep.equal(['-metadata track=1'])
|
expect(ffmpegStub.outputOptions.getCall(1).args[0]).to.deep.equal(['-metadata track=1'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(2).args[0]).to.deep.equal(['-id3v2_version 3'])
|
expect(ffmpegStub.outputOptions.getCall(2).args[0]).to.deep.equal(['-id3v2_version 3'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(3).args[0]).to.deep.equal(['-map 2:v', '-disposition:v:0 attached_pic', '-metadata:s:v', 'title=Cover', '-metadata:s:v', 'comment=Cover'])
|
expect(ffmpegStub.outputOptions.getCall(3).args[0]).to.deep.equal(['-map 2:v', '-disposition:v:0 attached_pic', '-metadata:s:v', 'title=Cover', '-metadata:s:v', 'comment=Cover'])
|
||||||
|
|
@ -227,9 +227,9 @@ describe('addCoverAndMetadataToFile', () => {
|
||||||
expect(ffmpegStub.input.getCall(2).args[0]).to.equal(coverFilePath)
|
expect(ffmpegStub.input.getCall(2).args[0]).to.equal(coverFilePath)
|
||||||
|
|
||||||
expect(ffmpegStub.outputOptions.callCount).to.equal(4)
|
expect(ffmpegStub.outputOptions.callCount).to.equal(4)
|
||||||
expect(ffmpegStub.outputOptions.getCall(0).args[0]).to.deep.equal(['-map 0:a', '-map_metadata 1', '-map_chapters 1', '-c copy'])
|
expect(ffmpegStub.outputOptions.getCall(0).args[0]).to.deep.equal(['-map 0:a', '-map_metadata 1', '-map_metadata 0', '-map_chapters 1', '-c copy'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(1).args[0]).to.deep.equal(['-metadata track=1'])
|
expect(ffmpegStub.outputOptions.getCall(1).args[0]).to.deep.equal(['-metadata track=1'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(2).args[0]).to.deep.equal(['-f mp4', '-movflags use_metadata_tags'])
|
expect(ffmpegStub.outputOptions.getCall(2).args[0]).to.deep.equal(['-f mp4'])
|
||||||
expect(ffmpegStub.outputOptions.getCall(3).args[0]).to.deep.equal(['-map 2:v', '-disposition:v:0 attached_pic', '-metadata:s:v', 'title=Cover', '-metadata:s:v', 'comment=Cover'])
|
expect(ffmpegStub.outputOptions.getCall(3).args[0]).to.deep.equal(['-map 2:v', '-disposition:v:0 attached_pic', '-metadata:s:v', 'title=Cover', '-metadata:s:v', 'comment=Cover'])
|
||||||
|
|
||||||
expect(ffmpegStub.output.calledOnce).to.be.true
|
expect(ffmpegStub.output.calledOnce).to.be.true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue