mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-22 19:59:37 +00:00
Add id to the metadata json and use it when moving files if ino cannot be matched
This commit is contained in:
parent
8758c62ae2
commit
6ac0a8a678
4 changed files with 17 additions and 1 deletions
|
|
@ -574,6 +574,7 @@ class LibraryItem extends Model {
|
||||||
let jsonObject = {}
|
let jsonObject = {}
|
||||||
if (this.mediaType === 'book') {
|
if (this.mediaType === 'book') {
|
||||||
jsonObject = {
|
jsonObject = {
|
||||||
|
absId: this.id,
|
||||||
tags: mediaExpanded.tags || [],
|
tags: mediaExpanded.tags || [],
|
||||||
chapters: mediaExpanded.chapters?.map((c) => ({ ...c })) || [],
|
chapters: mediaExpanded.chapters?.map((c) => ({ ...c })) || [],
|
||||||
title: mediaExpanded.title,
|
title: mediaExpanded.title,
|
||||||
|
|
@ -598,6 +599,7 @@ class LibraryItem extends Model {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
jsonObject = {
|
jsonObject = {
|
||||||
|
absId: this.id,
|
||||||
tags: mediaExpanded.tags || [],
|
tags: mediaExpanded.tags || [],
|
||||||
title: mediaExpanded.title,
|
title: mediaExpanded.title,
|
||||||
author: mediaExpanded.author,
|
author: mediaExpanded.author,
|
||||||
|
|
|
||||||
|
|
@ -821,6 +821,7 @@ class BookScanner {
|
||||||
const metadataFilePath = Path.join(metadataPath, `metadata.${global.ServerSettings.metadataFileFormat}`)
|
const metadataFilePath = Path.join(metadataPath, `metadata.${global.ServerSettings.metadataFileFormat}`)
|
||||||
|
|
||||||
const jsonObject = {
|
const jsonObject = {
|
||||||
|
absId: libraryItem.id,
|
||||||
tags: libraryItem.media.tags || [],
|
tags: libraryItem.media.tags || [],
|
||||||
chapters: libraryItem.media.chapters?.map((c) => ({ ...c })) || [],
|
chapters: libraryItem.media.chapters?.map((c) => ({ ...c })) || [],
|
||||||
title: libraryItem.media.title,
|
title: libraryItem.media.title,
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ const LibraryItemScanner = require('./LibraryItemScanner')
|
||||||
const LibraryScan = require('./LibraryScan')
|
const LibraryScan = require('./LibraryScan')
|
||||||
const LibraryItemScanData = require('./LibraryItemScanData')
|
const LibraryItemScanData = require('./LibraryItemScanData')
|
||||||
const Task = require('../objects/Task')
|
const Task = require('../objects/Task')
|
||||||
|
const abmetadataGenerator = require('../utils/generators/abmetadataGenerator')
|
||||||
|
|
||||||
class LibraryScanner {
|
class LibraryScanner {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -574,7 +575,7 @@ class LibraryScanner {
|
||||||
let updatedLibraryItemDetails = {}
|
let updatedLibraryItemDetails = {}
|
||||||
if (!existingLibraryItem) {
|
if (!existingLibraryItem) {
|
||||||
const isSingleMedia = isSingleMediaFile(fileUpdateGroup, itemDir)
|
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) {
|
if (existingLibraryItem) {
|
||||||
// Update library item paths for scan
|
// Update library item paths for scan
|
||||||
existingLibraryItem.path = fullPath
|
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}"`)
|
if (existingLibraryItem) Logger.debug(`[LibraryScanner] Found library item with inode matching one of "${itemFileInos.join(',')}" at path "${existingLibraryItem.path}"`)
|
||||||
return existingLibraryItem
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -421,6 +421,7 @@ class PodcastScanner {
|
||||||
const metadataFilePath = Path.join(metadataPath, `metadata.${global.ServerSettings.metadataFileFormat}`)
|
const metadataFilePath = Path.join(metadataPath, `metadata.${global.ServerSettings.metadataFileFormat}`)
|
||||||
|
|
||||||
const jsonObject = {
|
const jsonObject = {
|
||||||
|
absId: libraryItem.id,
|
||||||
tags: libraryItem.media.tags || [],
|
tags: libraryItem.media.tags || [],
|
||||||
title: libraryItem.media.title,
|
title: libraryItem.media.title,
|
||||||
author: libraryItem.media.author,
|
author: libraryItem.media.author,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue