[books] Add comicvine
This commit is contained in:
@ -208,25 +208,26 @@ def lookup_comic_from_comicvine(title: str) -> dict:
|
|||||||
client = ComicVineClient(
|
client = ComicVineClient(
|
||||||
api_key=getattr(settings, "COMICVINE_API_KEY", None)
|
api_key=getattr(settings, "COMICVINE_API_KEY", None)
|
||||||
)
|
)
|
||||||
return client.search(title)
|
result = [
|
||||||
results = [
|
|
||||||
r
|
r
|
||||||
for r in client.search(title).get("results")
|
for r in client.search(title).get("results")
|
||||||
if r.get("resource_type") == "volume"
|
if r.get("resource_type") == "volume"
|
||||||
]
|
][0]
|
||||||
|
|
||||||
return results
|
if "volume" not in result.keys():
|
||||||
"""
|
logger.warn("No result found on ComicVine", extra={"title": title})
|
||||||
{
|
return {}
|
||||||
"title": top.get("title"),
|
|
||||||
"isbn": isbn,
|
title = " ".join([result.get("volume").get("name"), result.get("name)")])
|
||||||
"comicvine_id": ol_id,
|
data_dict = {
|
||||||
"first_publish_year": top.get("first_publish_year"),
|
"title": title,
|
||||||
"first_sentence": first_sentence,
|
"cover_url": result.get("image").get("original_url"),
|
||||||
"pages": top.get("number_of_pages_median", None),
|
"comicvine_data": {
|
||||||
"cover_url": COVER_URL.format(id=ol_id),
|
"id": result.get("id"),
|
||||||
"cv_author_id": ol_author_id,
|
"site_detail_url": result.get("site_detail_url"),
|
||||||
"subject_key_list": top.get("subject_key", []),
|
"description": result.get("description"),
|
||||||
|
"image": result.get("image").get("original_url"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
return data_dict
|
||||||
|
|||||||
@ -23,6 +23,10 @@ from scrobbles.mixins import (
|
|||||||
from scrobbles.utils import get_scrobbles_for_media
|
from scrobbles.utils import get_scrobbles_for_media
|
||||||
from taggit.managers import TaggableManager
|
from taggit.managers import TaggableManager
|
||||||
from thefuzz import fuzz
|
from thefuzz import fuzz
|
||||||
|
from vrobbler.apps.books.comicvine import (
|
||||||
|
ComicVineClient,
|
||||||
|
lookup_comic_from_comicvine,
|
||||||
|
)
|
||||||
|
|
||||||
from vrobbler.apps.books.locg import (
|
from vrobbler.apps.books.locg import (
|
||||||
lookup_comic_by_locg_slug,
|
lookup_comic_by_locg_slug,
|
||||||
@ -30,6 +34,8 @@ from vrobbler.apps.books.locg import (
|
|||||||
lookup_comic_writer_by_locg_slug,
|
lookup_comic_writer_by_locg_slug,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
COMICVINE_API_KEY = getattr(settings, "COMICVINE_API_KEY", "")
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
BNULL = {"blank": True, "null": True}
|
BNULL = {"blank": True, "null": True}
|
||||||
@ -150,7 +156,7 @@ class Book(LongPlayScrobblableMixin):
|
|||||||
author_name = self.author.name
|
author_name = self.author.name
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
logger.warn(f"rChecking 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(
|
data = lookup_book_from_openlibrary(
|
||||||
str(self.openlibrary_id)
|
str(self.openlibrary_id)
|
||||||
@ -163,13 +169,18 @@ class Book(LongPlayScrobblableMixin):
|
|||||||
if not data:
|
if not data:
|
||||||
if self.locg_slug:
|
if self.locg_slug:
|
||||||
logger.warn(
|
logger.warn(
|
||||||
f"rChecking openlibrary for {self.title} with slug {self.locg_slug}"
|
f"Checking LOCG for {self.title} with slug {self.locg_slug}"
|
||||||
)
|
)
|
||||||
data = lookup_comic_by_locg_slug(str(self.locg_slug))
|
data = lookup_comic_by_locg_slug(str(self.locg_slug))
|
||||||
else:
|
else:
|
||||||
logger.warn(f"rChecking openlibrary for {self.title}")
|
logger.warn(f"Checking LOCG for {self.title}")
|
||||||
data = lookup_comic_from_locg(str(self.title))
|
data = lookup_comic_from_locg(str(self.title))
|
||||||
|
|
||||||
|
if not data and COMICVINE_API_KEY:
|
||||||
|
logger.warn(f"Checking ComicVine for {self.title}")
|
||||||
|
cv_client = ComicVineClient(api_key=COMICVINE_API_KEY)
|
||||||
|
data = lookup_comic_from_comicvine(str(self.title))
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
logger.warn(f"Book not found in any sources: {self.title}")
|
logger.warn(f"Book not found in any sources: {self.title}")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user