Merge remote-tracking branch 'books_api/cjwin2000-google_books_apikey'

This commit is contained in:
Ozzie Isaacs
2025-09-09 09:59:49 +02:00
4 changed files with 11 additions and 2 deletions

View File

@@ -1838,6 +1838,9 @@ def _configuration_update_helper():
services.goodreads_support.connect(config.config_goodreads_api_key, services.goodreads_support.connect(config.config_goodreads_api_key,
config.config_use_goodreads) config.config_use_goodreads)
# Google Books API configuration
reboot_required |=_config_string(to_save, "config_googlebooks_api_key")
_config_int(to_save, "config_updatechannel") _config_int(to_save, "config_updatechannel")
# Reverse proxy login configuration # Reverse proxy login configuration

View File

@@ -117,6 +117,7 @@ class _Settings(_Base):
config_use_goodreads = Column(Boolean, default=False) config_use_goodreads = Column(Boolean, default=False)
config_goodreads_api_key = Column(String) config_goodreads_api_key = Column(String)
config_googlebooks_api_key = Column(String, default='')
config_register_email = Column(Boolean, default=False) config_register_email = Column(Boolean, default=False)
config_login_type = Column(Integer, default=0) config_login_type = Column(Integer, default=0)

View File

@@ -23,7 +23,7 @@ from datetime import datetime
import requests import requests
from cps import logger from cps import logger, config
from cps.isoLanguages import get_lang3, get_language_name from cps.isoLanguages import get_lang3, get_language_name
from cps.services.Metadata import MetaRecord, MetaSourceInfo, Metadata from cps.services.Metadata import MetaRecord, MetaSourceInfo, Metadata
@@ -38,6 +38,7 @@ class Google(Metadata):
BOOK_URL = "https://books.google.com/books?id=" BOOK_URL = "https://books.google.com/books?id="
SEARCH_URL = "https://www.googleapis.com/books/v1/volumes?q=" SEARCH_URL = "https://www.googleapis.com/books/v1/volumes?q="
ISBN_TYPE = "ISBN_13" ISBN_TYPE = "ISBN_13"
API_KEY = "&key=" + config.config_googlebooks_api_key
def search( def search(
self, query: str, generic_cover: str = "", locale: str = "en" self, query: str, generic_cover: str = "", locale: str = "en"
@@ -50,7 +51,7 @@ class Google(Metadata):
tokens = [quote(t.encode("utf-8")) for t in title_tokens] tokens = [quote(t.encode("utf-8")) for t in title_tokens]
query = "+".join(tokens) query = "+".join(tokens)
try: try:
results = requests.get(Google.SEARCH_URL + query) results = requests.get(Google.SEARCH_URL + query + Google.API_KEY)
results.raise_for_status() results.raise_for_status()
except Exception as e: except Exception as e:
log.warning(e) log.warning(e)

View File

@@ -163,6 +163,10 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
<div class="form-group">
<label for="config_googlebooks_api_key">{{_('Google Books API Key')}}</label>
<input type="text" class="form-control" id="config_googlebooks_api_key" name="config_googlebooks_api_key" value="{% if config.config_googlebooks_api_key != '' %}{{ config.config_googlebooks_api_key }}{% endif %}" autocomplete="off">
</div>
<div class="form-group"> <div class="form-group">
<input type="checkbox" id="config_allow_reverse_proxy_header_login" name="config_allow_reverse_proxy_header_login" data-control="reverse-proxy-login-settings" {% if config.config_allow_reverse_proxy_header_login %}checked{% endif %}> <input type="checkbox" id="config_allow_reverse_proxy_header_login" name="config_allow_reverse_proxy_header_login" data-control="reverse-proxy-login-settings" {% if config.config_allow_reverse_proxy_header_login %}checked{% endif %}>
<label for="config_allow_reverse_proxy_header_login">{{_('Allow Reverse Proxy Authentication')}}</label> <label for="config_allow_reverse_proxy_header_login">{{_('Allow Reverse Proxy Authentication')}}</label>