Skip to content

Commit

Permalink
Update:Book matches support lowercase letters in audible ASIN #2849
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Apr 16, 2024
1 parent 0f7c99d commit f0caf1a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions server/providers/Audible.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,19 @@ class Audible {
}
}

/**
* Test if a search title matches an ASIN. Supports lowercase letters
*
* @param {string} title
* @returns {boolean}
*/
isProbablyAsin(title) {
return /^[0-9A-Z]{10}$/.test(title)
return /^[0-9A-Za-z]{10}$/.test(title)
}

asinSearch(asin, region) {
asin = encodeURIComponent(asin)
if (!asin) return []
asin = encodeURIComponent(asin.toUpperCase())
var regionQuery = region ? `?region=${region}` : ''
var url = `https://api.audnex.us/books/${asin}${regionQuery}`
Logger.debug(`[Audible] ASIN url: ${url}`)
Expand Down Expand Up @@ -124,7 +131,7 @@ class Audible {
const url = `https://api.audible${tld}/1.0/catalog/products?${queryString}`
Logger.debug(`[Audible] Search url: ${url}`)
items = await axios.get(url).then((res) => {
if (!res || !res.data || !res.data.products) return null
if (!res?.data?.products) return null
return Promise.all(res.data.products.map(result => this.asinSearch(result.asin, region)))
}).catch(error => {
Logger.error('[Audible] query search error', error)
Expand Down

0 comments on commit f0caf1a

Please sign in to comment.