Show more data about books in search
This commit is contained in:
@ -262,9 +262,10 @@ class SearchResult:
|
||||
|
||||
title: str
|
||||
key: str
|
||||
author: str
|
||||
year: str
|
||||
connector: object
|
||||
author: str = None
|
||||
year: str = None
|
||||
cover: str = None
|
||||
confidence: int = 1
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -24,5 +24,4 @@ class Connector(AbstractMinimalConnector):
|
||||
return data
|
||||
|
||||
def format_isbn_search_result(self, search_result):
|
||||
search_result["connector"] = self
|
||||
return SearchResult(**search_result)
|
||||
return self.format_search_result(search_result)
|
||||
|
@ -95,10 +95,12 @@ class Connector(AbstractConnector):
|
||||
url = "%s%s" % (self.base_url, author_id)
|
||||
yield self.get_or_create_author(url)
|
||||
|
||||
def get_cover_url(self, cover_blob):
|
||||
def get_cover_url(self, cover_blob, size='L'):
|
||||
""" ask openlibrary for the cover """
|
||||
if not cover_blob:
|
||||
return None
|
||||
cover_id = cover_blob[0]
|
||||
image_name = "%s-L.jpg" % cover_id
|
||||
image_name = "%s-%s.jpg" % (cover_id, size)
|
||||
return "%s/b/id/%s" % (self.covers_url, image_name)
|
||||
|
||||
def parse_search_data(self, data):
|
||||
@ -108,12 +110,15 @@ class Connector(AbstractConnector):
|
||||
# build the remote id from the openlibrary key
|
||||
key = self.books_url + search_result["key"]
|
||||
author = search_result.get("author_name") or ["Unknown"]
|
||||
cover_blob = search_result.get("cover_i")
|
||||
cover = self.get_cover_url([cover_blob], size='M') if cover_blob else None
|
||||
return SearchResult(
|
||||
title=search_result.get("title"),
|
||||
key=key,
|
||||
author=", ".join(author),
|
||||
connector=self,
|
||||
year=search_result.get("first_publish_year"),
|
||||
cover=cover,
|
||||
)
|
||||
|
||||
def parse_isbn_search_data(self, data):
|
||||
|
@ -67,20 +67,12 @@ class Connector(AbstractConnector):
|
||||
if search_result.published_date
|
||||
else None,
|
||||
connector=self,
|
||||
cover='%s%s' % (self.covers_url, search_result.cover),
|
||||
confidence=search_result.rank if hasattr(search_result, "rank") else 1,
|
||||
)
|
||||
|
||||
def format_isbn_search_result(self, search_result):
|
||||
return SearchResult(
|
||||
title=search_result.title,
|
||||
key=search_result.remote_id,
|
||||
author=search_result.author_text,
|
||||
year=search_result.published_date.year
|
||||
if search_result.published_date
|
||||
else None,
|
||||
connector=self,
|
||||
confidence=search_result.rank if hasattr(search_result, "rank") else 1,
|
||||
)
|
||||
return self.format_search_result(search_result)
|
||||
|
||||
def is_work_data(self, data):
|
||||
pass
|
||||
|
Reference in New Issue
Block a user