bit more clean up

This commit is contained in:
danny.rich 2025-11-03 17:26:43 -05:00
parent 7377f6adaa
commit 35862aec9b
2 changed files with 11 additions and 16 deletions

View File

@ -475,6 +475,7 @@ export default {
explicit: true, explicit: true,
asin: true, asin: true,
isbn: true, isbn: true,
rating: true,
abridged: true, abridged: true,
// Podcast specific // Podcast specific
itunesPageUrl: true, itunesPageUrl: true,
@ -585,16 +586,6 @@ export default {
var updatePayload = {} var updatePayload = {}
updatePayload.metadata = {} updatePayload.metadata = {}
// Always include rating if it exists in the match
if (this.selectedMatch?.rating !== undefined && this.selectedMatch?.rating !== null) {
const ratingValue = Number(this.selectedMatch.rating)
if (!isNaN(ratingValue) && ratingValue > 0) {
updatePayload.metadata.rating = ratingValue
} else if (ratingValue === 0 || isNaN(ratingValue)) {
updatePayload.metadata.rating = undefined
}
}
for (const key in this.selectedMatchUsage) { for (const key in this.selectedMatchUsage) {
if (this.selectedMatchUsage[key] && this.selectedMatch[key] !== undefined && this.selectedMatch[key] !== null) { if (this.selectedMatchUsage[key] && this.selectedMatch[key] !== undefined && this.selectedMatch[key] !== null) {
if (key === 'series') { if (key === 'series') {
@ -636,9 +627,11 @@ export default {
} else if (key === 'itunesId') { } else if (key === 'itunesId') {
updatePayload.metadata.itunesId = Number(this.selectedMatch[key]) updatePayload.metadata.itunesId = Number(this.selectedMatch[key])
} else if (key === 'rating') { } else if (key === 'rating') {
const ratingValue = typeof this.selectedMatch[key] === 'object' && this.selectedMatch[key].average ? this.selectedMatch[key].average : Number(this.selectedMatch[key]) const ratingValue = Number(this.selectedMatch[key])
if (!isNaN(ratingValue) && ratingValue > 0) { if (!isNaN(ratingValue) && ratingValue > 0) {
updatePayload.metadata.rating = ratingValue updatePayload.metadata.rating = ratingValue
} else if (ratingValue === 0 || isNaN(ratingValue)) {
updatePayload.metadata.rating = undefined
} }
} else { } else {
updatePayload.metadata[key] = this.selectedMatch[key] updatePayload.metadata[key] = this.selectedMatch[key]

View File

@ -231,15 +231,17 @@ class Scanner {
updatePayload[key] = tagsArray updatePayload[key] = tagsArray
} }
} else if (key === 'rating') { } else if (key === 'rating') {
// Normalize rating: convert object with average to number, or number to number // Normalize rating (handle object format {average: 4.5} from some providers)
let ratingValue = matchData[key] let ratingValue = matchData[key]
if (ratingValue && typeof ratingValue === 'object' && ratingValue.average) { if (ratingValue && typeof ratingValue === 'object' && ratingValue.average) {
ratingValue = Number(ratingValue.average) || null ratingValue = Number(ratingValue.average)
} else if (ratingValue !== undefined && ratingValue !== null) { } else if (ratingValue !== undefined && ratingValue !== null) {
ratingValue = Number(ratingValue) || null ratingValue = Number(ratingValue)
} else {
ratingValue = null
} }
if (ratingValue === 0) ratingValue = null // 0 = no rating, only update if valid rating > 0
if ((!libraryItem.media.rating || options.overrideDetails) && ratingValue !== null && !isNaN(ratingValue) && ratingValue > 0) { if (ratingValue !== null && !isNaN(ratingValue) && ratingValue > 0 && (!libraryItem.media.rating || options.overrideDetails)) {
updatePayload[key] = ratingValue updatePayload[key] = ratingValue
} else if (ratingValue === null && libraryItem.media.rating && options.overrideDetails) { } else if (ratingValue === null && libraryItem.media.rating && options.overrideDetails) {
updatePayload[key] = null updatePayload[key] = null