From a03146e09c7ba04311a0e8e14765809cce151630 Mon Sep 17 00:00:00 2001 From: Techwolf Date: Sun, 1 Dec 2024 18:10:44 -0800 Subject: [PATCH 1/4] Support additional disc folder names --- server/utils/scandir.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/utils/scandir.js b/server/utils/scandir.js index ff21e814f2..27cfe003a8 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -96,7 +96,7 @@ function groupFilesIntoLibraryItemPaths(mediaType, paths) { // This is the last directory, create group itemGroup[_path] = [Path.basename(path)] return - } else if (dirparts.length === 1 && /^cd\d{1,3}$/i.test(dirparts[0])) { + } else if (dirparts.length === 1 && /^(cd|dis[ck])\s*\d{1,3}$/i.test(dirparts[0])) { // Next directory is the last and is a CD dir, create group itemGroup[_path] = [Path.posix.join(dirparts[0], Path.basename(path))] return From cc89db059bdd8ed3595f4846a78d5f843f2cdefa Mon Sep 17 00:00:00 2001 From: Techwolf Date: Sun, 1 Dec 2024 18:41:38 -0800 Subject: [PATCH 2/4] Fix second instance of regex --- server/utils/scandir.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/utils/scandir.js b/server/utils/scandir.js index 27cfe003a8..028a1022db 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -179,7 +179,7 @@ function groupFileItemsIntoLibraryItemDirs(mediaType, fileItems, audiobooksOnly // This is the last directory, create group libraryItemGroup[_path] = [item.name] return - } else if (dirparts.length === 1 && /^cd\d{1,3}$/i.test(dirparts[0])) { + } else if (dirparts.length === 1 && /^(cd|dis[ck])\s*\d{1,3}$/i.test(dirparts[0])) { // Next directory is the last and is a CD dir, create group libraryItemGroup[_path] = [Path.posix.join(dirparts[0], item.name)] return From 605bd73c11aa2b79552a1da26f6c29ff904b899a Mon Sep 17 00:00:00 2001 From: Techwolf Date: Sun, 1 Dec 2024 23:57:47 -0800 Subject: [PATCH 3/4] Fix third instance of regex --- server/scanner/AudioFileScanner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/scanner/AudioFileScanner.js b/server/scanner/AudioFileScanner.js index 3c364c1066..6c808aaa1c 100644 --- a/server/scanner/AudioFileScanner.js +++ b/server/scanner/AudioFileScanner.js @@ -133,8 +133,8 @@ class AudioFileScanner { // Look for disc number in folder path e.g. /Book Title/CD01/audiofile.mp3 const pathdir = Path.dirname(path).split('/').pop() - if (pathdir && /^cd\d{1,3}$/i.test(pathdir)) { - const discFromFolder = Number(pathdir.replace(/cd/i, '')) + if (pathdir && /^(cd|dis[ck])\s*\d{1,3}$/i.test(pathdir)) { + const discFromFolder = Number(pathdir.replace(/^(cd|dis[ck])\s*/i, '')) if (!isNaN(discFromFolder) && discFromFolder !== null) discNumber = discFromFolder } From 0f1b64b883479401d09ad3f45c76a976e1af4211 Mon Sep 17 00:00:00 2001 From: advplyr Date: Tue, 3 Dec 2024 17:21:57 -0600 Subject: [PATCH 4/4] Add test for grouping book library items --- test/server/utils/scandir.test.js | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/server/utils/scandir.test.js diff --git a/test/server/utils/scandir.test.js b/test/server/utils/scandir.test.js new file mode 100644 index 0000000000..a5ff6ae0ec --- /dev/null +++ b/test/server/utils/scandir.test.js @@ -0,0 +1,52 @@ +const Path = require('path') +const chai = require('chai') +const expect = chai.expect +const scanUtils = require('../../../server/utils/scandir') + +describe('scanUtils', async () => { + it('should properly group files into potential book library items', async () => { + global.isWin = process.platform === 'win32' + global.ServerSettings = { + scannerParseSubtitle: true + } + + const filePaths = [ + 'randomfile.txt', // Should be ignored because it's not a book media file + 'Book1.m4b', // Root single file audiobook + 'Book2/audiofile.m4b', + 'Book2/disk 001/audiofile.m4b', + 'Book2/disk 002/audiofile.m4b', + 'Author/Book3/audiofile.mp3', + 'Author/Book3/Disc 1/audiofile.mp3', + 'Author/Book3/Disc 2/audiofile.mp3', + 'Author/Series/Book4/cover.jpg', + 'Author/Series/Book4/CD1/audiofile.mp3', + 'Author/Series/Book4/CD2/audiofile.mp3', + 'Author/Series2/Book5/deeply/nested/cd 01/audiofile.mp3', + 'Author/Series2/Book5/deeply/nested/cd 02/audiofile.mp3', + 'Author/Series2/Book5/randomfile.js' // Should be ignored because it's not a book media file + ] + + // Create fileItems to match the format of fileUtils.recurseFiles + const fileItems = [] + for (const filePath of filePaths) { + const dirname = Path.dirname(filePath) + fileItems.push({ + name: Path.basename(filePath), + reldirpath: dirname === '.' ? '' : dirname, + extension: Path.extname(filePath), + deep: filePath.split('/').length - 1 + }) + } + + const libraryItemGrouping = scanUtils.groupFileItemsIntoLibraryItemDirs('book', fileItems, false) + + expect(libraryItemGrouping).to.deep.equal({ + 'Book1.m4b': 'Book1.m4b', + Book2: ['audiofile.m4b', 'disk 001/audiofile.m4b', 'disk 002/audiofile.m4b'], + 'Author/Book3': ['audiofile.mp3', 'Disc 1/audiofile.mp3', 'Disc 2/audiofile.mp3'], + 'Author/Series/Book4': ['CD1/audiofile.mp3', 'CD2/audiofile.mp3', 'cover.jpg'], + 'Author/Series2/Book5/deeply/nested': ['cd 01/audiofile.mp3', 'cd 02/audiofile.mp3'] + }) + }) +})