mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-03 01:35:08 +02:00
This commit is contained in:
parent
7c1789a7c2
commit
ad4dad1c29
18 changed files with 311 additions and 55 deletions
50
server/providers/GoogleBooks.js
Normal file
50
server/providers/GoogleBooks.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
const axios = require('axios')
|
||||
const Logger = require('../Logger')
|
||||
|
||||
class GoogleBooks {
|
||||
constructor() { }
|
||||
|
||||
extractIsbn(industryIdentifiers) {
|
||||
if (!industryIdentifiers || !industryIdentifiers.length) return null
|
||||
|
||||
var isbnObj = industryIdentifiers.find(i => i.type === 'ISBN_13') || industryIdentifiers.find(i => i.type === 'ISBN_10')
|
||||
if (isbnObj && isbnObj.identifier) return isbnObj.identifier
|
||||
return null
|
||||
}
|
||||
|
||||
cleanResult(item) {
|
||||
var { id, volumeInfo } = item
|
||||
if (!volumeInfo) return null
|
||||
var { title, subtitle, authors, publisher, publisherDate, description, industryIdentifiers, categories, imageLinks } = volumeInfo
|
||||
|
||||
return {
|
||||
id,
|
||||
title,
|
||||
subtitle: subtitle || null,
|
||||
author: authors ? authors.join(', ') : null,
|
||||
publisher,
|
||||
publishYear: publisherDate ? publisherDate.split('-')[0] : null,
|
||||
description,
|
||||
cover: imageLinks && imageLinks.thumbnail ? imageLinks.thumbnail : null,
|
||||
genres: categories ? categories.join(', ') : null,
|
||||
isbn: this.extractIsbn(industryIdentifiers)
|
||||
}
|
||||
}
|
||||
|
||||
async search(title, author) {
|
||||
var queryString = `q=intitle:${title}`
|
||||
if (author) queryString += `+inauthor:${author}`
|
||||
var url = `https://www.googleapis.com/books/v1/volumes?${queryString}`
|
||||
Logger.debug(`[GoogleBooks] Search url: ${url}`)
|
||||
var items = await axios.get(url).then((res) => {
|
||||
if (!res || !res.data || !res.data.items) return []
|
||||
return res.data.items
|
||||
}).catch(error => {
|
||||
Logger.error('[GoogleBooks] Volume search error', error)
|
||||
return []
|
||||
})
|
||||
return items.map(item => this.cleanResult(item))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GoogleBooks
|
Loading…
Add table
Add a link
Reference in a new issue