Browse Source

Import fix, and don't overwrite KoReader data when OL conflicts

Colin Powell 1 year ago
parent
commit
209875f0e6
2 changed files with 10 additions and 3 deletions
  1. 9 2
      vrobbler/apps/books/models.py
  2. 1 1
      vrobbler/apps/books/tests/test_openlibrary.py

+ 9 - 2
vrobbler/apps/books/models.py

@@ -22,6 +22,7 @@ from scrobbles.mixins import (
 )
 from scrobbles.utils import get_scrobbles_for_media
 from taggit.managers import TaggableManager
+from thefuzz import fuzz
 
 from vrobbler.apps.books.locg import (
     lookup_comic_by_locg_slug,
@@ -176,10 +177,16 @@ class Book(LongPlayScrobblableMixin):
             ol_title = data.get("title", "")
 
             # Kick out a little warning if we're about to change KoReader's title
-            if ol_title.lower() != str(self.title).lower():
+            if (
+                fuzz.ratio(ol_title.lower(), str(self.title).lower()) < 80
+                and not force_update
+            ):
                 logger.warn(
-                    f"OL and KoReader disagree on this book title {self.title} != {ol_title}"
+                    f"OL and KoReader disagree on this book title {self.title} != {ol_title}, check manually"
                 )
+                self.openlibrary_id = data.get("openlibrary_id")
+                self.save(update_fields=["openlibrary_id"])
+                return
 
             # If we don't know pages, don't overwrite existing with None
             if "pages" in data.keys() and data.get("pages") == None:

+ 1 - 1
vrobbler/apps/books/tests/test_openlibrary.py

@@ -2,7 +2,7 @@ from unittest import skip
 
 import pytest
 
-from vrobbler.apps.books.openlibrary import lookup_book_from_openlibrary
+from books.openlibrary import lookup_book_from_openlibrary
 
 
 def test_lookup_modern_book():