Merge pull request #226 from keaganhilliard/master

Added ASIN support in the title field
This commit is contained in:
advplyr 2021-12-07 18:11:32 -06:00 committed by GitHub
commit 9548be7075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -6,7 +6,7 @@
<ui-dropdown v-model="provider" :items="providers" label="Provider" small /> <ui-dropdown v-model="provider" :items="providers" label="Provider" small />
</div> </div>
<div class="w-72 px-1"> <div class="w-72 px-1">
<ui-text-input-with-label v-model="searchTitle" label="Search Title" placeholder="Search" /> <ui-text-input-with-label v-model="searchTitle" :label="provider == 'audible' ? 'Search Title or ASIN' : 'Search Title'" placeholder="Search" />
</div> </div>
<div class="w-72 px-1"> <div class="w-72 px-1">
<ui-text-input-with-label v-model="searchAuthor" label="Author" /> <ui-text-input-with-label v-model="searchAuthor" label="Author" />

View File

@ -169,7 +169,7 @@ class BookFinder {
var books = [] var books = []
var maxTitleDistance = !isNaN(options.titleDistance) ? Number(options.titleDistance) : 4 var maxTitleDistance = !isNaN(options.titleDistance) ? Number(options.titleDistance) : 4
var maxAuthorDistance = !isNaN(options.authorDistance) ? Number(options.authorDistance) : 4 var maxAuthorDistance = !isNaN(options.authorDistance) ? Number(options.authorDistance) : 4
Logger.debug(`Cover Search: title: "${title}", author: "${author}", provider: ${provider}`) Logger.debug(`Book Search: title: "${title}", author: "${author}", provider: ${provider}`)
if (provider === 'google') { if (provider === 'google') {
return this.getGoogleBooksResults(title, author, maxTitleDistance, maxAuthorDistance) return this.getGoogleBooksResults(title, author, maxTitleDistance, maxAuthorDistance)

View File

@ -34,7 +34,29 @@ class Audible {
return (series && series.length > 0) ? series.find((s) => s.title == publication_name) || series[0] : null return (series && series.length > 0) ? series.find((s) => s.title == publication_name) || series[0] : null
} }
isProbablyAsin(title) {
return /[0-9A-Z]{10}/.test(title)
}
asinSearch(asin) {
var queryString = `response_groups=rating,series,contributors,product_desc,media,product_extended_attrs` +
`&image_sizes=500,1024,2000`;
var url = `https://api.audible.com/1.0/catalog/products/${asin}?${queryString}`
Logger.debug(`[Audible] ASIN url: ${url}`)
return axios.get(url).then((res) => {
if (!res || !res.data || !res.data.product) return []
return [res.data.product]
}).catch(error => {
Logger.error('[Audible] search error', error)
return []
})
}
async search(title, author) { async search(title, author) {
if (this.isProbablyAsin(title)) {
var items = await this.asinSearch(title)
if (items.length > 0) return items.map(item => this.cleanResult(item))
}
var queryString = `response_groups=rating,series,contributors,product_desc,media,product_extended_attrs` + var queryString = `response_groups=rating,series,contributors,product_desc,media,product_extended_attrs` +
`&image_sizes=500,1024,2000&num_results=25&products_sort_by=Relevance&title=${title}`; `&image_sizes=500,1024,2000&num_results=25&products_sort_by=Relevance&title=${title}`;
if (author) queryString += `&author=${author}` if (author) queryString += `&author=${author}`