mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
Add:Select cover search provider, Add:Persist selected provider, Change:API routes for searching
This commit is contained in:
parent
bb1a5b2e6d
commit
c5465ad8e0
@ -40,7 +40,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form @submit.prevent="submitSearchForm">
|
<!-- <form @submit.prevent="submitSearchForm">
|
||||||
<div class="flex items-center justify-start -mx-1 py-2 mt-2">
|
<div class="flex items-center justify-start -mx-1 py-2 mt-2">
|
||||||
<div class="flex-grow px-1">
|
<div class="flex-grow px-1">
|
||||||
<ui-text-input-with-label v-model="searchTitle" label="Search Title" placeholder="Search" :disabled="processing" />
|
<ui-text-input-with-label v-model="searchTitle" label="Search Title" placeholder="Search" :disabled="processing" />
|
||||||
@ -52,6 +52,22 @@
|
|||||||
<ui-btn type="submit" class="mt-5 w-full" :padding-x="0">Search</ui-btn>
|
<ui-btn type="submit" class="mt-5 w-full" :padding-x="0">Search</ui-btn>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</form> -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form @submit.prevent="submitSearchForm">
|
||||||
|
<div class="flex items-center justify-start -mx-1 h-20">
|
||||||
|
<div class="w-40 px-1">
|
||||||
|
<ui-dropdown v-model="provider" :items="providers" label="Provider" small />
|
||||||
|
</div>
|
||||||
|
<div class="w-72 px-1">
|
||||||
|
<ui-text-input-with-label v-model="searchTitle" :label="provider == 'audible' ? 'Search Title or ASIN' : 'Search Title'" placeholder="Search" />
|
||||||
|
</div>
|
||||||
|
<div class="w-72 px-1">
|
||||||
|
<ui-text-input-with-label v-model="searchAuthor" label="Author" />
|
||||||
|
</div>
|
||||||
|
<ui-btn class="mt-5 ml-1" type="submit">Search</ui-btn>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div v-if="hasSearched" class="flex items-center flex-wrap justify-center max-h-80 overflow-y-scroll mt-2 max-w-full">
|
<div v-if="hasSearched" class="flex items-center flex-wrap justify-center max-h-80 overflow-y-scroll mt-2 max-w-full">
|
||||||
<p v-if="!coversFound.length">No Covers Found</p>
|
<p v-if="!coversFound.length">No Covers Found</p>
|
||||||
@ -61,8 +77,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="previewUpload" class="absolute top-0 left-0 w-full h-full z-10 bg-bg p-8">
|
<div v-if="previewUpload" class="absolute top-0 left-0 w-full h-full z-10 bg-bg p-8">
|
||||||
<p class="text-lg">Preview Cover</p>
|
<p class="text-lg">Preview Cover</p>
|
||||||
@ -97,7 +111,22 @@ export default {
|
|||||||
hasSearched: false,
|
hasSearched: false,
|
||||||
showLocalCovers: false,
|
showLocalCovers: false,
|
||||||
previewUpload: null,
|
previewUpload: null,
|
||||||
selectedFile: null
|
selectedFile: null,
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
text: 'Google Books',
|
||||||
|
value: 'google'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Open Library',
|
||||||
|
value: 'openlibrary'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Audible',
|
||||||
|
value: 'audible'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
provider: 'google'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -201,6 +230,7 @@ export default {
|
|||||||
this.imageUrl = this.book.cover || ''
|
this.imageUrl = this.book.cover || ''
|
||||||
this.searchTitle = this.book.title || ''
|
this.searchTitle = this.book.title || ''
|
||||||
this.searchAuthor = this.book.authorFL || ''
|
this.searchAuthor = this.book.authorFL || ''
|
||||||
|
this.provider = localStorage.getItem('book-provider') || 'openlibrary'
|
||||||
},
|
},
|
||||||
removeCover() {
|
removeCover() {
|
||||||
if (!this.book.cover) {
|
if (!this.book.cover) {
|
||||||
@ -254,14 +284,24 @@ export default {
|
|||||||
this.isProcessing = false
|
this.isProcessing = false
|
||||||
},
|
},
|
||||||
getSearchQuery() {
|
getSearchQuery() {
|
||||||
var searchQuery = `provider=openlibrary&title=${this.searchTitle}`
|
var searchQuery = `provider=${this.provider}&title=${this.searchTitle}`
|
||||||
if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}`
|
if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}`
|
||||||
return searchQuery
|
return searchQuery
|
||||||
},
|
},
|
||||||
|
persistProvider() {
|
||||||
|
try {
|
||||||
|
localStorage.setItem('book-provider', this.provider)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('PersistProvider', error)
|
||||||
|
}
|
||||||
|
},
|
||||||
async submitSearchForm() {
|
async submitSearchForm() {
|
||||||
|
// Store provider in local storage
|
||||||
|
this.persistProvider()
|
||||||
|
|
||||||
this.isProcessing = true
|
this.isProcessing = true
|
||||||
var searchQuery = this.getSearchQuery()
|
var searchQuery = this.getSearchQuery()
|
||||||
var results = await this.$axios.$get(`/api/find/covers?${searchQuery}`).catch((error) => {
|
var results = await this.$axios.$get(`/api/search/covers?${searchQuery}`).catch((error) => {
|
||||||
console.error('Failed', error)
|
console.error('Failed', error)
|
||||||
return []
|
return []
|
||||||
})
|
})
|
||||||
|
@ -159,6 +159,13 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
persistProvider() {
|
||||||
|
try {
|
||||||
|
localStorage.setItem('book-provider', this.provider)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('PersistProvider', error)
|
||||||
|
}
|
||||||
|
},
|
||||||
getSearchQuery() {
|
getSearchQuery() {
|
||||||
var searchQuery = `provider=${this.provider}&fallbackTitleOnly=1&title=${this.searchTitle}`
|
var searchQuery = `provider=${this.provider}&fallbackTitleOnly=1&title=${this.searchTitle}`
|
||||||
if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}`
|
if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}`
|
||||||
@ -169,6 +176,7 @@ export default {
|
|||||||
this.$toast.warning('Search title is required')
|
this.$toast.warning('Search title is required')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.persistProvider()
|
||||||
this.runSearch()
|
this.runSearch()
|
||||||
},
|
},
|
||||||
async runSearch() {
|
async runSearch() {
|
||||||
@ -177,7 +185,7 @@ export default {
|
|||||||
this.searchResults = []
|
this.searchResults = []
|
||||||
this.isProcessing = true
|
this.isProcessing = true
|
||||||
this.lastSearch = searchQuery
|
this.lastSearch = searchQuery
|
||||||
var results = await this.$axios.$get(`/api/find/search?${searchQuery}`).catch((error) => {
|
var results = await this.$axios.$get(`/api/search/books?${searchQuery}`).catch((error) => {
|
||||||
console.error('Failed', error)
|
console.error('Failed', error)
|
||||||
return []
|
return []
|
||||||
})
|
})
|
||||||
@ -217,6 +225,7 @@ export default {
|
|||||||
}
|
}
|
||||||
this.searchTitle = this.audiobook.book.title
|
this.searchTitle = this.audiobook.book.title
|
||||||
this.searchAuthor = this.audiobook.book.authorFL || ''
|
this.searchAuthor = this.audiobook.book.authorFL || ''
|
||||||
|
this.provider = localStorage.getItem('book-provider') || 'google'
|
||||||
},
|
},
|
||||||
selectMatch(match) {
|
selectMatch(match) {
|
||||||
this.selectedMatch = match
|
this.selectedMatch = match
|
||||||
|
@ -40,10 +40,6 @@ class ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.router.get('/find/covers', this.findCovers.bind(this))
|
|
||||||
this.router.get('/find/:method', this.find.bind(this))
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Library Routes
|
// Library Routes
|
||||||
//
|
//
|
||||||
@ -149,6 +145,12 @@ class ApiController {
|
|||||||
this.router.delete('/backup/:id', BackupController.delete.bind(this))
|
this.router.delete('/backup/:id', BackupController.delete.bind(this))
|
||||||
this.router.post('/backup/upload', BackupController.upload.bind(this))
|
this.router.post('/backup/upload', BackupController.upload.bind(this))
|
||||||
|
|
||||||
|
//
|
||||||
|
// Search Routes
|
||||||
|
//
|
||||||
|
this.router.get('/search/covers', this.findCovers.bind(this))
|
||||||
|
this.router.get('/search/books', this.findBooks.bind(this))
|
||||||
|
|
||||||
//
|
//
|
||||||
// Others
|
// Others
|
||||||
//
|
//
|
||||||
@ -174,7 +176,10 @@ class ApiController {
|
|||||||
this.router.post('/syncUserAudiobookData', this.syncUserAudiobookData.bind(this))
|
this.router.post('/syncUserAudiobookData', this.syncUserAudiobookData.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
async find(req, res) {
|
async findBooks(req, res) {
|
||||||
|
if (req.method === 'match') {
|
||||||
|
|
||||||
|
} else if (req.method === 'cover')
|
||||||
var provider = req.query.provider || 'google'
|
var provider = req.query.provider || 'google'
|
||||||
var title = req.query.title || ''
|
var title = req.query.title || ''
|
||||||
var author = req.query.author || ''
|
var author = req.query.author || ''
|
||||||
@ -182,8 +187,10 @@ class ApiController {
|
|||||||
res.json(results)
|
res.json(results)
|
||||||
}
|
}
|
||||||
|
|
||||||
findCovers(req, res) {
|
async findCovers(req, res) {
|
||||||
this.scanner.findCovers(req, res)
|
var query = req.query
|
||||||
|
var result = await this.bookFinder.findCovers(query.provider, query.title, query.author || null)
|
||||||
|
res.json(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
authorize(req, res) {
|
authorize(req, res) {
|
||||||
|
@ -147,7 +147,7 @@ class BookFinder {
|
|||||||
return booksFiltered
|
return booksFiltered
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGoogleBooksResults(title, author, maxTitleDistance, maxAuthorDistance) {
|
async getGoogleBooksResults(title, author) {
|
||||||
var books = await this.googleBooks.search(title, author)
|
var books = await this.googleBooks.search(title, author)
|
||||||
if (this.verbose) Logger.debug(`GoogleBooks Book Search Results: ${books.length || 0}`)
|
if (this.verbose) Logger.debug(`GoogleBooks Book Search Results: ${books.length || 0}`)
|
||||||
if (books.errorCode) {
|
if (books.errorCode) {
|
||||||
@ -158,7 +158,7 @@ class BookFinder {
|
|||||||
return books
|
return books
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAudibleResults(title, author, maxTitleDistance, maxAuthorDistance) {
|
async getAudibleResults(title, author) {
|
||||||
var books = await this.audible.search(title, author);
|
var books = await this.audible.search(title, author);
|
||||||
if (this.verbose) Logger.debug(`Audible Book Search Results: ${books.length || 0}`)
|
if (this.verbose) Logger.debug(`Audible Book Search Results: ${books.length || 0}`)
|
||||||
if (!books) return []
|
if (!books) return []
|
||||||
@ -172,9 +172,9 @@ class BookFinder {
|
|||||||
Logger.debug(`Book Search: title: "${title}", author: "${author}", provider: ${provider}`)
|
Logger.debug(`Book Search: title: "${title}", author: "${author}", provider: ${provider}`)
|
||||||
|
|
||||||
if (provider === 'google') {
|
if (provider === 'google') {
|
||||||
return this.getGoogleBooksResults(title, author, maxTitleDistance, maxAuthorDistance)
|
return this.getGoogleBooksResults(title, author)
|
||||||
} else if (provider === 'audible') {
|
} else if (provider === 'audible') {
|
||||||
return this.getAudibleResults(title, author, maxTitleDistance, maxAuthorDistance)
|
return this.getAudibleResults(title, author)
|
||||||
} else if (provider === 'libgen') {
|
} else if (provider === 'libgen') {
|
||||||
books = await this.getLibGenResults(title, author, maxTitleDistance, maxAuthorDistance)
|
books = await this.getLibGenResults(title, author, maxTitleDistance, maxAuthorDistance)
|
||||||
} else if (provider === 'openlibrary') {
|
} else if (provider === 'openlibrary') {
|
||||||
|
Loading…
Reference in New Issue
Block a user