mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-04 02:05:06 +02:00
Supporting more file structures for series and publish year
This commit is contained in:
parent
15445ad548
commit
dd12e3ac73
8 changed files with 63 additions and 21 deletions
|
@ -29,22 +29,41 @@ function getFileType(ext) {
|
|||
return 'unknown'
|
||||
}
|
||||
|
||||
async function getAllAudiobookFiles(path) {
|
||||
console.log('getAllAudiobooks', path)
|
||||
var paths = await getPaths(path)
|
||||
async function getAllAudiobookFiles(abRootPath) {
|
||||
var paths = await getPaths(abRootPath)
|
||||
var audiobooks = {}
|
||||
|
||||
paths.files.forEach((filepath) => {
|
||||
var relpath = filepath.replace(path, '').slice(1)
|
||||
var relpath = filepath.replace(abRootPath, '').slice(1)
|
||||
var pathformat = Path.parse(relpath)
|
||||
var authordir = Path.dirname(pathformat.dir)
|
||||
var bookdir = Path.basename(pathformat.dir)
|
||||
if (!audiobooks[bookdir]) {
|
||||
audiobooks[bookdir] = {
|
||||
author: authordir,
|
||||
title: bookdir,
|
||||
path: pathformat.dir,
|
||||
fullPath: Path.join(path, pathformat.dir),
|
||||
var path = pathformat.dir
|
||||
|
||||
// If relative file directory has 3 folders, then the middle folder will be series
|
||||
var splitDir = pathformat.dir.split(Path.sep)
|
||||
var author = splitDir.shift()
|
||||
var series = null
|
||||
if (splitDir.length > 1) series = splitDir.shift()
|
||||
var title = splitDir.shift()
|
||||
|
||||
var publishYear = null
|
||||
|
||||
// If Title is of format 1999 - Title, then use 1999 as publish year
|
||||
var publishYearMatch = title.match(/^([0-9]{4}) - (.+)/)
|
||||
if (publishYearMatch && publishYearMatch.length > 2) {
|
||||
if (!isNaN(publishYearMatch[1])) {
|
||||
publishYear = publishYearMatch[1]
|
||||
title = publishYearMatch[2]
|
||||
}
|
||||
}
|
||||
|
||||
if (!audiobooks[path]) {
|
||||
audiobooks[path] = {
|
||||
author: author,
|
||||
title: title,
|
||||
series: series,
|
||||
publishYear: publishYear,
|
||||
path: relpath,
|
||||
fullPath: Path.join(abRootPath, path),
|
||||
parts: [],
|
||||
otherFiles: []
|
||||
}
|
||||
|
@ -52,7 +71,7 @@ async function getAllAudiobookFiles(path) {
|
|||
|
||||
var filetype = getFileType(pathformat.ext)
|
||||
if (filetype === 'abpart') {
|
||||
audiobooks[bookdir].parts.push(pathformat.base)
|
||||
audiobooks[path].parts.push(pathformat.base)
|
||||
} else {
|
||||
var fileObj = {
|
||||
filetype: filetype,
|
||||
|
@ -61,7 +80,7 @@ async function getAllAudiobookFiles(path) {
|
|||
fullPath: filepath,
|
||||
ext: pathformat.ext
|
||||
}
|
||||
audiobooks[bookdir].otherFiles.push(fileObj)
|
||||
audiobooks[path].otherFiles.push(fileObj)
|
||||
}
|
||||
})
|
||||
return Object.values(audiobooks)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue