Add:Support for book folders with CD# subfolders #393

This commit is contained in:
advplyr 2022-03-07 16:22:20 -06:00
parent c6eb1096e8
commit 2b7f53b0a7
2 changed files with 16 additions and 2 deletions

View File

@ -9,8 +9,9 @@ const { LogLevel } = require('../utils/constants')
class AudioFileScanner {
constructor() { }
getTrackAndDiscNumberFromFilename(bookScanData, filename) {
getTrackAndDiscNumberFromFilename(bookScanData, audioFileData) {
const { title, author, series, publishYear } = bookScanData
const { filename, path } = audioFileData
var partbasename = Path.basename(filename, Path.extname(filename))
// Remove title, author, series, and publishYear from filename if there
@ -31,6 +32,13 @@ class AudioFileScanner {
partbasename = partbasename.replace(/\b(disc|cd) ?(\d\d?)\b/i, '')
}
// Look for disc number in folder path e.g. /Book Title/CD01/audiofile.mp3
var pathdir = Path.dirname(path).split('/').pop()
if (pathdir && /^cd\d{1,3}$/i.test(pathdir)) {
var discFromFolder = Number(pathdir.replace(/cd/i, ''))
if (!isNaN(discFromFolder) && discFromFolder !== null) discNumber = discFromFolder
}
var numbersinpath = partbasename.match(/\d{1,4}/g)
var trackNumber = numbersinpath && numbersinpath.length ? parseInt(numbersinpath[0]) : null
return {
@ -60,7 +68,7 @@ class AudioFileScanner {
audioFileData.trackNumFromMeta = probeData.trackNumber
audioFileData.discNumFromMeta = probeData.discNumber
const { trackNumber, discNumber } = this.getTrackAndDiscNumberFromFilename(bookScanData, audioFileData.filename)
const { trackNumber, discNumber } = this.getTrackAndDiscNumberFromFilename(bookScanData, audioFileData)
audioFileData.trackNumFromFilename = trackNumber
audioFileData.discNumFromFilename = discNumber

View File

@ -47,6 +47,9 @@ function groupFilesIntoAudiobookPaths(paths) {
} else if (!dirparts.length) { // This is the last directory, create group
audiobookGroup[_path] = [Path.basename(path)]
return
} else if (dirparts.length === 1 && /^cd\d{1,3}$/i.test(dirparts[0])) { // Next directory is the last and is a CD dir, create group
audiobookGroup[_path] = [Path.posix.join(dirparts[0], Path.basename(path))]
return
}
}
})
@ -88,6 +91,9 @@ function groupFileItemsIntoBooks(fileItems) {
} else if (!dirparts.length) { // This is the last directory, create group
audiobookGroup[_path] = [item.name]
return
} else if (dirparts.length === 1 && /^cd\d{1,3}$/i.test(dirparts[0])) { // Next directory is the last and is a CD dir, create group
audiobookGroup[_path] = [Path.posix.join(dirparts[0], item.name)]
return
}
}
})