mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
Merge pull request #3329 from mikiher/embed-single-file
Fix embed and convert for single file library items
This commit is contained in:
commit
e0de59a4b6
@ -53,20 +53,21 @@ class AbMergeManager {
|
|||||||
async startAudiobookMerge(userId, libraryItem, options = {}) {
|
async startAudiobookMerge(userId, libraryItem, options = {}) {
|
||||||
const task = new Task()
|
const task = new Task()
|
||||||
|
|
||||||
const audiobookDirname = Path.basename(libraryItem.path)
|
const audiobookBaseName = libraryItem.isFile ? Path.basename(libraryItem.path, Path.extname(libraryItem.path)) : Path.basename(libraryItem.path)
|
||||||
const targetFilename = audiobookDirname + '.m4b'
|
const targetFilename = audiobookBaseName + '.m4b'
|
||||||
const itemCachePath = Path.join(this.itemsCacheDir, libraryItem.id)
|
const itemCachePath = Path.join(this.itemsCacheDir, libraryItem.id)
|
||||||
const tempFilepath = Path.join(itemCachePath, targetFilename)
|
const tempFilepath = Path.join(itemCachePath, targetFilename)
|
||||||
const ffmetadataPath = Path.join(itemCachePath, 'ffmetadata.txt')
|
const ffmetadataPath = Path.join(itemCachePath, 'ffmetadata.txt')
|
||||||
|
const libraryItemDir = libraryItem.isFile ? Path.dirname(libraryItem.path) : libraryItem.path
|
||||||
const taskData = {
|
const taskData = {
|
||||||
libraryItemId: libraryItem.id,
|
libraryItemId: libraryItem.id,
|
||||||
libraryItemPath: libraryItem.path,
|
libraryItemDir,
|
||||||
userId,
|
userId,
|
||||||
originalTrackPaths: libraryItem.media.tracks.map((t) => t.metadata.path),
|
originalTrackPaths: libraryItem.media.tracks.map((t) => t.metadata.path),
|
||||||
inos: libraryItem.media.includedAudioFiles.map((f) => f.ino),
|
inos: libraryItem.media.includedAudioFiles.map((f) => f.ino),
|
||||||
tempFilepath,
|
tempFilepath,
|
||||||
targetFilename,
|
targetFilename,
|
||||||
targetFilepath: Path.join(libraryItem.path, targetFilename),
|
targetFilepath: Path.join(libraryItemDir, targetFilename),
|
||||||
itemCachePath,
|
itemCachePath,
|
||||||
ffmetadataObject: ffmpegHelpers.getFFMetadataObject(libraryItem, 1),
|
ffmetadataObject: ffmpegHelpers.getFFMetadataObject(libraryItem, 1),
|
||||||
chapters: libraryItem.media.chapters?.map((c) => ({ ...c })),
|
chapters: libraryItem.media.chapters?.map((c) => ({ ...c })),
|
||||||
@ -95,8 +96,8 @@ class AbMergeManager {
|
|||||||
*/
|
*/
|
||||||
async runAudiobookMerge(libraryItem, task, encodingOptions) {
|
async runAudiobookMerge(libraryItem, task, encodingOptions) {
|
||||||
// Make sure the target directory is writable
|
// Make sure the target directory is writable
|
||||||
if (!(await isWritable(libraryItem.path))) {
|
if (!(await isWritable(task.data.libraryItemDir))) {
|
||||||
Logger.error(`[AbMergeManager] Target directory is not writable: ${libraryItem.path}`)
|
Logger.error(`[AbMergeManager] Target directory is not writable: ${task.data.libraryItemDir}`)
|
||||||
task.setFailed('Target directory is not writable')
|
task.setFailed('Target directory is not writable')
|
||||||
this.removeTask(task, true)
|
this.removeTask(task, true)
|
||||||
return
|
return
|
||||||
|
@ -7,6 +7,12 @@ const TaskManager = require('./TaskManager')
|
|||||||
const Task = require('../objects/Task')
|
const Task = require('../objects/Task')
|
||||||
const fileUtils = require('../utils/fileUtils')
|
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 {
|
class AudioMetadataMangaer {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.itemsCacheDir = Path.join(global.MetadataPath, 'cache/items')
|
this.itemsCacheDir = Path.join(global.MetadataPath, 'cache/items')
|
||||||
@ -47,8 +53,8 @@ class AudioMetadataMangaer {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {string} userId
|
* @param {string} userId
|
||||||
* @param {*} libraryItem
|
* @param {import('../objects/LibraryItem')} libraryItem
|
||||||
* @param {*} options
|
* @param {UpdateMetadataOptions} [options={}]
|
||||||
*/
|
*/
|
||||||
async updateMetadataForItem(userId, libraryItem, options = {}) {
|
async updateMetadataForItem(userId, libraryItem, options = {}) {
|
||||||
const forceEmbedChapters = !!options.forceEmbedChapters
|
const forceEmbedChapters = !!options.forceEmbedChapters
|
||||||
@ -67,9 +73,10 @@ class AudioMetadataMangaer {
|
|||||||
if (audioFiles.some((a) => a.mimeType !== mimeType)) mimeType = null
|
if (audioFiles.some((a) => a.mimeType !== mimeType)) mimeType = null
|
||||||
|
|
||||||
// Create task
|
// Create task
|
||||||
|
const libraryItemDir = libraryItem.isFile ? Path.dirname(libraryItem.path) : libraryItem.path
|
||||||
const taskData = {
|
const taskData = {
|
||||||
libraryItemId: libraryItem.id,
|
libraryItemId: libraryItem.id,
|
||||||
libraryItemPath: libraryItem.path,
|
libraryItemDir,
|
||||||
userId,
|
userId,
|
||||||
audioFiles: audioFiles.map((af) => ({
|
audioFiles: audioFiles.map((af) => ({
|
||||||
index: af.index,
|
index: af.index,
|
||||||
@ -112,10 +119,10 @@ class AudioMetadataMangaer {
|
|||||||
Logger.info(`[AudioMetadataManager] Starting metadata embed task`, task.description)
|
Logger.info(`[AudioMetadataManager] Starting metadata embed task`, task.description)
|
||||||
|
|
||||||
// Ensure target directory is writable
|
// Ensure target directory is writable
|
||||||
const targetDirWritable = await fileUtils.isWritable(task.data.libraryItemPath)
|
const targetDirWritable = await fileUtils.isWritable(task.data.libraryItemDir)
|
||||||
Logger.debug(`[AudioMetadataManager] Target directory ${task.data.libraryItemPath} writable: ${targetDirWritable}`)
|
Logger.debug(`[AudioMetadataManager] Target directory ${task.data.libraryItemDir} writable: ${targetDirWritable}`)
|
||||||
if (!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')
|
task.setFailed('Target directory is not writable')
|
||||||
this.handleTaskFinished(task)
|
this.handleTaskFinished(task)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user