diff --git a/server/managers/AbMergeManager.js b/server/managers/AbMergeManager.js index 77702d79..d94e9489 100644 --- a/server/managers/AbMergeManager.js +++ b/server/managers/AbMergeManager.js @@ -53,20 +53,21 @@ class AbMergeManager { async startAudiobookMerge(userId, libraryItem, options = {}) { const task = new Task() - const audiobookDirname = Path.basename(libraryItem.path) - const targetFilename = audiobookDirname + '.m4b' + const audiobookBaseName = libraryItem.isFile ? Path.basename(libraryItem.path, Path.extname(libraryItem.path)) : Path.basename(libraryItem.path) + const targetFilename = audiobookBaseName + '.m4b' const itemCachePath = Path.join(this.itemsCacheDir, libraryItem.id) const tempFilepath = Path.join(itemCachePath, targetFilename) const ffmetadataPath = Path.join(itemCachePath, 'ffmetadata.txt') + const libraryItemDir = libraryItem.isFile ? Path.dirname(libraryItem.path) : libraryItem.path const taskData = { libraryItemId: libraryItem.id, - libraryItemPath: libraryItem.path, + libraryItemDir, userId, originalTrackPaths: libraryItem.media.tracks.map((t) => t.metadata.path), inos: libraryItem.media.includedAudioFiles.map((f) => f.ino), tempFilepath, targetFilename, - targetFilepath: Path.join(libraryItem.path, targetFilename), + targetFilepath: Path.join(libraryItemDir, targetFilename), itemCachePath, ffmetadataObject: ffmpegHelpers.getFFMetadataObject(libraryItem, 1), chapters: libraryItem.media.chapters?.map((c) => ({ ...c })), @@ -95,8 +96,8 @@ class AbMergeManager { */ async runAudiobookMerge(libraryItem, task, encodingOptions) { // Make sure the target directory is writable - if (!(await isWritable(libraryItem.path))) { - Logger.error(`[AbMergeManager] Target directory is not writable: ${libraryItem.path}`) + if (!(await isWritable(task.data.libraryItemDir))) { + Logger.error(`[AbMergeManager] Target directory is not writable: ${task.data.libraryItemDir}`) task.setFailed('Target directory is not writable') this.removeTask(task, true) return diff --git a/server/managers/AudioMetadataManager.js b/server/managers/AudioMetadataManager.js index f970d5a8..2dcbb1d4 100644 --- a/server/managers/AudioMetadataManager.js +++ b/server/managers/AudioMetadataManager.js @@ -7,6 +7,12 @@ const TaskManager = require('./TaskManager') const Task = require('../objects/Task') const fileUtils = require('../utils/fileUtils') +/** + * @typedef UpdateMetadataOptions + * @property {boolean} [forceEmbedChapters=false] - Whether to force embed chapters. + * @property {boolean} [backup=false] - Whether to backup the files. + */ + class AudioMetadataMangaer { constructor() { this.itemsCacheDir = Path.join(global.MetadataPath, 'cache/items') @@ -47,8 +53,8 @@ class AudioMetadataMangaer { /** * * @param {string} userId - * @param {*} libraryItem - * @param {*} options + * @param {import('../objects/LibraryItem')} libraryItem + * @param {UpdateMetadataOptions} [options={}] */ async updateMetadataForItem(userId, libraryItem, options = {}) { const forceEmbedChapters = !!options.forceEmbedChapters @@ -67,9 +73,10 @@ class AudioMetadataMangaer { if (audioFiles.some((a) => a.mimeType !== mimeType)) mimeType = null // Create task + const libraryItemDir = libraryItem.isFile ? Path.dirname(libraryItem.path) : libraryItem.path const taskData = { libraryItemId: libraryItem.id, - libraryItemPath: libraryItem.path, + libraryItemDir, userId, audioFiles: audioFiles.map((af) => ({ index: af.index, @@ -112,10 +119,10 @@ class AudioMetadataMangaer { Logger.info(`[AudioMetadataManager] Starting metadata embed task`, task.description) // Ensure target directory is writable - const targetDirWritable = await fileUtils.isWritable(task.data.libraryItemPath) - Logger.debug(`[AudioMetadataManager] Target directory ${task.data.libraryItemPath} writable: ${targetDirWritable}`) + const targetDirWritable = await fileUtils.isWritable(task.data.libraryItemDir) + Logger.debug(`[AudioMetadataManager] Target directory ${task.data.libraryItemDir} writable: ${targetDirWritable}`) if (!targetDirWritable) { - Logger.error(`[AudioMetadataManager] Target directory is not writable: ${task.data.libraryItemPath}`) + Logger.error(`[AudioMetadataManager] Target directory is not writable: ${task.data.libraryItemDir}`) task.setFailed('Target directory is not writable') this.handleTaskFinished(task) return