mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-18 06:00:32 +00:00
Fix metadata search results
This commit is contained in:
parent
3733fd442f
commit
095074f977
@ -53,7 +53,6 @@ class Amazon(Metadata):
|
|||||||
def search(
|
def search(
|
||||||
self, query: str, generic_cover: str = "", locale: str = "en"
|
self, query: str, generic_cover: str = "", locale: str = "en"
|
||||||
) -> Optional[List[MetaRecord]]:
|
) -> Optional[List[MetaRecord]]:
|
||||||
#timer=time()
|
|
||||||
def inner(link, index) -> [dict, int]:
|
def inner(link, index) -> [dict, int]:
|
||||||
with self.session as session:
|
with self.session as session:
|
||||||
try:
|
try:
|
||||||
@ -61,11 +60,11 @@ class Amazon(Metadata):
|
|||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
log.warning(ex)
|
log.warning(ex)
|
||||||
return None
|
return []
|
||||||
long_soup = BS(r.text, "lxml") #~4sec :/
|
long_soup = BS(r.text, "lxml") #~4sec :/
|
||||||
soup2 = long_soup.find("div", attrs={"cel_widget_id": "dpx-books-ppd_csm_instrumentation_wrapper"})
|
soup2 = long_soup.find("div", attrs={"cel_widget_id": "dpx-books-ppd_csm_instrumentation_wrapper"})
|
||||||
if soup2 is None:
|
if soup2 is None:
|
||||||
return None
|
return []
|
||||||
try:
|
try:
|
||||||
match = MetaRecord(
|
match = MetaRecord(
|
||||||
title = "",
|
title = "",
|
||||||
@ -88,7 +87,7 @@ class Amazon(Metadata):
|
|||||||
soup2.find("div", attrs={"data-feature-name": "bookDescription"}).stripped_strings)\
|
soup2.find("div", attrs={"data-feature-name": "bookDescription"}).stripped_strings)\
|
||||||
.replace("\xa0"," ")[:-9].strip().strip("\n")
|
.replace("\xa0"," ")[:-9].strip().strip("\n")
|
||||||
except (AttributeError, TypeError):
|
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:
|
try:
|
||||||
match.title = soup2.find("span", attrs={"id": "productTitle"}).text
|
match.title = soup2.find("span", attrs={"id": "productTitle"}).text
|
||||||
except (AttributeError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
@ -113,7 +112,7 @@ class Amazon(Metadata):
|
|||||||
return match, index
|
return match, index
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error_or_exception(e)
|
log.error_or_exception(e)
|
||||||
return None
|
return []
|
||||||
|
|
||||||
val = list()
|
val = list()
|
||||||
if self.active:
|
if self.active:
|
||||||
|
@ -54,7 +54,7 @@ class Google(Metadata):
|
|||||||
results.raise_for_status()
|
results.raise_for_status()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning(e)
|
log.warning(e)
|
||||||
return None
|
return []
|
||||||
for result in results.json().get("items", []):
|
for result in results.json().get("items", []):
|
||||||
val.append(
|
val.append(
|
||||||
self._parse_search_result(
|
self._parse_search_result(
|
||||||
|
Loading…
Reference in New Issue
Block a user