calibre-web的豆瓣api provider
This commit is contained in:
parent
405608267c
commit
5af3f07b96
12
README.md
12
README.md
|
@ -1,2 +1,12 @@
|
|||
# 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`使用**
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
requests>=2.11.1,<2.25.0
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,6 @@
|
|||
from douban import Douban
|
||||
|
||||
douban = Douban()
|
||||
result = douban.search('人民的名义')
|
||||
for book in result:
|
||||
print(book.get('title'), book.get('url'))
|
Loading…
Reference in New Issue