Skip to content

Commit 95c80a5

Browse files
authored
Merge pull request #3672 from Techwolfy/disc-folder-support
Support additional disc folder names
2 parents 615ed26 + 0f1b64b commit 95c80a5

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

server/scanner/AudioFileScanner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ class AudioFileScanner {
133133

134134
// Look for disc number in folder path e.g. /Book Title/CD01/audiofile.mp3
135135
const pathdir = Path.dirname(path).split('/').pop()
136-
if (pathdir && /^cd\d{1,3}$/i.test(pathdir)) {
137-
const discFromFolder = Number(pathdir.replace(/cd/i, ''))
136+
if (pathdir && /^(cd|dis[ck])\s*\d{1,3}$/i.test(pathdir)) {
137+
const discFromFolder = Number(pathdir.replace(/^(cd|dis[ck])\s*/i, ''))
138138
if (!isNaN(discFromFolder) && discFromFolder !== null) discNumber = discFromFolder
139139
}
140140

server/utils/scandir.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function groupFilesIntoLibraryItemPaths(mediaType, paths) {
9696
// This is the last directory, create group
9797
itemGroup[_path] = [Path.basename(path)]
9898
return
99-
} else if (dirparts.length === 1 && /^cd\d{1,3}$/i.test(dirparts[0])) {
99+
} else if (dirparts.length === 1 && /^(cd|dis[ck])\s*\d{1,3}$/i.test(dirparts[0])) {
100100
// Next directory is the last and is a CD dir, create group
101101
itemGroup[_path] = [Path.posix.join(dirparts[0], Path.basename(path))]
102102
return
@@ -179,7 +179,7 @@ function groupFileItemsIntoLibraryItemDirs(mediaType, fileItems, audiobooksOnly
179179
// This is the last directory, create group
180180
libraryItemGroup[_path] = [item.name]
181181
return
182-
} else if (dirparts.length === 1 && /^cd\d{1,3}$/i.test(dirparts[0])) {
182+
} else if (dirparts.length === 1 && /^(cd|dis[ck])\s*\d{1,3}$/i.test(dirparts[0])) {
183183
// Next directory is the last and is a CD dir, create group
184184
libraryItemGroup[_path] = [Path.posix.join(dirparts[0], item.name)]
185185
return

test/server/utils/scandir.test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const Path = require('path')
2+
const chai = require('chai')
3+
const expect = chai.expect
4+
const scanUtils = require('../../../server/utils/scandir')
5+
6+
describe('scanUtils', async () => {
7+
it('should properly group files into potential book library items', async () => {
8+
global.isWin = process.platform === 'win32'
9+
global.ServerSettings = {
10+
scannerParseSubtitle: true
11+
}
12+
13+
const filePaths = [
14+
'randomfile.txt', // Should be ignored because it's not a book media file
15+
'Book1.m4b', // Root single file audiobook
16+
'Book2/audiofile.m4b',
17+
'Book2/disk 001/audiofile.m4b',
18+
'Book2/disk 002/audiofile.m4b',
19+
'Author/Book3/audiofile.mp3',
20+
'Author/Book3/Disc 1/audiofile.mp3',
21+
'Author/Book3/Disc 2/audiofile.mp3',
22+
'Author/Series/Book4/cover.jpg',
23+
'Author/Series/Book4/CD1/audiofile.mp3',
24+
'Author/Series/Book4/CD2/audiofile.mp3',
25+
'Author/Series2/Book5/deeply/nested/cd 01/audiofile.mp3',
26+
'Author/Series2/Book5/deeply/nested/cd 02/audiofile.mp3',
27+
'Author/Series2/Book5/randomfile.js' // Should be ignored because it's not a book media file
28+
]
29+
30+
// Create fileItems to match the format of fileUtils.recurseFiles
31+
const fileItems = []
32+
for (const filePath of filePaths) {
33+
const dirname = Path.dirname(filePath)
34+
fileItems.push({
35+
name: Path.basename(filePath),
36+
reldirpath: dirname === '.' ? '' : dirname,
37+
extension: Path.extname(filePath),
38+
deep: filePath.split('/').length - 1
39+
})
40+
}
41+
42+
const libraryItemGrouping = scanUtils.groupFileItemsIntoLibraryItemDirs('book', fileItems, false)
43+
44+
expect(libraryItemGrouping).to.deep.equal({
45+
'Book1.m4b': 'Book1.m4b',
46+
Book2: ['audiofile.m4b', 'disk 001/audiofile.m4b', 'disk 002/audiofile.m4b'],
47+
'Author/Book3': ['audiofile.mp3', 'Disc 1/audiofile.mp3', 'Disc 2/audiofile.mp3'],
48+
'Author/Series/Book4': ['CD1/audiofile.mp3', 'CD2/audiofile.mp3', 'cover.jpg'],
49+
'Author/Series2/Book5/deeply/nested': ['cd 01/audiofile.mp3', 'cd 02/audiofile.mp3']
50+
})
51+
})
52+
})

0 commit comments

Comments
 (0)