[books] Update lookup for books to use openlibrary
This commit is contained in:
@ -12,6 +12,9 @@ from books.openlibrary import (
|
|||||||
lookup_book_from_openlibrary,
|
lookup_book_from_openlibrary,
|
||||||
)
|
)
|
||||||
from books.sources.google import lookup_book_from_google
|
from books.sources.google import lookup_book_from_google
|
||||||
|
from books.sources.openlibrary import (
|
||||||
|
lookup_book_from_openlibrary as lookup_book_from_ol,
|
||||||
|
)
|
||||||
from books.sources.semantic import lookup_paper_from_semantic
|
from books.sources.semantic import lookup_paper_from_semantic
|
||||||
from books.utils import get_comic_issue_url
|
from books.utils import get_comic_issue_url
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -106,11 +109,9 @@ class Author(TimeStampedModel):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.name}"
|
return f"{self.name}"
|
||||||
|
|
||||||
def enrich_from_semantic(self, overwrite=False):
|
def enrich_from_semantic(self, overwrite=False): ...
|
||||||
...
|
|
||||||
|
|
||||||
def enrich_from_google_books(self, overwrite=False):
|
def enrich_from_google_books(self, overwrite=False): ...
|
||||||
...
|
|
||||||
|
|
||||||
def enrich_from_openlibrary(self, overwrite=False):
|
def enrich_from_openlibrary(self, overwrite=False):
|
||||||
data_dict = lookup_author_from_openlibrary(self.openlibrary_id)
|
data_dict = lookup_author_from_openlibrary(self.openlibrary_id)
|
||||||
@ -243,8 +244,9 @@ class Book(LongPlayScrobblableMixin):
|
|||||||
def find_or_create(
|
def find_or_create(
|
||||||
cls,
|
cls,
|
||||||
title: str,
|
title: str,
|
||||||
|
author: str | None = None,
|
||||||
url: str = "",
|
url: str = "",
|
||||||
enrich: bool = False,
|
enrich: bool = True,
|
||||||
commit: bool = True,
|
commit: bool = True,
|
||||||
):
|
):
|
||||||
"""Given a title, get a Book instance.
|
"""Given a title, get a Book instance.
|
||||||
@ -275,6 +277,9 @@ class Book(LongPlayScrobblableMixin):
|
|||||||
book_dict["readcomics_url"]
|
book_dict["readcomics_url"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not book_dict:
|
||||||
|
book_dict = lookup_book_from_ol(title, author=author)
|
||||||
|
|
||||||
if not book_dict:
|
if not book_dict:
|
||||||
book_dict = lookup_book_from_google(title)
|
book_dict = lookup_book_from_google(title)
|
||||||
|
|
||||||
@ -287,7 +292,7 @@ class Book(LongPlayScrobblableMixin):
|
|||||||
author_list = []
|
author_list = []
|
||||||
authors = book_dict.pop("authors", [])
|
authors = book_dict.pop("authors", [])
|
||||||
cover_url = book_dict.pop("cover_url", "")
|
cover_url = book_dict.pop("cover_url", "")
|
||||||
genres = book_dict.pop("generes", [])
|
genres = book_dict.pop("genres", book_dict.pop("generes", []))
|
||||||
|
|
||||||
if authors:
|
if authors:
|
||||||
for author_str in authors:
|
for author_str in authors:
|
||||||
@ -326,9 +331,9 @@ class Book(LongPlayScrobblableMixin):
|
|||||||
if not data:
|
if not data:
|
||||||
logger.warn(f"Checking openlibrary for {self.title}")
|
logger.warn(f"Checking openlibrary for {self.title}")
|
||||||
if self.openlibrary_id and force_update:
|
if self.openlibrary_id and force_update:
|
||||||
data = lookup_book_from_openlibrary(str(self.openlibrary_id))
|
data = lookup_book_from_ol(str(self.openlibrary_id))
|
||||||
else:
|
else:
|
||||||
data = lookup_book_from_openlibrary(str(self.title), author_name)
|
data = lookup_book_from_ol(str(self.title), author_name)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
if self.locg_slug:
|
if self.locg_slug:
|
||||||
|
|||||||
Reference in New Issue
Block a user