From 32bdae31a8b1d7467e60d3a932ac7f7b2c90cefc Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 14 May 2023 13:43:20 -0500 Subject: [PATCH] Add:All providers option for searching covers #1774 --- client/components/modals/item/tabs/Cover.vue | 4 ++-- server/finders/BookFinder.js | 22 +++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/client/components/modals/item/tabs/Cover.vue b/client/components/modals/item/tabs/Cover.vue index 9c9d61db..a2a624c7 100644 --- a/client/components/modals/item/tabs/Cover.vue +++ b/client/components/modals/item/tabs/Cover.vue @@ -128,7 +128,7 @@ export default { }, providers() { if (this.isPodcast) return this.$store.state.scanners.podcastProviders - return [...this.$store.state.scanners.providers, ...this.$store.state.scanners.coverOnlyProviders] + return [{ text: 'All', value: 'all' }, ...this.$store.state.scanners.providers, ...this.$store.state.scanners.coverOnlyProviders] }, searchTitleLabel() { if (this.provider.startsWith('audible')) return this.$strings.LabelSearchTitleOrASIN @@ -288,7 +288,7 @@ export default { }, getSearchQuery() { var searchQuery = `provider=${this.provider}&title=${this.searchTitle}` - if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}` + if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor || ''}` if (this.isPodcast) searchQuery += '&podcast=1' return searchQuery }, diff --git a/server/finders/BookFinder.js b/server/finders/BookFinder.js index 94981d14..9124e2bd 100644 --- a/server/finders/BookFinder.js +++ b/server/finders/BookFinder.js @@ -18,6 +18,8 @@ class BookFinder { this.fantLab = new FantLab() this.audiobookCovers = new AudiobookCovers() + this.providers = ['google', 'itunes', 'openlibrary', 'fantlab', 'audiobookcovers', 'audible', 'audible.ca', 'audible.uk', 'audible.au', 'audible.fr', 'audible.de', 'audible.jp', 'audible.it', 'audible.in', 'audible.es'] + this.verbose = false } @@ -183,7 +185,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(`Book Search: title: "${title}", author: "${author}", provider: ${provider}`) + Logger.debug(`Book Search: title: "${title}", author: "${author || ''}", provider: ${provider}`) if (provider === 'google') { books = await this.getGoogleBooksResults(title, author) @@ -222,19 +224,29 @@ class BookFinder { } async findCovers(provider, title, author, options = {}) { - var searchResults = await this.search(provider, title, author, options) + let searchResults = [] + + if (provider === 'all') { + for (const providerString of this.providers) { + const providerResults = await this.search(providerString, title, author, options) + Logger.debug(`[BookFinder] Found ${providerResults.length} covers from ${providerString}`) + searchResults.push(...providerResults) + } + } else { + searchResults = await this.search(provider, title, author, options) + } Logger.debug(`[BookFinder] FindCovers search results: ${searchResults.length}`) - var covers = [] + const covers = [] searchResults.forEach((result) => { if (result.covers && result.covers.length) { - covers = covers.concat(result.covers) + covers.push(...result.covers) } if (result.cover) { covers.push(result.cover) } }) - return covers + return [...(new Set(covers))] } findChapters(asin, region) {