calibre-web的豆瓣api provider

This commit is contained in:
Gary Fu 2021-10-28 19:17:59 +08:00
parent 3a36b17b0b
commit 8ad96fec3f
3 changed files with 6 additions and 4 deletions

View File

@ -12,9 +12,9 @@
### 使用方法(已废弃) ### 使用方法(已废弃)
修改`src/douban.py`中的`doubanUrl`地址后,复制`src/douban.py`到`calibre-web/cps/metadata_provider/`目录下,重启项目。 ~~修改`src/douban.py`中的`doubanUrl`地址后,复制`src/douban.py`到`calibre-web/cps/metadata_provider/`目录下,重启项目。~~
**注意由于豆瓣api已经不开放使用了这个豆瓣api需要连接`simple-boot-douban-api`使用** ~~由于豆瓣api已经不开放使用了这个豆瓣api需要连接`simple-boot-douban-api`使用~~

View File

@ -1,4 +1,6 @@
import re import re
import time
import requests import requests
from concurrent.futures import ThreadPoolExecutor, as_completed from concurrent.futures import ThreadPoolExecutor, as_completed
from urllib.parse import urlparse, unquote from urllib.parse import urlparse, unquote
@ -78,8 +80,10 @@ class DoubanBookLoader:
@lru_cache(maxsize=DOUBAN_BOOK_CACHE_SIZE) @lru_cache(maxsize=DOUBAN_BOOK_CACHE_SIZE)
def load_book(self, url): def load_book(self, url):
book = None book = None
start_time = time.time()
res = requests.get(url, headers=DEFAULT_HEADERS) res = requests.get(url, headers=DEFAULT_HEADERS)
if res.status_code in [200, 201]: if res.status_code in [200, 201]:
print("下载书籍:{}成功,耗时{:.0f}ms".format(url, (time.time() - start_time) * 1000))
book_detail_content = res.content book_detail_content = res.content
book = self.book_parser.parse_book(url, book_detail_content.decode("utf8")) book = self.book_parser.parse_book(url, book_detail_content.decode("utf8"))
return book return book

View File

@ -3,7 +3,5 @@ from douban import Douban
if __name__ == "__main__": if __name__ == "__main__":
douban = Douban() douban = Douban()
result = douban.search('人民的名义') result = douban.search('人民的名义')
result = douban.search('人民的名义')
result = douban.search('人民的名义')
for book in result: for book in result:
print(book.get('title'), book.get('url')) print(book.get('title'), book.get('url'))