From 589c4f73d23924bc18bf3265062b1a8a90cd41be Mon Sep 17 00:00:00 2001 From: advplyr Date: Wed, 12 Apr 2023 16:45:52 -0500 Subject: [PATCH] Cleanup scanner --- server/scanner/Scanner.js | 6 +++--- server/utils/scandir.js | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/server/scanner/Scanner.js b/server/scanner/Scanner.js index 682700b5..2280f0e3 100644 --- a/server/scanner/Scanner.js +++ b/server/scanner/Scanner.js @@ -68,7 +68,7 @@ class Scanner { async scanLibraryItem(libraryMediaType, folder, libraryItem) { // TODO: Support for single media item - const libraryItemData = await getLibraryItemFileData(libraryMediaType, folder, libraryItem.path, false, this.db.serverSettings) + const libraryItemData = await getLibraryItemFileData(libraryMediaType, folder, libraryItem.path, false) if (!libraryItemData) { return ScanResult.NOTHING } @@ -173,7 +173,7 @@ class Scanner { // Scan each library for (let i = 0; i < libraryScan.folders.length; i++) { const folder = libraryScan.folders[i] - const itemDataFoundInFolder = await scanFolder(libraryScan.libraryMediaType, folder, this.db.serverSettings) + const itemDataFoundInFolder = await scanFolder(libraryScan.libraryMediaType, folder) libraryScan.addLog(LogLevel.INFO, `${itemDataFoundInFolder.length} item data found in folder "${folder.fullPath}"`) libraryItemDataFound = libraryItemDataFound.concat(itemDataFoundInFolder) } @@ -632,7 +632,7 @@ class Scanner { } async scanPotentialNewLibraryItem(libraryMediaType, folder, fullPath, isSingleMediaItem = false) { - const libraryItemData = await getLibraryItemFileData(libraryMediaType, folder, fullPath, isSingleMediaItem, this.db.serverSettings) + const libraryItemData = await getLibraryItemFileData(libraryMediaType, folder, fullPath, isSingleMediaItem) if (!libraryItemData) return null return this.scanNewLibraryItem(libraryItemData, libraryMediaType) } diff --git a/server/utils/scandir.js b/server/utils/scandir.js index 9df5254b..7f5b9855 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -175,7 +175,7 @@ function cleanFileObjects(libraryItemPath, files) { } // Scan folder -async function scanFolder(libraryMediaType, folder, serverSettings = {}) { +async function scanFolder(libraryMediaType, folder) { const folderPath = filePathToPOSIX(folder.fullPath) const pathExists = await fs.pathExists(folderPath) @@ -216,7 +216,7 @@ async function scanFolder(libraryMediaType, folder, serverSettings = {}) { fileObjs = await cleanFileObjects(folderPath, [libraryItemPath]) isFile = true } else { - libraryItemData = getDataFromMediaDir(libraryMediaType, folderPath, libraryItemPath, serverSettings, libraryItemGrouping[libraryItemPath]) + libraryItemData = getDataFromMediaDir(libraryMediaType, folderPath, libraryItemPath) fileObjs = await cleanFileObjects(libraryItemData.path, libraryItemGrouping[libraryItemPath]) } @@ -347,19 +347,18 @@ function getPodcastDataFromDir(folderPath, relPath) { } } -function getDataFromMediaDir(libraryMediaType, folderPath, relPath, serverSettings, fileNames) { +function getDataFromMediaDir(libraryMediaType, folderPath, relPath) { if (libraryMediaType === 'podcast') { return getPodcastDataFromDir(folderPath, relPath) } else if (libraryMediaType === 'book') { - var parseSubtitle = !!serverSettings.scannerParseSubtitle - return getBookDataFromDir(folderPath, relPath, parseSubtitle) + return getBookDataFromDir(folderPath, relPath, !!global.ServerSettings.scannerParseSubtitle) } else { return getPodcastDataFromDir(folderPath, relPath) } } // Called from Scanner.js -async function getLibraryItemFileData(libraryMediaType, folder, libraryItemPath, isSingleMediaItem, serverSettings = {}) { +async function getLibraryItemFileData(libraryMediaType, folder, libraryItemPath, isSingleMediaItem) { libraryItemPath = filePathToPOSIX(libraryItemPath) const folderFullPath = filePathToPOSIX(folder.fullPath) @@ -384,8 +383,7 @@ async function getLibraryItemFileData(libraryMediaType, folder, libraryItemPath, } } else { fileItems = await recurseFiles(libraryItemPath) - const fileNames = fileItems.map(i => i.name) - libraryItemData = getDataFromMediaDir(libraryMediaType, folderFullPath, libraryItemDir, serverSettings, fileNames) + libraryItemData = getDataFromMediaDir(libraryMediaType, folderFullPath, libraryItemDir) } const libraryItemDirStats = await getFileTimestampsWithIno(libraryItemData.path)