mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-04 10:14:36 +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
|
@ -20,7 +20,7 @@ class Book {
|
|||
this.title = book.title
|
||||
this.author = book.author
|
||||
this.series = book.series
|
||||
this.publishYear = book.publish_year
|
||||
this.publishYear = book.publishYear
|
||||
this.publisher = book.publisher
|
||||
this.description = book.description
|
||||
this.cover = book.cover
|
||||
|
@ -33,7 +33,7 @@ class Book {
|
|||
title: this.title,
|
||||
author: this.author,
|
||||
series: this.series,
|
||||
publishYear: this.publish_year,
|
||||
publishYear: this.publishYear,
|
||||
publisher: this.publisher,
|
||||
description: this.description,
|
||||
cover: this.cover,
|
||||
|
@ -42,11 +42,12 @@ class Book {
|
|||
}
|
||||
|
||||
setData(data) {
|
||||
console.log('SET DATA', data)
|
||||
this.olid = data.olid || null
|
||||
this.title = data.title || null
|
||||
this.author = data.author || null
|
||||
this.series = data.series || null
|
||||
this.publishYear = data.publish_year || null
|
||||
this.publishYear = data.publishYear || null
|
||||
this.description = data.description || null
|
||||
this.cover = data.cover || null
|
||||
this.genres = data.genres || []
|
||||
|
|
|
@ -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