diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 1260e8c004..7bed56dc5e 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -1931,12 +1931,13 @@ class Cache(object): author_map = defaultdict(set) for aid, author in at.id_map.iteritems(): author_map[icu_lower(author)].add(aid) - return (author_map, at.col_book_map.copy(), self.fields['title'].table.book_col_map.copy()) + return (author_map, at.col_book_map.copy(), self.fields['title'].table.book_col_map.copy(), self.fields['languages'].book_value_map.copy()) @read_api def update_data_for_find_identical_books(self, book_id, data): - author_map, author_book_map, title_map = data + author_map, author_book_map, title_map, lang_map = data title_map[book_id] = self._field_for('title', book_id) + lang_map[book_id] = self._field_for('languages', book_id) at = self.fields['authors'].table for aid in at.book_col_map.get(book_id, ()): author_map[icu_lower(at.id_map[aid])].add(aid) diff --git a/src/calibre/db/utils.py b/src/calibre/db/utils.py index a4067236e6..4f102aa31e 100644 --- a/src/calibre/db/utils.py +++ b/src/calibre/db/utils.py @@ -15,6 +15,8 @@ from threading import Lock from calibre import as_unicode, prints from calibre.constants import cache_dir, get_windows_number_formats, iswindows +from calibre.utils.localization import canonicalize_lang + def force_to_bool(val): if isinstance(val, (str, unicode)): @@ -59,7 +61,7 @@ def fuzzy_title(title): def find_identical_books(mi, data): - author_map, aid_map, title_map = data + author_map, aid_map, title_map, lang_map = data found_books = None for a in mi.authors: author_ids = author_map.get(icu_lower(a)) @@ -79,7 +81,23 @@ def find_identical_books(mi, data): title = title_map.get(book_id, '') if fuzzy_title(title) == titleq: ans.add(book_id) - return ans + + if ans is None: + return set() + + alg = set() + langq = canonicalize_lang(mi.language) + if langq is None: + return ans + for book_id in ans: + lang_list = lang_map.get(book_id, '') + if lang_list is None: + return ans + for lang in lang_list: + lang=canonicalize_lang(lang) + if lang == langq: + alg.add(book_id) + return alg Entry = namedtuple('Entry', 'path size timestamp thumbnail_size') diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py index 796989e517..aca0c76b9e 100644 --- a/src/calibre/gui2/actions/copy_to_library.py +++ b/src/calibre/gui2/actions/copy_to_library.py @@ -351,7 +351,7 @@ class DuplicatesQuestion(QDialog): # {{{ QDialog.__init__(self, parent) l = QVBoxLayout() self.setLayout(l) - self.la = la = QLabel(_('Books with the same title and author as the following already exist in the library %s.' + self.la = la = QLabel(_('Books with the same, language, title and author as the following already exist in the library %s.' ' Select which books you want copied anyway.') % os.path.basename(loc)) la.setWordWrap(True) diff --git a/src/calibre/gui2/preferences/adding.ui b/src/calibre/gui2/preferences/adding.ui index c8163530de..bb42c68132 100644 --- a/src/calibre/gui2/preferences/adding.ui +++ b/src/calibre/gui2/preferences/adding.ui @@ -111,7 +111,7 @@ - When using the "Copy to library" action check for &duplicates with the same title and author + When using the "Copy to library" action check for &duplicates with the same language, title, and author @@ -165,7 +165,7 @@ Title match ignores leading indefinite articles ("the", "a", Auto-merge: If books with similar titles and authors found, merge the incoming formats automatically into existing book records. This box controls what happens when an existing record already has -the incoming format: +the incoming format: Ignore duplicate incoming files - means that existing files in your calibre library will not be replaced Overwrite existing duplicate files - means that existing files in your calibre library will be replaced