mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-05-24 01:13:00 -04:00
Update watcher to re-scan library items when non-media files are added/updated #4245
This commit is contained in:
parent
2b7268c952
commit
2cc9d1b7f8
@ -246,7 +246,6 @@ class LibraryItem extends Model {
|
||||
include
|
||||
})
|
||||
if (!libraryItem) {
|
||||
Logger.error(`[LibraryItem] Library item not found`)
|
||||
return null
|
||||
}
|
||||
|
||||
|
@ -407,7 +407,7 @@ class LibraryScanner {
|
||||
const folder = library.libraryFolders[0]
|
||||
|
||||
const filePathItems = folderGroups[folderId].fileUpdates.map((fileUpdate) => fileUtils.getFilePathItemFromFileUpdate(fileUpdate))
|
||||
const fileUpdateGroup = scanUtils.groupFileItemsIntoLibraryItemDirs(library.mediaType, filePathItems, !!library.settings?.audiobooksOnly)
|
||||
const fileUpdateGroup = scanUtils.groupFileItemsIntoLibraryItemDirs(library.mediaType, filePathItems, !!library.settings?.audiobooksOnly, true)
|
||||
|
||||
if (!Object.keys(fileUpdateGroup).length) {
|
||||
Logger.info(`[LibraryScanner] No important changes to scan for in folder "${folderId}"`)
|
||||
|
@ -24,6 +24,12 @@ function isMediaFile(mediaType, ext, audiobooksOnly = false) {
|
||||
return globals.SupportedAudioTypes.includes(extclean) || globals.SupportedEbookTypes.includes(extclean)
|
||||
}
|
||||
|
||||
function isScannableNonMediaFile(ext) {
|
||||
if (!ext) return false
|
||||
const extclean = ext.slice(1).toLowerCase()
|
||||
return globals.TextFileTypes.includes(extclean) || globals.MetadataFileTypes.includes(extclean) || globals.SupportedImageTypes.includes(extclean)
|
||||
}
|
||||
|
||||
function checkFilepathIsAudioFile(filepath) {
|
||||
const ext = Path.extname(filepath)
|
||||
if (!ext) return false
|
||||
@ -35,27 +41,31 @@ module.exports.checkFilepathIsAudioFile = checkFilepathIsAudioFile
|
||||
/**
|
||||
* @param {string} mediaType
|
||||
* @param {import('./fileUtils').FilePathItem[]} fileItems
|
||||
* @param {boolean} [audiobooksOnly=false]
|
||||
* @param {boolean} audiobooksOnly
|
||||
* @param {boolean} [includeNonMediaFiles=false] - Used by the watcher to re-scan when covers/metadata files are added/removed
|
||||
* @returns {Record<string,string[]>} map of files grouped into potential libarary item dirs
|
||||
*/
|
||||
function groupFileItemsIntoLibraryItemDirs(mediaType, fileItems, audiobooksOnly = false) {
|
||||
function groupFileItemsIntoLibraryItemDirs(mediaType, fileItems, audiobooksOnly, includeNonMediaFiles = false) {
|
||||
// Step 1: Filter out non-book-media files in root dir (with depth of 0)
|
||||
const itemsFiltered = fileItems.filter((i) => {
|
||||
return i.deep > 0 || (mediaType === 'book' && isMediaFile(mediaType, i.extension, audiobooksOnly))
|
||||
})
|
||||
|
||||
// Step 2: Separate media files and other files
|
||||
// - Directories without a media file will not be included
|
||||
// - Directories without a media file will not be included (unless includeNonMediaFiles is true)
|
||||
/** @type {import('./fileUtils').FilePathItem[]} */
|
||||
const mediaFileItems = []
|
||||
/** @type {import('./fileUtils').FilePathItem[]} */
|
||||
const otherFileItems = []
|
||||
itemsFiltered.forEach((item) => {
|
||||
if (isMediaFile(mediaType, item.extension, audiobooksOnly)) mediaFileItems.push(item)
|
||||
else otherFileItems.push(item)
|
||||
if (isMediaFile(mediaType, item.extension, audiobooksOnly) || (includeNonMediaFiles && isScannableNonMediaFile(item.extension))) {
|
||||
mediaFileItems.push(item)
|
||||
} else {
|
||||
otherFileItems.push(item)
|
||||
}
|
||||
})
|
||||
|
||||
// Step 3: Group audio files in library items
|
||||
// Step 3: Group media files (or non-media files if includeNonMediaFiles is true) in library items
|
||||
const libraryItemGroup = {}
|
||||
mediaFileItems.forEach((item) => {
|
||||
const dirparts = item.reldirpath.split('/').filter((p) => !!p)
|
||||
|
Loading…
x
Reference in New Issue
Block a user