[books] Update lookup for books to use openlibrary

This commit is contained in:
2026-03-26 15:53:15 -04:00
parent 49f1410814
commit 062386a5b6

View File

@ -12,6 +12,9 @@ from books.openlibrary import (
lookup_book_from_openlibrary,
)
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.utils import get_comic_issue_url
from django.conf import settings
@ -106,11 +109,9 @@ class Author(TimeStampedModel):
def __str__(self):
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):
data_dict = lookup_author_from_openlibrary(self.openlibrary_id)
@ -243,8 +244,9 @@ class Book(LongPlayScrobblableMixin):
def find_or_create(
cls,
title: str,
author: str | None = None,
url: str = "",
enrich: bool = False,
enrich: bool = True,
commit: bool = True,
):
"""Given a title, get a Book instance.
@ -275,6 +277,9 @@ class Book(LongPlayScrobblableMixin):
book_dict["readcomics_url"]
)
if not book_dict:
book_dict = lookup_book_from_ol(title, author=author)
if not book_dict:
book_dict = lookup_book_from_google(title)
@ -287,7 +292,7 @@ class Book(LongPlayScrobblableMixin):
author_list = []
authors = book_dict.pop("authors", [])
cover_url = book_dict.pop("cover_url", "")
genres = book_dict.pop("generes", [])
genres = book_dict.pop("genres", book_dict.pop("generes", []))
if authors:
for author_str in authors:
@ -326,9 +331,9 @@ class Book(LongPlayScrobblableMixin):
if not data:
logger.warn(f"Checking openlibrary for {self.title}")
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:
data = lookup_book_from_openlibrary(str(self.title), author_name)
data = lookup_book_from_ol(str(self.title), author_name)
if not data:
if self.locg_slug: