mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 18:01:42 +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
|
|
@ -18,6 +18,10 @@
|
|||
<div>
|
||||
<p v-if="book.author" class="text-gray-300 text-xs md:text-sm">{{ $getString('LabelByAuthor', [book.author]) }}</p>
|
||||
<p v-if="book.narrator" class="text-gray-400 text-xs">{{ $strings.LabelNarrators }}: {{ book.narrator }}</p>
|
||||
<div v-if="bookRatingValue > 0" class="flex items-center text-xs text-gray-400 mt-0.5">
|
||||
<span v-for="i in 5" :key="i" class="material-symbols text-xs mr-0.5" :class="bookRatingValue >= i - 0.5 ? 'text-warning fill' : 'text-gray-500'">{{ bookRatingValue >= i ? 'star' : bookRatingValue >= i - 0.5 ? 'star_half' : 'star_border' }}</span>
|
||||
<span class="ml-1">{{ bookRatingValue.toFixed(1) }}</span>
|
||||
</div>
|
||||
<p v-if="book.duration" class="text-gray-400 text-xs">{{ $strings.LabelDuration }}: {{ $elapsedPrettyExtended(bookDuration, false) }} {{ bookDurationComparison }}</p>
|
||||
</div>
|
||||
<div class="grow" />
|
||||
|
|
@ -88,7 +92,19 @@ export default {
|
|||
return this.$getString('LabelDurationComparisonShorter', [this.$elapsedPrettyExtended(differenceInMinutes * 60, false, false)])
|
||||
}
|
||||
return this.$strings.LabelDurationComparisonExactMatch
|
||||
}
|
||||
},
|
||||
bookRatingValue() {
|
||||
if (!this.book.rating) return 0
|
||||
if (typeof this.book.rating === 'string') {
|
||||
const num = Number(this.book.rating)
|
||||
return isNaN(num) ? 0 : num
|
||||
}
|
||||
if (typeof this.book.rating === 'object' && this.book.rating.average) {
|
||||
return Number(this.book.rating.average) || 0
|
||||
}
|
||||
const num = Number(this.book.rating)
|
||||
return isNaN(num) ? 0 : num
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
selectMatch() {
|
||||
|
|
|
|||
|
|
@ -349,6 +349,13 @@ export default {
|
|||
if (this.mediaMetadata.publishedYear) return this.$getString('LabelPublishedDate', [this.mediaMetadata.publishedYear])
|
||||
return '\u00A0'
|
||||
}
|
||||
if (this.orderBy === 'media.metadata.rating') {
|
||||
if (this.mediaMetadata.rating) {
|
||||
const ratingValue = typeof this.mediaMetadata.rating === 'object' && this.mediaMetadata.rating.average ? this.mediaMetadata.rating.average : Number(this.mediaMetadata.rating)
|
||||
if (!isNaN(ratingValue) && ratingValue > 0) return `Rating: ${ratingValue.toFixed(1)}`
|
||||
}
|
||||
return '\u00A0'
|
||||
}
|
||||
if (this.orderBy === 'progress') {
|
||||
if (!this.userProgressLastUpdated) return '\u00A0'
|
||||
return this.$getString('LabelLastProgressDate', [this.$formatDatetime(this.userProgressLastUpdated, this.dateFormat, this.timeFormat)])
|
||||
|
|
|
|||
|
|
@ -110,6 +110,10 @@ export default {
|
|||
text: this.$strings.LabelPublishYear,
|
||||
value: 'media.metadata.publishedYear'
|
||||
},
|
||||
{
|
||||
text: 'Rating',
|
||||
value: 'media.metadata.rating'
|
||||
},
|
||||
{
|
||||
text: this.$strings.LabelAddedAt,
|
||||
value: 'addedAt'
|
||||
|
|
|
|||
|
|
@ -174,6 +174,16 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="selectedMatchOrig.rating" class="flex items-center py-2">
|
||||
<ui-checkbox v-model="selectedMatchUsage.rating" checkbox-bg="bg" @input="checkboxToggled" />
|
||||
<div class="grow ml-4">
|
||||
<ui-text-input-with-label v-model="selectedMatch.rating" type="number" step="0.1" min="0" max="5" :disabled="!selectedMatchUsage.rating" label="Rating" />
|
||||
<p v-if="mediaMetadata.rating" class="text-xs ml-1 text-white/60">
|
||||
{{ $strings.LabelCurrently }} <a :title="$strings.LabelClickToUseCurrentValue" class="cursor-pointer hover:underline" @click.stop="setMatchFieldValue('rating', typeof mediaMetadata.rating === 'object' && mediaMetadata.rating.average ? mediaMetadata.rating.average : Number(mediaMetadata.rating))">{{ typeof mediaMetadata.rating === 'object' && mediaMetadata.rating.average ? mediaMetadata.rating.average.toFixed(1) : Number(mediaMetadata.rating).toFixed(1) }}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="selectedMatchOrig.itunesId" class="flex items-center py-2">
|
||||
<ui-checkbox v-model="selectedMatchUsage.itunesId" checkbox-bg="bg" @input="checkboxToggled" />
|
||||
<div class="grow ml-4">
|
||||
|
|
@ -270,6 +280,7 @@ export default {
|
|||
explicit: true,
|
||||
asin: true,
|
||||
isbn: true,
|
||||
rating: true,
|
||||
abridged: true,
|
||||
// Podcast specific
|
||||
itunesPageUrl: true,
|
||||
|
|
@ -559,6 +570,11 @@ export default {
|
|||
if (match.narrator && !Array.isArray(match.narrator)) {
|
||||
match.narrator = match.narrator.split(',').map((g) => g.trim())
|
||||
}
|
||||
if (match.rating && typeof match.rating === 'object' && match.rating.average) {
|
||||
match.rating = Number(match.rating.average) || null
|
||||
} else if (match.rating !== undefined && match.rating !== null) {
|
||||
match.rating = Number(match.rating) || null
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Select Match', match)
|
||||
|
|
@ -569,8 +585,19 @@ export default {
|
|||
var updatePayload = {}
|
||||
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)) {
|
||||
// Set to null to remove rating
|
||||
updatePayload.metadata.rating = null
|
||||
}
|
||||
}
|
||||
|
||||
for (const key in this.selectedMatchUsage) {
|
||||
if (this.selectedMatchUsage[key] && this.selectedMatch[key]) {
|
||||
if (this.selectedMatchUsage[key] && this.selectedMatch[key] !== undefined && this.selectedMatch[key] !== null) {
|
||||
if (key === 'series') {
|
||||
if (!Array.isArray(this.selectedMatch[key])) {
|
||||
console.error('Invalid series in selectedMatch', this.selectedMatch[key])
|
||||
|
|
@ -609,6 +636,11 @@ export default {
|
|||
updatePayload.tags = this.selectedMatch[key]
|
||||
} else if (key === 'itunesId') {
|
||||
updatePayload.metadata.itunesId = Number(this.selectedMatch[key])
|
||||
} else if (key === 'rating') {
|
||||
const ratingValue = typeof this.selectedMatch[key] === 'object' && this.selectedMatch[key].average ? this.selectedMatch[key].average : Number(this.selectedMatch[key])
|
||||
if (!isNaN(ratingValue) && ratingValue > 0) {
|
||||
updatePayload.metadata.rating = ratingValue
|
||||
}
|
||||
} else {
|
||||
updatePayload.metadata[key] = this.selectedMatch[key]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<em v-if="note" class="font-normal text-xs pl-2">{{ note }}</em>
|
||||
</label>
|
||||
</slot>
|
||||
<ui-text-input :placeholder="placeholder || label" :inputId="identifier" ref="input" v-model="inputValue" :disabled="disabled" :readonly="readonly" :type="type" :min="min" :show-copy="showCopy" class="w-full" :class="inputClass" :trim-whitespace="trimWhitespace" @blur="inputBlurred" />
|
||||
<ui-text-input :placeholder="placeholder || label" :inputId="identifier" ref="input" v-model="inputValue" :disabled="disabled" :readonly="readonly" :type="type" :min="min" :step="step || undefined" :max="max || undefined" :show-copy="showCopy" class="w-full" :class="inputClass" :trim-whitespace="trimWhitespace" @blur="inputBlurred" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
@ -22,6 +22,8 @@ export default {
|
|||
default: 'text'
|
||||
},
|
||||
min: [String, Number],
|
||||
max: [String, Number],
|
||||
step: [String, Number],
|
||||
readonly: Boolean,
|
||||
disabled: Boolean,
|
||||
inputClass: String,
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@
|
|||
<div class="w-1/2 md:w-1/4 px-1 mt-2 md:mt-0">
|
||||
<ui-text-input-with-label ref="asinInput" v-model="details.asin" label="ASIN" trim-whitespace @input="handleInputChange" />
|
||||
</div>
|
||||
<div class="w-1/2 md:w-1/4 px-1 mt-2 md:mt-0">
|
||||
<ui-text-input-with-label ref="ratingInput" v-model="details.rating" type="number" step="0.1" min="0" max="5" label="Rating" @input="handleInputChange" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap mt-2 -mx-1">
|
||||
|
|
@ -93,6 +96,7 @@ export default {
|
|||
language: null,
|
||||
isbn: null,
|
||||
asin: null,
|
||||
rating: null,
|
||||
genres: [],
|
||||
explicit: false,
|
||||
abridged: false
|
||||
|
|
@ -187,6 +191,7 @@ export default {
|
|||
if (this.$refs.descriptionInput) this.$refs.descriptionInput.blur()
|
||||
if (this.$refs.isbnInput) this.$refs.isbnInput.blur()
|
||||
if (this.$refs.asinInput) this.$refs.asinInput.blur()
|
||||
if (this.$refs.ratingInput) this.$refs.ratingInput.blur()
|
||||
if (this.$refs.publisherInput) this.$refs.publisherInput.blur()
|
||||
if (this.$refs.languageInput) this.$refs.languageInput.blur()
|
||||
|
||||
|
|
@ -242,6 +247,10 @@ export default {
|
|||
for (const key in this.details) {
|
||||
var newValue = this.details[key]
|
||||
var oldValue = this.mediaMetadata[key]
|
||||
// Convert rating 0 to null
|
||||
if (key === 'rating' && newValue === 0) {
|
||||
newValue = null
|
||||
}
|
||||
// Key cleared out or key first populated
|
||||
if ((!newValue && oldValue) || (newValue && !oldValue)) {
|
||||
metadata[key] = newValue
|
||||
|
|
@ -254,6 +263,11 @@ export default {
|
|||
if (!this.objectArrayEqual(newValue, oldValue)) {
|
||||
metadata[key] = newValue.map((v) => ({ ...v }))
|
||||
}
|
||||
} else if (key === 'rating') {
|
||||
// Always check rating changes, even if null
|
||||
if (newValue != oldValue) {
|
||||
metadata[key] = newValue
|
||||
}
|
||||
} else if (newValue && newValue != oldValue) {
|
||||
// Intentional !=
|
||||
metadata[key] = newValue
|
||||
|
|
@ -283,6 +297,12 @@ export default {
|
|||
this.details.language = this.mediaMetadata.language || null
|
||||
this.details.isbn = this.mediaMetadata.isbn || null
|
||||
this.details.asin = this.mediaMetadata.asin || null
|
||||
if (this.mediaMetadata.rating) {
|
||||
const ratingValue = typeof this.mediaMetadata.rating === 'object' && this.mediaMetadata.rating.average ? this.mediaMetadata.rating.average : Number(this.mediaMetadata.rating)
|
||||
this.details.rating = !isNaN(ratingValue) && ratingValue > 0 ? ratingValue : null
|
||||
} else {
|
||||
this.details.rating = null
|
||||
}
|
||||
this.details.explicit = !!this.mediaMetadata.explicit
|
||||
this.details.abridged = !!this.mediaMetadata.abridged
|
||||
this.newTags = [...(this.media.tags || [])]
|
||||
|
|
|
|||
|
|
@ -45,6 +45,11 @@
|
|||
</p>
|
||||
<p v-else class="mb-2 mt-0.5 text-gray-200 text-xl">by Unknown</p>
|
||||
|
||||
<div v-if="ratingValue > 0 && !isPodcast" class="flex items-center mb-2 mt-1">
|
||||
<span v-for="i in 5" :key="i" class="material-symbols text-sm mr-0.5" :class="ratingValue >= i - 0.5 ? 'text-warning fill' : 'text-gray-500'">{{ ratingValue >= i ? 'star' : ratingValue >= i - 0.5 ? 'star_half' : 'star_border' }}</span>
|
||||
<span class="ml-1 text-gray-300">{{ ratingValue.toFixed(1) }}</span>
|
||||
</div>
|
||||
|
||||
<content-library-item-details :library-item="libraryItem" />
|
||||
</div>
|
||||
<div class="hidden md:block grow" />
|
||||
|
|
@ -280,6 +285,17 @@ export default {
|
|||
authors() {
|
||||
return this.mediaMetadata.authors || []
|
||||
},
|
||||
asin() {
|
||||
return this.mediaMetadata?.asin || null
|
||||
},
|
||||
rating() {
|
||||
return this.mediaMetadata?.rating || null
|
||||
},
|
||||
ratingValue() {
|
||||
if (!this.rating) return 0
|
||||
const value = typeof this.rating === 'object' && this.rating.average ? this.rating.average : Number(this.rating)
|
||||
return isNaN(value) || value <= 0 ? 0 : value
|
||||
},
|
||||
series() {
|
||||
return this.mediaMetadata.series || []
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue