diff --git a/vrobbler/apps/books/koreader.py b/vrobbler/apps/books/koreader.py index e6864ce..8d5665a 100644 --- a/vrobbler/apps/books/koreader.py +++ b/vrobbler/apps/books/koreader.py @@ -1,3 +1,4 @@ +import re import codecs import logging import os @@ -69,6 +70,8 @@ def get_book_map_from_sqlite(rows: Iterable) -> dict: ko_authors = book_row[ KoReaderBookColumn.AUTHORS.value ].replace("\n", ", ") + # Strip middle initials, OpenLibrary often fails with these + ko_authors = re.sub(" [A-Z]. ", " ", ko_authors) book_dict = { "title": book_row[KoReaderBookColumn.TITLE.value], "pages": total_pages, @@ -80,9 +83,7 @@ def get_book_map_from_sqlite(rows: Iterable) -> dict: Book.objects.filter(pk=book.id).update(**book_dict) # Add authors - authors = book_row[KoReaderBookColumn.AUTHORS.value].split( - "\n" - ) + authors = ko_authors.split(", ") author_list = [] for author_str in authors: logger.debug(f"Looking up author {author_str}") diff --git a/vrobbler/apps/books/openlibrary.py b/vrobbler/apps/books/openlibrary.py index 70e736b..5a2ddef 100644 --- a/vrobbler/apps/books/openlibrary.py +++ b/vrobbler/apps/books/openlibrary.py @@ -1,6 +1,5 @@ import json import logging -import re import urllib import requests @@ -79,8 +78,6 @@ def lookup_book_from_openlibrary(title: str, author: str = None) -> dict: title_quoted = urllib.parse.quote(title) author_quoted = "" if author: - # Strip middle initials, OpenLibrary often fails with these - author = re.sub(" [A-Z]. ", " ", author) author_quoted = urllib.parse.quote(author) query = f"{title_quoted} {author_quoted}"