From f9ed412e4e47a781b7febdbfa1c2b250b4414f12 Mon Sep 17 00:00:00 2001 From: Spenser Bushey Date: Wed, 19 Apr 2023 22:13:52 -0700 Subject: [PATCH 1/3] Add AudiobookCovers.com metadata provider AudiobookCovers.com acts as a cover-only metadata provider, therefore will only show up in the covers selector. --- client/components/modals/item/tabs/Cover.vue | 6 ++--- client/store/scanners.js | 6 +++++ server/finders/BookFinder.js | 16 ++++++++++++ server/providers/AudiobookCovers.js | 26 ++++++++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 server/providers/AudiobookCovers.js diff --git a/client/components/modals/item/tabs/Cover.vue b/client/components/modals/item/tabs/Cover.vue index 3cbad218..42931744 100644 --- a/client/components/modals/item/tabs/Cover.vue +++ b/client/components/modals/item/tabs/Cover.vue @@ -49,13 +49,13 @@
-
+
-
+
{{ $strings.ButtonSearch }} @@ -128,7 +128,7 @@ export default { }, providers() { if (this.isPodcast) return this.$store.state.scanners.podcastProviders - return this.$store.state.scanners.providers + return [...this.$store.state.scanners.providers, ...this.$store.state.scanners.coverOnlyProviders] }, searchTitleLabel() { if (this.provider.startsWith('audible')) return this.$strings.LabelSearchTitleOrASIN diff --git a/client/store/scanners.js b/client/store/scanners.js index 0a339a03..9a330f4f 100644 --- a/client/store/scanners.js +++ b/client/store/scanners.js @@ -63,6 +63,12 @@ export const state = () => ({ text: 'iTunes', value: 'itunes' } + ], + coverOnlyProviders: [ + { + text: 'AudiobookCovers.com', + value: 'audiobookcovers' + } ] }) diff --git a/server/finders/BookFinder.js b/server/finders/BookFinder.js index a7d5b730..7716301f 100644 --- a/server/finders/BookFinder.js +++ b/server/finders/BookFinder.js @@ -4,6 +4,7 @@ const Audible = require('../providers/Audible') const iTunes = require('../providers/iTunes') const Audnexus = require('../providers/Audnexus') const FantLab = require('../providers/FantLab') +const AudiobookCovers = require('../providers/AudiobookCovers') const Logger = require('../Logger') const { levenshteinDistance } = require('../utils/index') @@ -15,6 +16,7 @@ class BookFinder { this.iTunesApi = new iTunes() this.audnexus = new Audnexus() this.fantLab = new FantLab() + this.audiobookCovers = new AudiobookCovers() this.verbose = false } @@ -159,6 +161,16 @@ class BookFinder { return books } + async getAudiobookCoversResults(search) { + const covers = await this.audiobookCovers.search(search) + if (this.verbose) Logger.debug(`AudiobookCovers Book Search Results: ${books.length || 0}`) + if (covers.errorCode) { + Logger.error(`AusiobookCovers Search Error ${books.errorCode}`) + return [] + } + return covers + } + async getiTunesAudiobooksResults(title, author) { return this.iTunesApi.searchAudiobooks(title) } @@ -187,11 +199,15 @@ class BookFinder { books = await this.getOpenLibResults(title, author, maxTitleDistance, maxAuthorDistance) } else if (provider === 'fantlab') { books = await this.getFantLabResults(title, author) + } else if (provider === 'audiobookcovers') { + books = await this.getAudiobookCoversResults(title) } else { books = await this.getGoogleBooksResults(title, author) } + console.log(books) + if (!books.length && !options.currentlyTryingCleaned) { var cleanedTitle = this.cleanTitleForCompares(title) var cleanedAuthor = this.cleanAuthorForCompares(author) diff --git a/server/providers/AudiobookCovers.js b/server/providers/AudiobookCovers.js new file mode 100644 index 00000000..b969fba3 --- /dev/null +++ b/server/providers/AudiobookCovers.js @@ -0,0 +1,26 @@ +const axios = require('axios') +const Logger = require('../Logger') + +class AudiobookCovers { + constructor() { } + + async search(search) { + const url = `https://api.audiobookcovers.com/cover/bytext/` + const params = new URLSearchParams([['q', search]]) + const items = await axios.get(url, { params }).then((res) => { + if (!res || !res.data) return [] + return res.data + }).catch(error => { + Logger.error('[AudiobookCovers] Cover search error', error) + return [] + }) + // console.log(items) + // return items as an array of objects, each object contains: + // cover: item.filename + return items.map(item => { return { cover: item.filename } }) + } +} + + + +module.exports = AudiobookCovers From 134289785833548c5468643990f95542a9d8d57a Mon Sep 17 00:00:00 2001 From: Spenser Bushey Date: Thu, 20 Apr 2023 16:39:04 -0700 Subject: [PATCH 2/3] Removed useless comments --- server/providers/AudiobookCovers.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/server/providers/AudiobookCovers.js b/server/providers/AudiobookCovers.js index b969fba3..ea03a9d2 100644 --- a/server/providers/AudiobookCovers.js +++ b/server/providers/AudiobookCovers.js @@ -14,9 +14,6 @@ class AudiobookCovers { Logger.error('[AudiobookCovers] Cover search error', error) return [] }) - // console.log(items) - // return items as an array of objects, each object contains: - // cover: item.filename return items.map(item => { return { cover: item.filename } }) } } From 84839bea44e85fdaecdd3e6b56bf9d7ff37f1066 Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 21 Apr 2023 16:17:52 -0500 Subject: [PATCH 3/3] Cleanup audiobookcovers.com addition --- client/components/modals/item/tabs/Cover.vue | 2 +- server/finders/BookFinder.js | 20 ++++++++------------ server/providers/AudiobookCovers.js | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/client/components/modals/item/tabs/Cover.vue b/client/components/modals/item/tabs/Cover.vue index 42931744..ab63c7e8 100644 --- a/client/components/modals/item/tabs/Cover.vue +++ b/client/components/modals/item/tabs/Cover.vue @@ -49,7 +49,7 @@
-
+
diff --git a/server/finders/BookFinder.js b/server/finders/BookFinder.js index 7716301f..94981d14 100644 --- a/server/finders/BookFinder.js +++ b/server/finders/BookFinder.js @@ -163,12 +163,8 @@ class BookFinder { async getAudiobookCoversResults(search) { const covers = await this.audiobookCovers.search(search) - if (this.verbose) Logger.debug(`AudiobookCovers Book Search Results: ${books.length || 0}`) - if (covers.errorCode) { - Logger.error(`AusiobookCovers Search Error ${books.errorCode}`) - return [] - } - return covers + if (this.verbose) Logger.debug(`AudiobookCovers Search Results: ${covers.length || 0}`) + return covers || [] } async getiTunesAudiobooksResults(title, author) { @@ -206,8 +202,6 @@ class BookFinder { books = await this.getGoogleBooksResults(title, author) } - console.log(books) - if (!books.length && !options.currentlyTryingCleaned) { var cleanedTitle = this.cleanTitleForCompares(title) var cleanedAuthor = this.cleanAuthorForCompares(author) @@ -218,11 +212,13 @@ class BookFinder { return this.search(provider, cleanedTitle, cleanedAuthor, isbn, asin, options) } - if (["google", "audible", "itunes", 'fantlab'].includes(provider)) return books + if (provider === 'openlibrary') { + books.sort((a, b) => { + return a.totalDistance - b.totalDistance + }) + } - return books.sort((a, b) => { - return a.totalDistance - b.totalDistance - }) + return books } async findCovers(provider, title, author, options = {}) { diff --git a/server/providers/AudiobookCovers.js b/server/providers/AudiobookCovers.js index ea03a9d2..edb1b199 100644 --- a/server/providers/AudiobookCovers.js +++ b/server/providers/AudiobookCovers.js @@ -14,7 +14,7 @@ class AudiobookCovers { Logger.error('[AudiobookCovers] Cover search error', error) return [] }) - return items.map(item => { return { cover: item.filename } }) + return items.map(item => ({ cover: item.filename })) } }