mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-08 00:08:14 +01:00
Add:Region support for audible chapter lookup
This commit is contained in:
parent
067d90474b
commit
ce4e48cbd7
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<transition name="menu">
|
<transition name="menu">
|
||||||
<ul v-show="showMenu" class="absolute z-10 -mt-px w-full bg-primary border border-black-200 shadow-lg max-h-56 rounded-b-md py-1 ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm" tabindex="-1" role="listbox">
|
<ul v-show="showMenu" class="absolute z-10 -mt-px w-full bg-primary border border-black-200 shadow-lg max-h-56 rounded-b-md py-1 ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm" tabindex="-1" role="listbox">
|
||||||
<template v-for="item in items">
|
<template v-for="item in itemsToShow">
|
||||||
<li :key="item.value" class="text-gray-100 select-none relative py-2 cursor-pointer hover:bg-black-400" id="listbox-option-0" role="option" @click="clickedOption(item.value)">
|
<li :key="item.value" class="text-gray-100 select-none relative py-2 cursor-pointer hover:bg-black-400" id="listbox-option-0" role="option" @click="clickedOption(item.value)">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<span class="ml-3 block truncate font-sans text-sm" :class="{ 'font-semibold': item.subtext }">{{ item.text }}</span>
|
<span class="ml-3 block truncate font-sans text-sm" :class="{ 'font-semibold': item.subtext }">{{ item.text }}</span>
|
||||||
@ -62,8 +62,19 @@ export default {
|
|||||||
this.$emit('input', val)
|
this.$emit('input', val)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
itemsToShow() {
|
||||||
|
return this.items.map((i) => {
|
||||||
|
if (typeof i === 'string') {
|
||||||
|
return {
|
||||||
|
text: i,
|
||||||
|
value: i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
})
|
||||||
|
},
|
||||||
selectedItem() {
|
selectedItem() {
|
||||||
return this.items.find((i) => i.value === this.selected)
|
return this.itemsToShow.find((i) => i.value === this.selected)
|
||||||
},
|
},
|
||||||
selectedText() {
|
selectedText() {
|
||||||
return this.selectedItem ? this.selectedItem.text : ''
|
return this.selectedItem ? this.selectedItem.text : ''
|
||||||
|
@ -128,7 +128,8 @@
|
|||||||
<div class="w-full h-full max-h-full text-sm rounded-lg bg-bg shadow-lg border border-black-300 relative">
|
<div class="w-full h-full max-h-full text-sm rounded-lg bg-bg shadow-lg border border-black-300 relative">
|
||||||
<div v-if="!chapterData" class="flex p-20">
|
<div v-if="!chapterData" class="flex p-20">
|
||||||
<ui-text-input-with-label v-model="asinInput" label="ASIN" />
|
<ui-text-input-with-label v-model="asinInput" label="ASIN" />
|
||||||
<ui-btn small color="primary" class="mt-5 ml-2" @click="findChapters">Find</ui-btn>
|
<ui-dropdown v-model="regionInput" label="Region" small :items="audibleRegions" class="w-32 mx-1" />
|
||||||
|
<ui-btn small color="primary" class="mt-5" @click="findChapters">Find</ui-btn>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="w-full p-4">
|
<div v-else class="w-full p-4">
|
||||||
<div class="flex justify-between mb-4">
|
<div class="flex justify-between mb-4">
|
||||||
@ -218,10 +219,12 @@ export default {
|
|||||||
currentTrackIndex: 0,
|
currentTrackIndex: 0,
|
||||||
saving: false,
|
saving: false,
|
||||||
asinInput: null,
|
asinInput: null,
|
||||||
|
regionInput: 'US',
|
||||||
findingChapters: false,
|
findingChapters: false,
|
||||||
showFindChaptersModal: false,
|
showFindChaptersModal: false,
|
||||||
chapterData: null,
|
chapterData: null,
|
||||||
showSecondInputs: false
|
showSecondInputs: false,
|
||||||
|
audibleRegions: ['US', 'CA', 'UK', 'AU', 'FR', 'DE', 'JP', 'IT', 'IN', 'ES']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -475,10 +478,16 @@ export default {
|
|||||||
this.$toast.error('Must input an ASIN')
|
this.$toast.error('Must input an ASIN')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update local storage region
|
||||||
|
if (this.regionInput !== localStorage.getItem('audibleRegion')) {
|
||||||
|
localStorage.setItem('audibleRegion', this.regionInput)
|
||||||
|
}
|
||||||
|
|
||||||
this.findingChapters = true
|
this.findingChapters = true
|
||||||
this.chapterData = null
|
this.chapterData = null
|
||||||
this.$axios
|
this.$axios
|
||||||
.$get(`/api/search/chapters?asin=${this.asinInput}`)
|
.$get(`/api/search/chapters?asin=${this.asinInput}®ion=${this.regionInput}`)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
this.findingChapters = false
|
this.findingChapters = false
|
||||||
|
|
||||||
@ -499,6 +508,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
this.regionInput = localStorage.getItem('audibleRegion') || 'US'
|
||||||
this.asinInput = this.mediaMetadata.asin || null
|
this.asinInput = this.mediaMetadata.asin || null
|
||||||
this.newChapters = this.chapters.map((c) => ({ ...c }))
|
this.newChapters = this.chapters.map((c) => ({ ...c }))
|
||||||
if (!this.newChapters.length) {
|
if (!this.newChapters.length) {
|
||||||
|
@ -210,7 +210,8 @@ class MiscController {
|
|||||||
|
|
||||||
async findChapters(req, res) {
|
async findChapters(req, res) {
|
||||||
var asin = req.query.asin
|
var asin = req.query.asin
|
||||||
var chapterData = await this.bookFinder.findChapters(asin)
|
var region = (req.query.region || 'us').toLowerCase()
|
||||||
|
var chapterData = await this.bookFinder.findChapters(asin, region)
|
||||||
if (!chapterData) {
|
if (!chapterData) {
|
||||||
return res.json({ error: 'Chapters not found' })
|
return res.json({ error: 'Chapters not found' })
|
||||||
}
|
}
|
||||||
|
@ -209,8 +209,8 @@ class BookFinder {
|
|||||||
return covers
|
return covers
|
||||||
}
|
}
|
||||||
|
|
||||||
findChapters(asin) {
|
findChapters(asin, region) {
|
||||||
return this.audnexus.getChaptersByASIN(asin)
|
return this.audnexus.getChaptersByASIN(asin, region)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = BookFinder
|
module.exports = BookFinder
|
@ -59,12 +59,12 @@ class Audnexus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChaptersByASIN(asin) {
|
getChaptersByASIN(asin, region) {
|
||||||
Logger.debug(`[Audnexus] Get chapters for ASIN ${asin}`)
|
Logger.debug(`[Audnexus] Get chapters for ASIN ${asin}/${region}`)
|
||||||
return axios.get(`${this.baseUrl}/books/${asin}/chapters`).then((res) => {
|
return axios.get(`${this.baseUrl}/books/${asin}/chapters?region=${region}`).then((res) => {
|
||||||
return res.data
|
return res.data
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
Logger.error(`[Audnexus] Chapter ASIN request failed for ${asin}`, error)
|
Logger.error(`[Audnexus] Chapter ASIN request failed for ${asin}/${region}`, error)
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user