mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Cleanup previous PR
We don't want an quadratic algorithm for author lookups. Also contains searches have too large a chance of false positives. So check individual authors one by one for a match rather than doing contains searches.
This commit is contained in:
parent
aa4c720c48
commit
da197459ec
@ -1908,23 +1908,6 @@ class DeviceMixin: # {{{
|
|||||||
if get_covers and desired_thumbnail_height != 0:
|
if get_covers and desired_thumbnail_height != 0:
|
||||||
self.update_thumbnail(book)
|
self.update_thumbnail(book)
|
||||||
|
|
||||||
def extract_id_from_dict(author_to_look_for, target_dict):
|
|
||||||
'''
|
|
||||||
Extracts id from dict with full match by author or partial match for cases when
|
|
||||||
book has multiple authors.
|
|
||||||
'''
|
|
||||||
debug_print('Trying to extract id for author:', author_to_look_for, ' in:', target_dict)
|
|
||||||
if author_to_look_for in target_dict:
|
|
||||||
return target_dict[book_authors]
|
|
||||||
else:
|
|
||||||
# for cases when multiple authors like: Author A & Author B => 'authoraauthorb' need to match 'authorb'
|
|
||||||
for author in target_dict:
|
|
||||||
if author_to_look_for in author:
|
|
||||||
return target_dict[author]
|
|
||||||
|
|
||||||
debug_print('Id is not extracted!')
|
|
||||||
return None
|
|
||||||
|
|
||||||
def updateq(id_, book):
|
def updateq(id_, book):
|
||||||
try:
|
try:
|
||||||
if not update_metadata:
|
if not update_metadata:
|
||||||
@ -1952,6 +1935,21 @@ class DeviceMixin: # {{{
|
|||||||
except:
|
except:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_by_author(book, d, author):
|
||||||
|
book_id = d['authors'].get(author)
|
||||||
|
if book_id is not None:
|
||||||
|
book.in_library = 'AUTHOR'
|
||||||
|
book.application_id = book_id
|
||||||
|
update_book(book_id, book)
|
||||||
|
return True
|
||||||
|
book_id = d['author_sort'].get(author)
|
||||||
|
if book_id is not None:
|
||||||
|
book.in_library = 'AUTH_SORT'
|
||||||
|
book.application_id = book_id
|
||||||
|
update_book(book_id, book)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
# Now iterate through all the books on the device, setting the
|
# Now iterate through all the books on the device, setting the
|
||||||
# in_library field. If the UUID matches a book in the library, then
|
# in_library field. If the UUID matches a book in the library, then
|
||||||
# do not consider that book for other matching. In all cases set
|
# do not consider that book for other matching. In all cases set
|
||||||
@ -2024,24 +2022,11 @@ class DeviceMixin: # {{{
|
|||||||
if book.authors:
|
if book.authors:
|
||||||
# Compare against both author and author sort, because
|
# Compare against both author and author sort, because
|
||||||
# either can appear as the author
|
# either can appear as the author
|
||||||
book_authors = clean_string(authors_to_string(book.authors))
|
all_book_authors = clean_string(authors_to_string(book.authors))
|
||||||
extracted_id = None
|
if not get_by_author(book, d, all_book_authors):
|
||||||
authors_id = extract_id_from_dict(book_authors, d['authors'])
|
for author in book.authors:
|
||||||
if authors_id is not None:
|
if get_by_author(book, d, clean_string(author)):
|
||||||
extracted_id = authors_id
|
break
|
||||||
book.in_library = 'AUTHOR'
|
|
||||||
else:
|
|
||||||
author_sort_id = extract_id_from_dict(book_authors, d['author_sort'])
|
|
||||||
if author_sort_id is not None:
|
|
||||||
extracted_id = author_sort_id
|
|
||||||
book.in_library = 'AUTH_SORT'
|
|
||||||
|
|
||||||
update_book(extracted_id, book)
|
|
||||||
book.application_id = extracted_id
|
|
||||||
|
|
||||||
if extracted_id is None:
|
|
||||||
debug_print('No author match for a book:\n', book)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Book definitely not matched. Clear its application ID
|
# Book definitely not matched. Clear its application ID
|
||||||
book.application_id = None
|
book.application_id = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user