mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-15 18:38:56 +01:00
Added support for audible metadata
This commit is contained in:
parent
66911a4b70
commit
ae8046823f
@ -49,6 +49,10 @@
|
||||
<ui-checkbox v-model="selectedMatchUsage.author" />
|
||||
<ui-text-input-with-label v-model="selectedMatch.author" :disabled="!selectedMatchUsage.author" label="Author" class="flex-grow ml-4" />
|
||||
</div>
|
||||
<div v-if="selectedMatch.narrator" class="flex items-center py-2">
|
||||
<ui-checkbox v-model="selectedMatchUsage.narrator" />
|
||||
<ui-text-input-with-label v-model="selectedMatch.narrator" :disabled="!selectedMatchUsage.narrator" label="Narrator" class="flex-grow ml-4" />
|
||||
</div>
|
||||
<div v-if="selectedMatch.description" class="flex items-center py-2">
|
||||
<ui-checkbox v-model="selectedMatchUsage.description" />
|
||||
<ui-textarea-with-label v-model="selectedMatch.description" :rows="3" :disabled="!selectedMatchUsage.description" label="Description" class="flex-grow ml-4" />
|
||||
@ -65,6 +69,18 @@
|
||||
<ui-checkbox v-model="selectedMatchUsage.isbn" />
|
||||
<ui-text-input-with-label v-model="selectedMatch.isbn" :disabled="!selectedMatchUsage.isbn" label="ISBN" class="flex-grow ml-4" />
|
||||
</div>
|
||||
<div v-if="selectedMatch.series" class="flex items-center py-2">
|
||||
<ui-checkbox v-model="selectedMatchUsage.series" />
|
||||
<ui-text-input-with-label v-model="selectedMatch.series" :disabled="!selectedMatchUsage.series" label="Series" class="flex-grow ml-4" />
|
||||
</div>
|
||||
<div v-if="selectedMatch.volumeNumber" class="flex items-center py-2">
|
||||
<ui-checkbox v-model="selectedMatchUsage.volumeNumber" />
|
||||
<ui-text-input-with-label v-model="selectedMatch.volumeNumber" :disabled="!selectedMatchUsage.volumeNumber" label="Volume Number" class="flex-grow ml-4" />
|
||||
</div>
|
||||
<!-- <div v-if="selectedMatch.asin" class="flex items-center py-2">
|
||||
<ui-checkbox v-model="selectedMatchUsage.asin" />
|
||||
<ui-text-input-with-label v-model="selectedMatch.asin" :disabled="!selectedMatchUsage.asin" label="ASIN" class="flex-grow ml-4" />
|
||||
</div> -->
|
||||
<div class="flex items-center justify-end py-2">
|
||||
<ui-btn color="success" type="submit">Update</ui-btn>
|
||||
</div>
|
||||
@ -96,6 +112,10 @@ export default {
|
||||
{
|
||||
text: 'Open Library',
|
||||
value: 'openlibrary'
|
||||
},
|
||||
{
|
||||
text: 'Audible',
|
||||
value: 'audible'
|
||||
}
|
||||
],
|
||||
provider: 'google',
|
||||
@ -107,10 +127,13 @@ export default {
|
||||
subtitle: true,
|
||||
cover: true,
|
||||
author: true,
|
||||
narrator: true,
|
||||
description: true,
|
||||
isbn: true,
|
||||
publisher: true,
|
||||
publishYear: true
|
||||
publishYear: true,
|
||||
series: true,
|
||||
volumeNumber: true,
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -169,10 +192,13 @@ export default {
|
||||
subtitle: true,
|
||||
cover: true,
|
||||
author: true,
|
||||
narrator: true,
|
||||
description: true,
|
||||
isbn: true,
|
||||
publisher: true,
|
||||
publishYear: true
|
||||
publishYear: true,
|
||||
series: true,
|
||||
volumeNumber: true,
|
||||
}
|
||||
|
||||
if (this.audiobook.id !== this.audiobookId) {
|
||||
|
@ -45,6 +45,7 @@
|
||||
"read-chunk": "^3.1.0",
|
||||
"recursive-readdir-async": "^1.1.8",
|
||||
"socket.io": "^4.1.3",
|
||||
"string-strip-html": "^8.3.0",
|
||||
"watcher": "^1.2.0",
|
||||
"xml2js": "^0.4.23"
|
||||
},
|
||||
|
@ -1,6 +1,7 @@
|
||||
const OpenLibrary = require('./providers/OpenLibrary')
|
||||
const LibGen = require('./providers/LibGen')
|
||||
const GoogleBooks = require('./providers/GoogleBooks')
|
||||
const Audible = require('./providers/Audible')
|
||||
const Logger = require('./Logger')
|
||||
const { levenshteinDistance } = require('./utils/index')
|
||||
|
||||
@ -9,6 +10,7 @@ class BookFinder {
|
||||
this.openLibrary = new OpenLibrary()
|
||||
this.libGen = new LibGen()
|
||||
this.googleBooks = new GoogleBooks()
|
||||
this.audible = new Audible()
|
||||
|
||||
this.verbose = false
|
||||
}
|
||||
@ -156,6 +158,13 @@ class BookFinder {
|
||||
return books
|
||||
}
|
||||
|
||||
async getAudibleResults(title, author, maxTitleDistance, maxAuthorDistance) {
|
||||
var books = await this.audible.search(title, author);
|
||||
if (this.verbose) Logger.debug(`Audible Book Search Results: ${books.length || 0}`)
|
||||
if (!books) return []
|
||||
return books
|
||||
}
|
||||
|
||||
async search(provider, title, author, options = {}) {
|
||||
var books = []
|
||||
var maxTitleDistance = !isNaN(options.titleDistance) ? Number(options.titleDistance) : 4
|
||||
@ -164,6 +173,8 @@ class BookFinder {
|
||||
|
||||
if (provider === 'google') {
|
||||
return this.getGoogleBooksResults(title, author, maxTitleDistance, maxAuthorDistance)
|
||||
} else if (provider === 'audible') {
|
||||
return this.getAudibleResults(title, author, maxTitleDistance, maxAuthorDistance)
|
||||
} else if (provider === 'libgen') {
|
||||
books = await this.getLibGenResults(title, author, maxTitleDistance, maxAuthorDistance)
|
||||
} else if (provider === 'openlibrary') {
|
||||
|
51
server/providers/Audible.js
Normal file
51
server/providers/Audible.js
Normal file
@ -0,0 +1,51 @@
|
||||
const axios = require('axios')
|
||||
const {stripHtml} = require('string-strip-html')
|
||||
const Logger = require('../Logger')
|
||||
|
||||
class Audible {
|
||||
constructor() { }
|
||||
|
||||
cleanResult(item) {
|
||||
var { title, subtitle, asin, authors, narrators, publisher_name, publisher_summary, release_date, series, product_images } = item;
|
||||
|
||||
var firstSeries = series && series.length > 0 ? series[0] : null;
|
||||
|
||||
return {
|
||||
title,
|
||||
subtitle: subtitle || null,
|
||||
author: authors ? authors.map(({ name }) => name).join(', ') : null,
|
||||
narrator: narrators ? narrators.map(({ name }) => name).join(', ') : null,
|
||||
publisher: publisher_name,
|
||||
publishYear: release_date ? release_date.split('-')[0] : null,
|
||||
description: stripHtml(publisher_summary).result,
|
||||
cover: this.getBestImageLink(product_images),
|
||||
asin,
|
||||
series: firstSeries ? firstSeries.title : null,
|
||||
volumeNumber: firstSeries ? firstSeries.sequence : null
|
||||
}
|
||||
}
|
||||
|
||||
getBestImageLink(images) {
|
||||
var keys = Object.keys(images);
|
||||
return images[keys[keys.length - 1]];
|
||||
}
|
||||
|
||||
async search(title, author) {
|
||||
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}`
|
||||
var url = `https://api.audible.com/1.0/catalog/products?${queryString}`
|
||||
Logger.debug(`[Audible] Search url: ${url}`)
|
||||
var items = await axios.get(url).then((res) => {
|
||||
if (!res || !res.data || !res.data.products) return []
|
||||
return res.data.products
|
||||
}).catch(error => {
|
||||
Logger.error('[Audible] search error', error)
|
||||
return []
|
||||
})
|
||||
Logger.debug(JSON.stringify(items.map(item => this.cleanResult(item))))
|
||||
return items.map(item => this.cleanResult(item))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Audible
|
Loading…
Reference in New Issue
Block a user