audiobookshelf/server/providers/AudiobookCovers.js
2023-04-20 16:39:04 -07:00

24 lines
607 B
JavaScript

const axios = require('axios')
const Logger = require('../Logger')
class AudiobookCovers {
constructor() { }
async search(search) {
const url = `https://api.audiobookcovers.com/cover/bytext/`
const params = new URLSearchParams([['q', search]])
const items = await axios.get(url, { params }).then((res) => {
if (!res || !res.data) return []
return res.data
}).catch(error => {
Logger.error('[AudiobookCovers] Cover search error', error)
return []
})
return items.map(item => { return { cover: item.filename } })
}
}
module.exports = AudiobookCovers