[Enhancement] Simple ratings from audible.com

This commit is contained in:
danny.rich 2025-11-03 13:46:51 -05:00
parent 0c7b738b7c
commit 831d50320c
13 changed files with 202 additions and 3 deletions

View file

@ -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