mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-18 10:59:41 +02:00
Author API requests to use region from library provider
This commit is contained in:
@@ -7,10 +7,12 @@ class Audnexus {
|
||||
this.baseUrl = 'https://api.audnex.us'
|
||||
}
|
||||
|
||||
authorASINsRequest(name) {
|
||||
name = encodeURIComponent(name);
|
||||
var regionQuery = region ? `®ion=${region}` : ''
|
||||
return axios.get(`${this.baseUrl}/authors?name=${name}${regionQuery}`).then((res) => {
|
||||
authorASINsRequest(name, region) {
|
||||
name = encodeURIComponent(name)
|
||||
const regionQuery = region ? `®ion=${region}` : ''
|
||||
const authorRequestUrl = `${this.baseUrl}/authors?name=${name}${regionQuery}`
|
||||
Logger.info(`[Audnexus] Searching for author "${authorRequestUrl}"`)
|
||||
return axios.get(authorRequestUrl).then((res) => {
|
||||
return res.data || []
|
||||
}).catch((error) => {
|
||||
Logger.error(`[Audnexus] Author ASIN request failed for ${name}`, error)
|
||||
@@ -18,10 +20,12 @@ class Audnexus {
|
||||
})
|
||||
}
|
||||
|
||||
authorRequest(asin) {
|
||||
asin = encodeURIComponent(asin);
|
||||
var regionQuery = region ? `?region=${region}` : ''
|
||||
return axios.get(`${this.baseUrl}/authors/${asin}${regionQuery}`).then((res) => {
|
||||
authorRequest(asin, region) {
|
||||
asin = encodeURIComponent(asin)
|
||||
const regionQuery = region ? `?region=${region}` : ''
|
||||
const authorRequestUrl = `${this.baseUrl}/authors/${asin}${regionQuery}`
|
||||
Logger.info(`[Audnexus] Searching for author "${authorRequestUrl}"`)
|
||||
return axios.get(authorRequestUrl).then((res) => {
|
||||
return res.data
|
||||
}).catch((error) => {
|
||||
Logger.error(`[Audnexus] Author request failed for ${asin}`, error)
|
||||
@@ -29,8 +33,8 @@ class Audnexus {
|
||||
})
|
||||
}
|
||||
|
||||
async findAuthorByASIN(asin) {
|
||||
var author = await this.authorRequest(asin)
|
||||
async findAuthorByASIN(asin, region) {
|
||||
const author = await this.authorRequest(asin, region)
|
||||
if (!author) {
|
||||
return null
|
||||
}
|
||||
@@ -42,14 +46,14 @@ class Audnexus {
|
||||
}
|
||||
}
|
||||
|
||||
async findAuthorByName(name, maxLevenshtein = 3) {
|
||||
async findAuthorByName(name, region, maxLevenshtein = 3) {
|
||||
Logger.debug(`[Audnexus] Looking up author by name ${name}`)
|
||||
var asins = await this.authorASINsRequest(name)
|
||||
var matchingAsin = asins.find(obj => levenshteinDistance(obj.name, name) <= maxLevenshtein)
|
||||
const asins = await this.authorASINsRequest(name, region)
|
||||
const matchingAsin = asins.find(obj => levenshteinDistance(obj.name, name) <= maxLevenshtein)
|
||||
if (!matchingAsin) {
|
||||
return null
|
||||
}
|
||||
var author = await this.authorRequest(matchingAsin.asin)
|
||||
const author = await this.authorRequest(matchingAsin.asin)
|
||||
if (!author) {
|
||||
return null
|
||||
}
|
||||
|
Reference in New Issue
Block a user