calibre-web的豆瓣api provider

This commit is contained in:
Gary Fu 2021-10-21 16:53:46 +08:00
parent 405608267c
commit 5af3f07b96
5 changed files with 84 additions and 1 deletions

View File

@ -1,2 +1,12 @@
# calibre-web-douban-api # calibre-web-douban-api
新版calibre-web已经移除douban-api了添加一个豆瓣api实现调用simple-boot-douban-api服务
新版calibre-web已经移除douban-api了而且把从get_meta.js中直接发起请求获取数据改成了从服务端使用python获取数据。
此项目是添加一个豆瓣api provider实现需要放到metadata_provider目录下调用simple-boot-douban-api服务
### 使用方法
复制`src/douban.py`到`calibre-web/cps/metadata_provider/`目录下,重启项目。
**注意由于豆瓣api已经不开放使用了这个豆瓣api需要连接`simple-boot-douban-api`使用**

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
requests>=2.11.1,<2.25.0

View File

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
# Copyright (C) 2021 OzzieIsaacs
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# 从calibre-web复制出来方便测试使用
class Metadata():
__name__ = "Generic"
def __init__(self):
self.active = True
def set_status(self, state):
self.active = state

39
src/douban.py Normal file
View File

@ -0,0 +1,39 @@
import requests
from cps.services.Metadata import Metadata
class Douban(Metadata):
__name__ = "Douban Books"
__id__ = "douban"
doubanUrl = "http://YOUR_NAS_IP:8085"
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3573.0 Safari/537.36'
}
def search(self, query, generic_cover=""):
if self.active:
val = list()
result = requests.get(self.doubanUrl + "/v2/book/search?q=" + query.replace(" ", "+"), headers=self.headers)
for r in result.json()['books']:
v = dict()
v['id'] = r['id']
v['title'] = r['title']
v['authors'] = r.get('authors', [])
v['description'] = r.get('summary', "")
v['publisher'] = r.get('publisher', "")
v['publishedDate'] = r.get('pubdate', "")
v['tags'] = [tag.get('name', '') for tag in r.get('tags', [])]
v['rating'] = r['rating'].get('average', 0)
if r.get('image'):
v['cover'] = r.get('image')
else:
v['cover'] = generic_cover
v['source'] = {
"id": self.__id__,
"description": self.__name__,
"link": "https://book.douban.com/"
}
v['url'] = "https://book.douban.com/subject/" + r['id']
val.append(v)
return val

6
tests/DoubanTest.py Normal file
View File

@ -0,0 +1,6 @@
from douban import Douban
douban = Douban()
result = douban.search('人民的名义')
for book in result:
print(book.get('title'), book.get('url'))