[books] Fix looking up comic by original title

This commit is contained in:
2025-10-20 22:47:32 -04:00
parent 59e8339e94
commit e1d4a7c5a4
3 changed files with 12 additions and 8 deletions

View File

@ -21,7 +21,8 @@ class BookAdmin(admin.ModelAdmin):
date_hierarchy = "created" date_hierarchy = "created"
list_display = ( list_display = (
"title", "title",
"subtitle", "author",
"issue_or_volume",
"isbn_13", "isbn_13",
"first_publish_year", "first_publish_year",
"pages", "pages",
@ -32,6 +33,9 @@ class BookAdmin(admin.ModelAdmin):
ScrobbleInline, ScrobbleInline,
] ]
def issue_or_volume(self, obj):
return obj.issue_number or obj.volume_number
@admin.register(Paper) @admin.register(Paper)
class BookAdmin(admin.ModelAdmin): class BookAdmin(admin.ModelAdmin):

View File

@ -197,9 +197,8 @@ class Book(LongPlayScrobblableMixin):
@classmethod @classmethod
def get_from_comicvine(cls, title: str, overwrite: bool = False, force_new: bool =False) -> "Book": def get_from_comicvine(cls, title: str, overwrite: bool = False, force_new: bool =False) -> "Book":
book, created = cls.objects.get_or_create(title=title) book, created = cls.objects.get_or_create(title=title)
if not created and not overwrite and not force_new:
book, created = cls.objects.get_or_create(original_title=title) if not created:
logger.info("Found comic by original title, use force_new=True to override")
return book return book
book_dict = lookup_comic_from_comicvine(title) book_dict = lookup_comic_from_comicvine(title)
@ -244,7 +243,7 @@ class Book(LongPlayScrobblableMixin):
like to batch create, use commit=False and you'll get an unsaved but enriched like to batch create, use commit=False and you'll get an unsaved but enriched
instance back which you can then save at your convenience.""" instance back which you can then save at your convenience."""
# TODO use either a Google Books id identifier or author name like for tracks # TODO use either a Google Books id identifier or author name like for tracks
book, created = cls.objects.get_or_create(title=title) book, created = cls.objects.get_or_create(original_title=title)
if not created: if not created:
logger.info( logger.info(
"Found exact match for book by title", extra={"title": title} "Found exact match for book by title", extra={"title": title}
@ -258,7 +257,7 @@ class Book(LongPlayScrobblableMixin):
return book return book
book_dict = lookup_book_from_google(title) book_dict = lookup_book_from_google(title)
if not book_dict or book_dict.get("isbn_10"): if not book_dict or not book_dict.get("isbn_10"):
book_dict = lookup_comic_from_comicvine(title) book_dict = lookup_comic_from_comicvine(title)
author_list = [] author_list = []

View File

@ -227,14 +227,12 @@ def lookup_comic_from_comicvine(title: str) -> dict:
for r in raw_results for r in raw_results
if r.get("resource_type") == resource_type if r.get("resource_type") == resource_type
] ]
print(results)
if not results: if not results:
logger.warning("No comic found on ComicVine") logger.warning("No comic found on ComicVine")
return {} return {}
found_result = None found_result = None
for result in results: for result in results:
print("checking ", result.get("issue_number"), " to ", str(issue_number))
if result.get("issue_number") == str(issue_number): if result.get("issue_number") == str(issue_number):
found_result = result found_result = result
break break
@ -264,6 +262,9 @@ def lookup_comic_from_comicvine(title: str) -> dict:
"cover_url": found_result.get("image").get("original_url"), "cover_url": found_result.get("image").get("original_url"),
"comicvine_id": found_result.get("id"), "comicvine_id": found_result.get("id"),
"comicvine_data": found_result, "comicvine_data": found_result,
"summary": found_result.get("description"),
"publish_date": found_result.get("cover_date"),
"first_publish_year": found_result.get("store_date").year,
} }
return data_dict return data_dict