1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-09-21 03:39:46 +00:00

Fix metadata search results

This commit is contained in:
Ozzie Isaacs 2024-08-12 18:29:31 +02:00
parent 3733fd442f
commit 095074f977
2 changed files with 6 additions and 7 deletions

View File

@ -53,7 +53,6 @@ class Amazon(Metadata):
def search(
self, query: str, generic_cover: str = "", locale: str = "en"
) -> Optional[List[MetaRecord]]:
#timer=time()
def inner(link, index) -> [dict, int]:
with self.session as session:
try:
@ -61,11 +60,11 @@ class Amazon(Metadata):
r.raise_for_status()
except Exception as ex:
log.warning(ex)
return None
return []
long_soup = BS(r.text, "lxml") #~4sec :/
soup2 = long_soup.find("div", attrs={"cel_widget_id": "dpx-books-ppd_csm_instrumentation_wrapper"})
if soup2 is None:
return None
return []
try:
match = MetaRecord(
title = "",
@ -88,7 +87,7 @@ class Amazon(Metadata):
soup2.find("div", attrs={"data-feature-name": "bookDescription"}).stripped_strings)\
.replace("\xa0"," ")[:-9].strip().strip("\n")
except (AttributeError, TypeError):
return None # if there is no description it is not a book and therefore should be ignored
return [] # if there is no description it is not a book and therefore should be ignored
try:
match.title = soup2.find("span", attrs={"id": "productTitle"}).text
except (AttributeError, TypeError):
@ -113,7 +112,7 @@ class Amazon(Metadata):
return match, index
except Exception as e:
log.error_or_exception(e)
return None
return []
val = list()
if self.active:

View File

@ -54,7 +54,7 @@ class Google(Metadata):
results.raise_for_status()
except Exception as e:
log.warning(e)
return None
return []
for result in results.json().get("items", []):
val.append(
self._parse_search_result(