Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix embed and convert for single file library items #3329

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions server/managers/AbMergeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })),
Expand Down Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions server/managers/AudioMetadataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading