Add id to the metadata json and use it when moving files if ino cannot be matched

This commit is contained in:
Cutch 2025-11-24 22:46:57 -05:00
parent 8758c62ae2
commit 6ac0a8a678
4 changed files with 17 additions and 1 deletions

View file

@ -574,6 +574,7 @@ class LibraryItem extends Model {
let jsonObject = {}
if (this.mediaType === 'book') {
jsonObject = {
absId: this.id,
tags: mediaExpanded.tags || [],
chapters: mediaExpanded.chapters?.map((c) => ({ ...c })) || [],
title: mediaExpanded.title,
@ -598,6 +599,7 @@ class LibraryItem extends Model {
}
} else {
jsonObject = {
absId: this.id,
tags: mediaExpanded.tags || [],
title: mediaExpanded.title,
author: mediaExpanded.author,

View file

@ -821,6 +821,7 @@ class BookScanner {
const metadataFilePath = Path.join(metadataPath, `metadata.${global.ServerSettings.metadataFileFormat}`)
const jsonObject = {
absId: libraryItem.id,
tags: libraryItem.media.tags || [],
chapters: libraryItem.media.chapters?.map((c) => ({ ...c })) || [],
title: libraryItem.media.title,

View file

@ -14,6 +14,7 @@ const LibraryItemScanner = require('./LibraryItemScanner')
const LibraryScan = require('./LibraryScan')
const LibraryItemScanData = require('./LibraryItemScanData')
const Task = require('../objects/Task')
const abmetadataGenerator = require('../utils/generators/abmetadataGenerator')
class LibraryScanner {
constructor() {
@ -574,7 +575,7 @@ class LibraryScanner {
let updatedLibraryItemDetails = {}
if (!existingLibraryItem) {
const isSingleMedia = isSingleMediaFile(fileUpdateGroup, itemDir)
existingLibraryItem = (await findLibraryItemByItemToItemInoMatch(library.id, fullPath)) || (await findLibraryItemByItemToFileInoMatch(library.id, fullPath, isSingleMedia)) || (await findLibraryItemByFileToItemInoMatch(library.id, fullPath, isSingleMedia, fileUpdateGroup[itemDir]))
existingLibraryItem = (await findLibraryItemByItemToItemInoMatch(library.id, fullPath)) || (await findLibraryItemByItemToFileInoMatch(library.id, fullPath, isSingleMedia)) || (await findLibraryItemByFileToItemInoMatch(library.id, fullPath, isSingleMedia, fileUpdateGroup[itemDir])) || (await findLibraryItemByItemToMetadata(fullPath, isSingleMedia))
if (existingLibraryItem) {
// Update library item paths for scan
existingLibraryItem.path = fullPath
@ -709,3 +710,14 @@ async function findLibraryItemByFileToItemInoMatch(libraryId, fullPath, isSingle
if (existingLibraryItem) Logger.debug(`[LibraryScanner] Found library item with inode matching one of "${itemFileInos.join(',')}" at path "${existingLibraryItem.path}"`)
return existingLibraryItem
}
async function findLibraryItemByItemToMetadata(fullPath, isSingleMedia) {
if (isSingleMedia) return null
const metadataText = await fileUtils.readTextFile(Path.join(fullPath, 'metadata.json'))
if (!metadataText) return null
const abMetadata = abmetadataGenerator.parseJson(metadataText) || {}
// check if metadata id exists in the database
const existingLibraryItem = await Database.libraryItemModel.getExpandedById(abMetadata.absId)
if (existingLibraryItem) Logger.debug(`[LibraryScanner] Found library item with metadata id matching one of "${abMetadata.absId}" at path "${existingLibraryItem.path}"`)
return existingLibraryItem
}

View file

@ -421,6 +421,7 @@ class PodcastScanner {
const metadataFilePath = Path.join(metadataPath, `metadata.${global.ServerSettings.metadataFileFormat}`)
const jsonObject = {
absId: libraryItem.id,
tags: libraryItem.media.tags || [],
title: libraryItem.media.title,
author: libraryItem.media.author,