mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-29 03:20:32 +00:00
Merge pull request #1108 from bookwyrm-social/ol-redirects
Handle openlibrary redirects
This commit is contained in:
commit
b6c17defd7
1 changed files with 10 additions and 3 deletions
|
@ -58,6 +58,13 @@ class Connector(AbstractConnector):
|
|||
Mapping("bio", formatter=get_description),
|
||||
]
|
||||
|
||||
def get_book_data(self, remote_id):
|
||||
data = get_data(remote_id)
|
||||
if data.get("type", {}).get("key") == "/type/redirect":
|
||||
remote_id = self.base_url + data.get("location")
|
||||
return get_data(remote_id)
|
||||
return data
|
||||
|
||||
def get_remote_id_from_data(self, data):
|
||||
"""format a url from an openlibrary id field"""
|
||||
try:
|
||||
|
@ -75,7 +82,7 @@ class Connector(AbstractConnector):
|
|||
except KeyError:
|
||||
raise ConnectorException("Invalid book data")
|
||||
url = "%s%s/editions" % (self.books_url, key)
|
||||
data = get_data(url)
|
||||
data = self.get_book_data(url)
|
||||
edition = pick_default_edition(data["entries"])
|
||||
if not edition:
|
||||
raise ConnectorException("No editions for work")
|
||||
|
@ -87,7 +94,7 @@ class Connector(AbstractConnector):
|
|||
except (IndexError, KeyError):
|
||||
raise ConnectorException("No work found for edition")
|
||||
url = "%s%s" % (self.books_url, key)
|
||||
return get_data(url)
|
||||
return self.get_book_data(url)
|
||||
|
||||
def get_authors_from_data(self, data):
|
||||
"""parse author json and load or create authors"""
|
||||
|
@ -146,7 +153,7 @@ class Connector(AbstractConnector):
|
|||
def load_edition_data(self, olkey):
|
||||
"""query openlibrary for editions of a work"""
|
||||
url = "%s/works/%s/editions" % (self.books_url, olkey)
|
||||
return get_data(url)
|
||||
return self.get_book_data(url)
|
||||
|
||||
def expand_book_data(self, book):
|
||||
work = book
|
||||
|
|
Loading…
Reference in a new issue