From 059d6d96a7e06fa05bc29035315c6c5cd91f0876 Mon Sep 17 00:00:00 2001 From: Keagan Hilliard Date: Tue, 7 Dec 2021 10:27:30 -0800 Subject: [PATCH 1/2] Added ASIN support in the title field --- client/components/modals/edit-tabs/Match.vue | 2 +- server/providers/Audible.js | 22 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/client/components/modals/edit-tabs/Match.vue b/client/components/modals/edit-tabs/Match.vue index 7bbdc0e2..b0667b13 100644 --- a/client/components/modals/edit-tabs/Match.vue +++ b/client/components/modals/edit-tabs/Match.vue @@ -6,7 +6,7 @@
- +
diff --git a/server/providers/Audible.js b/server/providers/Audible.js index c617614e..e601d05e 100644 --- a/server/providers/Audible.js +++ b/server/providers/Audible.js @@ -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}` From 2b3688b141f1a0446befda18e596ccd5daebe4a7 Mon Sep 17 00:00:00 2001 From: advplyr Date: Tue, 7 Dec 2021 18:10:56 -0600 Subject: [PATCH 2/2] Update async function, update debug log --- server/BookFinder.js | 2 +- server/providers/Audible.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/BookFinder.js b/server/BookFinder.js index 538ae377..6ad856a0 100644 --- a/server/BookFinder.js +++ b/server/BookFinder.js @@ -169,7 +169,7 @@ class BookFinder { var books = [] var maxTitleDistance = !isNaN(options.titleDistance) ? Number(options.titleDistance) : 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') { return this.getGoogleBooksResults(title, author, maxTitleDistance, maxAuthorDistance) diff --git a/server/providers/Audible.js b/server/providers/Audible.js index e601d05e..36484b7d 100644 --- a/server/providers/Audible.js +++ b/server/providers/Audible.js @@ -38,12 +38,12 @@ class Audible { return /[0-9A-Z]{10}/.test(title) } - async asinSearch(asin) { + asinSearch(asin) { var queryString = `response_groups=rating,series,contributors,product_desc,media,product_extended_attrs` + - `&image_sizes=500,1024,2000`; + `&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) => { + return axios.get(url).then((res) => { if (!res || !res.data || !res.data.product) return [] return [res.data.product] }).catch(error => { @@ -56,7 +56,7 @@ class Audible { 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}`