Cleaning up, adding readme and images, genre filter

This commit is contained in:
Mark Cooper 2021-08-19 17:29:36 -05:00
parent 53e46ff54d
commit 307b5b83a9
25 changed files with 269 additions and 65 deletions

View file

@ -28,6 +28,8 @@ class ApiController {
this.router.delete('/user/audiobook/:id', this.resetUserAudiobookProgress.bind(this))
this.router.post('/authorize', this.authorize.bind(this))
this.router.get('/genres', this.getGenres.bind(this))
}
find(req, res) {
@ -139,5 +141,11 @@ class ApiController {
this.emitter('user_updated', req.user.toJSONForBrowser())
res.sendStatus(200)
}
getGenres(req, res) {
res.json({
genres: this.db.getGenres()
})
}
}
module.exports = ApiController

View file

@ -57,6 +57,10 @@ class Audiobook {
return this.book ? this.book.author : 'Unknown'
}
get genres() {
return this.book ? this.book.genres || [] : []
}
get totalDuration() {
var total = 0
this.tracks.forEach((track) => total += track.duration)

View file

@ -8,7 +8,7 @@ class Book {
this.publisher = null
this.description = null
this.cover = null
this.genre = []
this.genres = []
if (book) {
this.construct(book)
@ -24,7 +24,7 @@ class Book {
this.publisher = book.publisher
this.description = book.description
this.cover = book.cover
this.genre = book.genre
this.genres = book.genres
}
toJSON() {
@ -37,7 +37,7 @@ class Book {
publisher: this.publisher,
description: this.description,
cover: this.cover,
genre: this.genre
genres: this.genres
}
}
@ -49,7 +49,7 @@ class Book {
this.publishYear = data.publish_year || null
this.description = data.description || null
this.cover = data.cover || null
this.genre = data.genre || []
this.genres = data.genres || []
}
update(payload) {
@ -57,12 +57,12 @@ class Book {
for (const key in payload) {
if (payload[key] === undefined) continue;
if (key === 'genre') {
if (payload['genre'] === null && this.genre !== null) {
this.genre = []
if (key === 'genres') {
if (payload['genres'] === null && this.genres !== null) {
this.genres = []
hasUpdates = true
} else if (payload['genre'].join(',') !== this.genre.join(',')) {
this.genre = payload['genre']
} else if (payload['genres'].join(',') !== this.genres.join(',')) {
this.genres = payload['genres']
hasUpdates = true
}
} else if (this[key] !== undefined && payload[key] !== this[key]) {

View file

@ -154,5 +154,23 @@ class Db {
Logger.error(`[DB] Remove entity ${entityName} Failed: ${error}`)
})
}
getGenres() {
var allGenres = []
this.db.audiobooks.forEach((audiobook) => {
allGenres = allGenres.concat(audiobook.genres)
})
allGenres = [...new Set(allGenres)] // Removes duplicates
return allGenres
}
getTags() {
var allTags = []
this.db.audiobooks.forEach((audiobook) => {
allTags = allTags.concat(audiobook.tags)
})
allTags = [...new Set(allTags)] // Removes duplicates
return allTags
}
}
module.exports = Db

View file

@ -106,12 +106,10 @@ async function scanParts(audiobook, parts) {
}
audiobook.audioFiles.push(audioFileObj)
var trackNumber = isNumber(trackNumFromMeta) ? trackNumFromMeta : trackNumFromFilename
if (trackNumber === null) {
if (parts.length === 1) {
// Only 1 track
trackNumber = 1
} else {
var trackNumber = 1
if (parts.length > 1) {
trackNumber = isNumber(trackNumFromMeta) ? trackNumFromMeta : trackNumFromFilename
if (trackNumber === null) {
Logger.error('Invalid track number for', parts[i])
audioFileObj.invalid = true
audioFileObj.error = 'Failed to get track number'
@ -136,6 +134,11 @@ async function scanParts(audiobook, parts) {
}
tracks.sort((a, b) => a.index - b.index)
audiobook.audioFiles.sort((a, b) => {
var aNum = isNumber(a.trackNumFromMeta) ? a.trackNumFromMeta : isNumber(a.trackNumFromFilename) ? a.trackNumFromFilename : 0
var bNum = isNumber(b.trackNumFromMeta) ? b.trackNumFromMeta : isNumber(b.trackNumFromFilename) ? b.trackNumFromFilename : 0
return aNum - bNum
})
// If first index is 0, increment all by 1
if (tracks[0].index === 0) {