mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-03 17:54:54 +02:00
Parse and update author name on each update
This commit is contained in:
parent
6ca7e9e6a6
commit
81487d1dba
9 changed files with 65 additions and 41 deletions
|
@ -310,10 +310,6 @@ class Audiobook {
|
|||
return hasUpdates
|
||||
}
|
||||
|
||||
syncAuthorNames(audiobookData) {
|
||||
return this.book.syncAuthorNames(audiobookData.authorFL, audiobookData.authorLF)
|
||||
}
|
||||
|
||||
isSearchMatch(search) {
|
||||
return this.book.isSearchMatch(search.toLowerCase().trim())
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
const Path = require('path')
|
||||
const Logger = require('./Logger')
|
||||
const parseAuthors = require('./utils/parseAuthors')
|
||||
class Book {
|
||||
constructor(book = null) {
|
||||
this.olid = null
|
||||
|
@ -55,12 +57,29 @@ class Book {
|
|||
}
|
||||
}
|
||||
|
||||
setParseAuthor(author) {
|
||||
if (!author) {
|
||||
var hasUpdated = this.authorFL || this.authorLF
|
||||
this.authorFL = null
|
||||
this.authorLF = null
|
||||
return hasUpdated
|
||||
}
|
||||
try {
|
||||
var { authorLF, authorFL } = parseAuthors(author)
|
||||
var hasUpdated = authorLF !== this.authorLF || authorFL !== this.authorFL
|
||||
this.authorFL = authorFL || null
|
||||
this.authorLF = authorLF || null
|
||||
return hasUpdated
|
||||
} catch (err) {
|
||||
Logger.error('[Book] Parse authors failed', err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
setData(data) {
|
||||
this.olid = data.olid || null
|
||||
this.title = data.title || null
|
||||
this.author = data.author || null
|
||||
this.authorLF = data.authorLF || null
|
||||
this.authorFL = data.authorFL || null
|
||||
this.series = data.series || null
|
||||
this.volumeNumber = data.volumeNumber || null
|
||||
this.publishYear = data.publishYear || null
|
||||
|
@ -68,6 +87,10 @@ class Book {
|
|||
this.cover = data.cover || null
|
||||
this.genres = data.genres || []
|
||||
|
||||
if (data.author) {
|
||||
this.setParseAuthor(this.author)
|
||||
}
|
||||
|
||||
// Use first image file as cover
|
||||
if (data.otherFiles && data.otherFiles.length) {
|
||||
var imageFile = data.otherFiles.find(f => f.filetype === 'image')
|
||||
|
@ -90,6 +113,14 @@ class Book {
|
|||
this.genres = payload['genres']
|
||||
hasUpdates = true
|
||||
}
|
||||
} else if (key === 'author') {
|
||||
if (this.author !== payload.author) {
|
||||
this.author = payload.author || null
|
||||
hasUpdates = true
|
||||
}
|
||||
if (this.setParseAuthor(this.author)) {
|
||||
hasUpdates = true
|
||||
}
|
||||
} else if (this[key] !== undefined && payload[key] !== this[key]) {
|
||||
this[key] = payload[key]
|
||||
hasUpdates = true
|
||||
|
@ -98,19 +129,6 @@ class Book {
|
|||
return hasUpdates
|
||||
}
|
||||
|
||||
syncAuthorNames(authorFL, authorLF) {
|
||||
var hasUpdates = false
|
||||
if (authorFL !== this.authorFL) {
|
||||
this.authorFL = authorFL
|
||||
hasUpdates = true
|
||||
}
|
||||
if (authorLF !== this.authorLF) {
|
||||
this.authorLF = authorLF
|
||||
hasUpdates = true
|
||||
}
|
||||
return hasUpdates
|
||||
}
|
||||
|
||||
isSearchMatch(search) {
|
||||
return this._title.toLowerCase().includes(search) || this._author.toLowerCase().includes(search) || this._series.toLowerCase().includes(search)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
const Path = require('path')
|
||||
const Logger = require('./Logger')
|
||||
const BookFinder = require('./BookFinder')
|
||||
const Audiobook = require('./Audiobook')
|
||||
|
@ -120,11 +119,6 @@ class Scanner {
|
|||
hasUpdates = true
|
||||
}
|
||||
|
||||
if (audiobookData.author && existingAudiobook.syncAuthorNames(audiobookData)) {
|
||||
Logger.info(`[Scanner] "${existingAudiobook.title}" author names updated, "${existingAudiobook.authorLF}"`)
|
||||
hasUpdates = true
|
||||
}
|
||||
|
||||
if (hasUpdates) {
|
||||
Logger.info(`[Scanner] "${existingAudiobook.title}" was updated - saving`)
|
||||
existingAudiobook.lastUpdate = Date.now()
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
const Path = require('path')
|
||||
const dir = require('node-dir')
|
||||
const Logger = require('../Logger')
|
||||
const parseAuthors = require('./parseAuthors')
|
||||
const { cleanString } = require('./index')
|
||||
|
||||
const AUDIOBOOK_PARTS_FORMATS = ['m4b', 'mp3']
|
||||
|
@ -75,14 +74,6 @@ async function getAllAudiobookFiles(abRootPath) {
|
|||
parts: [],
|
||||
otherFiles: []
|
||||
}
|
||||
if (author) {
|
||||
var parsedAuthors = parseAuthors(author)
|
||||
if (parsedAuthors) {
|
||||
var { authorLF, authorFL } = parsedAuthors
|
||||
audiobooks[path].authorLF = authorLF || null
|
||||
audiobooks[path].authorFL = authorFL || null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var filetype = getFileType(pathformat.ext)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue