2023-04-20 07:13:52 +02:00
|
|
|
const axios = require('axios')
|
|
|
|
const Logger = require('../Logger')
|
|
|
|
|
|
|
|
class AudiobookCovers {
|
2024-05-25 23:32:02 +02:00
|
|
|
#responseTimeout = 30000
|
|
|
|
|
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {string} search
|
|
|
|
* @param {number} [timeout]
|
|
|
|
* @returns {Promise<{cover: string}[]>}
|
|
|
|
*/
|
|
|
|
async search(search, timeout = this.#responseTimeout) {
|
|
|
|
if (!timeout || isNaN(timeout)) timeout = this.#responseTimeout
|
2023-04-20 07:13:52 +02:00
|
|
|
|
|
|
|
const url = `https://api.audiobookcovers.com/cover/bytext/`
|
|
|
|
const params = new URLSearchParams([['q', search]])
|
2024-05-25 23:32:02 +02:00
|
|
|
const items = await axios
|
|
|
|
.get(url, {
|
|
|
|
params,
|
|
|
|
timeout
|
|
|
|
})
|
|
|
|
.then((res) => res?.data || [])
|
|
|
|
.catch((error) => {
|
|
|
|
Logger.error('[AudiobookCovers] Cover search error', error)
|
|
|
|
return []
|
|
|
|
})
|
|
|
|
return items.map((item) => ({ cover: item.versions.png.original }))
|
2023-04-20 07:13:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = AudiobookCovers
|