From f0caf1a93390523beae012e491ff1ea77d6710d1 Mon Sep 17 00:00:00 2001 From: advplyr Date: Tue, 16 Apr 2024 16:39:57 -0500 Subject: [PATCH] Update:Book matches support lowercase letters in audible ASIN #2849 --- server/providers/Audible.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/providers/Audible.js b/server/providers/Audible.js index de98f67b..97fea620 100644 --- a/server/providers/Audible.js +++ b/server/providers/Audible.js @@ -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}`) @@ -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)