Add:Region support for audible chapter lookup

This commit is contained in:
advplyr 2022-10-15 15:31:07 -05:00
parent 067d90474b
commit ce4e48cbd7
5 changed files with 34 additions and 12 deletions

View file

@ -210,7 +210,8 @@ class MiscController {
async findChapters(req, res) {
var asin = req.query.asin
var chapterData = await this.bookFinder.findChapters(asin)
var region = (req.query.region || 'us').toLowerCase()
var chapterData = await this.bookFinder.findChapters(asin, region)
if (!chapterData) {
return res.json({ error: 'Chapters not found' })
}

View file

@ -209,8 +209,8 @@ class BookFinder {
return covers
}
findChapters(asin) {
return this.audnexus.getChaptersByASIN(asin)
findChapters(asin, region) {
return this.audnexus.getChaptersByASIN(asin, region)
}
}
module.exports = BookFinder

View file

@ -59,12 +59,12 @@ class Audnexus {
}
}
async getChaptersByASIN(asin) {
Logger.debug(`[Audnexus] Get chapters for ASIN ${asin}`)
return axios.get(`${this.baseUrl}/books/${asin}/chapters`).then((res) => {
getChaptersByASIN(asin, region) {
Logger.debug(`[Audnexus] Get chapters for ASIN ${asin}/${region}`)
return axios.get(`${this.baseUrl}/books/${asin}/chapters?region=${region}`).then((res) => {
return res.data
}).catch((error) => {
Logger.error(`[Audnexus] Chapter ASIN request failed for ${asin}`, error)
Logger.error(`[Audnexus] Chapter ASIN request failed for ${asin}/${region}`, error)
return null
})
}