mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-04 18:24:46 +02:00
Added ASIN support in the title field
This commit is contained in:
parent
9423727f89
commit
059d6d96a7
2 changed files with 23 additions and 1 deletions
|
@ -34,7 +34,29 @@ class Audible {
|
|||
return (series && series.length > 0) ? series.find((s) => s.title == publication_name) || series[0] : null
|
||||
}
|
||||
|
||||
isProbablyAsin(title) {
|
||||
return /[0-9A-Z]{10}/.test(title)
|
||||
}
|
||||
|
||||
async 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 await 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) {
|
||||
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` +
|
||||
`&image_sizes=500,1024,2000&num_results=25&products_sort_by=Relevance&title=${title}`;
|
||||
if (author) queryString += `&author=${author}`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue