Skip to content

Commit

Permalink
Include a header in requests to AudiobookCovers
Browse files Browse the repository at this point in the history
  • Loading branch information
Weldawadyathink committed Feb 5, 2024
1 parent 66585c3 commit 5ced43c
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions server/providers/AudiobookCovers.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
const axios = require('axios')
const Logger = require('../Logger')
const axios = require("axios");
const Logger = require("../Logger");

class AudiobookCovers {
constructor() { }
constructor() {}

async search(search) {
const url = `https://api.audiobookcovers.com/cover/ai-search`
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 => ({ cover: item.versions.png.original }))
const url = "https://api.audiobookcovers.com/cover/ai-search";
const request_options = {
params: {
q: search,
},
headers: {
"User-Agent": `Audiobookshelf/${global.ServerSettings.version}`,
},
};
const items = await axios
.get(url, request_options)
.then((res) => {
if (!res || !res.data) return [];
return res.data;
})
.catch((error) => {
Logger.error("[AudiobookCovers] Cover search error", error);
return [];
});
return items.map((item) => ({ cover: item.versions.png.original }));
}
}



module.exports = AudiobookCovers
module.exports = AudiobookCovers;

0 comments on commit 5ced43c

Please sign in to comment.