-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3672 from Techwolfy/disc-folder-support
Support additional disc folder names
- Loading branch information
Showing
3 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'] | ||
}) | ||
}) | ||
}) |