mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Add:Support for book folders with CD# subfolders #393
This commit is contained in:
parent
c6eb1096e8
commit
2b7f53b0a7
@ -9,8 +9,9 @@ const { LogLevel } = require('../utils/constants')
|
|||||||
class AudioFileScanner {
|
class AudioFileScanner {
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
getTrackAndDiscNumberFromFilename(bookScanData, filename) {
|
getTrackAndDiscNumberFromFilename(bookScanData, audioFileData) {
|
||||||
const { title, author, series, publishYear } = bookScanData
|
const { title, author, series, publishYear } = bookScanData
|
||||||
|
const { filename, path } = audioFileData
|
||||||
var partbasename = Path.basename(filename, Path.extname(filename))
|
var partbasename = Path.basename(filename, Path.extname(filename))
|
||||||
|
|
||||||
// Remove title, author, series, and publishYear from filename if there
|
// 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, '')
|
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 numbersinpath = partbasename.match(/\d{1,4}/g)
|
||||||
var trackNumber = numbersinpath && numbersinpath.length ? parseInt(numbersinpath[0]) : null
|
var trackNumber = numbersinpath && numbersinpath.length ? parseInt(numbersinpath[0]) : null
|
||||||
return {
|
return {
|
||||||
@ -60,7 +68,7 @@ class AudioFileScanner {
|
|||||||
audioFileData.trackNumFromMeta = probeData.trackNumber
|
audioFileData.trackNumFromMeta = probeData.trackNumber
|
||||||
audioFileData.discNumFromMeta = probeData.discNumber
|
audioFileData.discNumFromMeta = probeData.discNumber
|
||||||
|
|
||||||
const { trackNumber, discNumber } = this.getTrackAndDiscNumberFromFilename(bookScanData, audioFileData.filename)
|
const { trackNumber, discNumber } = this.getTrackAndDiscNumberFromFilename(bookScanData, audioFileData)
|
||||||
audioFileData.trackNumFromFilename = trackNumber
|
audioFileData.trackNumFromFilename = trackNumber
|
||||||
audioFileData.discNumFromFilename = discNumber
|
audioFileData.discNumFromFilename = discNumber
|
||||||
|
|
||||||
|
@ -47,6 +47,9 @@ function groupFilesIntoAudiobookPaths(paths) {
|
|||||||
} else if (!dirparts.length) { // This is the last directory, create group
|
} else if (!dirparts.length) { // This is the last directory, create group
|
||||||
audiobookGroup[_path] = [Path.basename(path)]
|
audiobookGroup[_path] = [Path.basename(path)]
|
||||||
return
|
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
|
} else if (!dirparts.length) { // This is the last directory, create group
|
||||||
audiobookGroup[_path] = [item.name]
|
audiobookGroup[_path] = [item.name]
|
||||||
return
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user