mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-08 02:11:35 +00:00
[Enhancement] Simple ratings from audible.com
This commit is contained in:
parent
0c7b738b7c
commit
831d50320c
13 changed files with 202 additions and 3 deletions
|
|
@ -97,6 +97,8 @@ class Book extends Model {
|
|||
this.isbn
|
||||
/** @type {string} */
|
||||
this.asin
|
||||
/** @type {number} */
|
||||
this.rating
|
||||
/** @type {string} */
|
||||
this.language
|
||||
/** @type {boolean} */
|
||||
|
|
@ -153,6 +155,7 @@ class Book extends Model {
|
|||
description: DataTypes.TEXT,
|
||||
isbn: DataTypes.STRING,
|
||||
asin: DataTypes.STRING,
|
||||
rating: DataTypes.FLOAT,
|
||||
language: DataTypes.STRING,
|
||||
explicit: DataTypes.BOOLEAN,
|
||||
abridged: DataTypes.BOOLEAN,
|
||||
|
|
@ -355,6 +358,7 @@ class Book extends Model {
|
|||
description: this.description,
|
||||
isbn: this.isbn,
|
||||
asin: this.asin,
|
||||
rating: this.rating,
|
||||
language: this.language,
|
||||
explicit: !!this.explicit,
|
||||
abridged: !!this.abridged
|
||||
|
|
@ -373,6 +377,27 @@ class Book extends Model {
|
|||
|
||||
if (payload.metadata) {
|
||||
const metadataStringKeys = ['title', 'subtitle', 'publishedYear', 'publishedDate', 'publisher', 'description', 'isbn', 'asin', 'language']
|
||||
if (payload.metadata.rating !== undefined) {
|
||||
let ratingValue = null
|
||||
if (payload.metadata.rating !== null) {
|
||||
if (typeof payload.metadata.rating === 'object' && payload.metadata.rating.average) {
|
||||
ratingValue = Number(payload.metadata.rating.average)
|
||||
} else {
|
||||
ratingValue = Number(payload.metadata.rating)
|
||||
}
|
||||
}
|
||||
// Treat 0 as null (no rating)
|
||||
if (ratingValue === 0) ratingValue = null
|
||||
if (ratingValue !== null && !isNaN(ratingValue) && ratingValue > 0) {
|
||||
if (this.rating !== ratingValue) {
|
||||
this.rating = ratingValue
|
||||
hasUpdates = true
|
||||
}
|
||||
} else if (ratingValue === null && this.rating !== null) {
|
||||
this.rating = null
|
||||
hasUpdates = true
|
||||
}
|
||||
}
|
||||
metadataStringKeys.forEach((key) => {
|
||||
if (typeof payload.metadata[key] == 'number') {
|
||||
payload.metadata[key] = String(payload.metadata[key])
|
||||
|
|
@ -567,6 +592,7 @@ class Book extends Model {
|
|||
description: this.description,
|
||||
isbn: this.isbn,
|
||||
asin: this.asin,
|
||||
rating: this.rating,
|
||||
language: this.language,
|
||||
explicit: this.explicit,
|
||||
abridged: this.abridged
|
||||
|
|
@ -589,6 +615,7 @@ class Book extends Model {
|
|||
description: this.description,
|
||||
isbn: this.isbn,
|
||||
asin: this.asin,
|
||||
rating: this.rating,
|
||||
language: this.language,
|
||||
explicit: this.explicit,
|
||||
abridged: this.abridged
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue