From 80916e811f73a77e292915f1b8eb09328654c483 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 6 Jul 2011 09:15:47 -0600 Subject: [PATCH] Fix #798309 (Support ISBNless merging from multiple sources) --- .../ebooks/metadata/sources/identify.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/metadata/sources/identify.py b/src/calibre/ebooks/metadata/sources/identify.py index f1ed62f55e..c43d2e58ac 100644 --- a/src/calibre/ebooks/metadata/sources/identify.py +++ b/src/calibre/ebooks/metadata/sources/identify.py @@ -82,6 +82,7 @@ class ISBNMerge(object): def __init__(self, log): self.pools = {} self.isbnless_results = [] + self.results = [] self.log = log self.use_xisbn = True @@ -137,15 +138,19 @@ class ISBNMerge(object): if results: has_isbn_result = True break - self.has_isbn_result = has_isbn_result + isbn_sources = frozenset() if has_isbn_result: - self.merge_isbn_results() - else: - results = sorted(self.isbnless_results, - key=attrgetter('relevance_in_source')) + isbn_sources = self.merge_isbn_results() + + # Now handle results that have no ISBNs + results = sorted(self.isbnless_results, + key=attrgetter('relevance_in_source')) + # Only use results that are from sources that have not also returned a + # result with an ISBN + results = [r for r in results if r.identify_plugin not in isbn_sources] + if results: # Pick only the most relevant result from each source - self.results = [] seen = set() for result in results: if result.identify_plugin not in seen: @@ -225,11 +230,15 @@ class ISBNMerge(object): def merge_isbn_results(self): self.results = [] + sources = set() for min_year, results in self.pools.itervalues(): if results: + for r in results: + sources.add(r.identify_plugin) self.results.append(self.merge(results, min_year)) self.results.sort(key=attrgetter('average_source_relevance')) + return sources def length_merge(self, attr, results, null_value=None, shortest=True): values = [getattr(x, attr) for x in results if not x.is_null(attr)]