diff --git a/src/calibre/ebooks/metadata/sources/base.py b/src/calibre/ebooks/metadata/sources/base.py index 7c7d51077b..67a80d5785 100644 --- a/src/calibre/ebooks/metadata/sources/base.py +++ b/src/calibre/ebooks/metadata/sources/base.py @@ -78,8 +78,8 @@ class InternalMetadataCompareKeyGen(object): exact_title = 1 if title and \ cleanup_title(title) == cleanup_title(mi.title) else 2 - has_cover = 2 if source_plugin.get_cached_cover_url(mi.identifiers)\ - is None else 1 + has_cover = 2 if (not source_plugin.cached_cover_url_is_reliable or + source_plugin.get_cached_cover_url(mi.identifiers) is None) else 1 self.base = (isbn, has_cover, all_fields, exact_title) self.comments_len = len(mi.comments.strip() if mi.comments else '') @@ -157,6 +157,12 @@ class Source(Plugin): #: correctly first supports_gzip_transfer_encoding = False + #: Cached cover URLs can sometimes be unreliable (i.e. the download could + #: fail or the returned image could be bogus. If that is the case set this to + #: False + cached_cover_url_is_reliable = True + + def __init__(self, *args, **kwargs): Plugin.__init__(self, *args, **kwargs) self._isbn_to_identifier_cache = {} diff --git a/src/calibre/ebooks/metadata/sources/google.py b/src/calibre/ebooks/metadata/sources/google.py index 34753cf35f..4133d4d527 100644 --- a/src/calibre/ebooks/metadata/sources/google.py +++ b/src/calibre/ebooks/metadata/sources/google.py @@ -7,7 +7,7 @@ __license__ = 'GPL v3' __copyright__ = '2011, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import time +import time, hashlib from urllib import urlencode from functools import partial from Queue import Queue, Empty @@ -164,9 +164,12 @@ class GoogleBooks(Source): 'comments', 'publisher', 'identifier:isbn', 'rating', 'identifier:google']) # language currently disabled supports_gzip_transfer_encoding = True + cached_cover_url_is_reliable = False GOOGLE_COVER = 'http://books.google.com/books?id=%s&printsec=frontcover&img=1' + DUMMY_IMAGE_MD5 = frozenset(['0de4383ebad0adad5eeb8975cd796657']) + def get_book_url(self, identifiers): # {{{ goog = identifiers.get('google', None) if goog is not None: @@ -235,7 +238,11 @@ class GoogleBooks(Source): log('Downloading cover from:', cached_url) try: cdata = br.open_novisit(cached_url, timeout=timeout).read() - result_queue.put((self, cdata)) + if cdata: + if hashlib.md5(cdata).hexdigest() in self.DUMMY_IMAGE_MD5: + log.warning('Google returned a dummy image, ignoring') + else: + result_queue.put((self, cdata)) except: log.exception('Failed to download cover from:', cached_url) diff --git a/src/calibre/ebooks/metadata/sources/identify.py b/src/calibre/ebooks/metadata/sources/identify.py index 784977b82c..cd658a0daf 100644 --- a/src/calibre/ebooks/metadata/sources/identify.py +++ b/src/calibre/ebooks/metadata/sources/identify.py @@ -338,8 +338,9 @@ def identify(log, abort, # {{{ for i, result in enumerate(presults): result.relevance_in_source = i - result.has_cached_cover_url = \ - plugin.get_cached_cover_url(result.identifiers) is not None + result.has_cached_cover_url = (plugin.cached_cover_url_is_reliable + and plugin.get_cached_cover_url(result.identifiers) is not + None) result.identify_plugin = plugin log('The identify phase took %.2f seconds'%(time.time() - start_time)) diff --git a/src/calibre/gui2/metadata/single_download.py b/src/calibre/gui2/metadata/single_download.py index 16fb1b42f2..9b59b57e13 100644 --- a/src/calibre/gui2/metadata/single_download.py +++ b/src/calibre/gui2/metadata/single_download.py @@ -180,6 +180,13 @@ class ResultsModel(QAbstractTableModel): # {{{ return self.yes_icon elif role == Qt.UserRole: return book + elif role == Qt.ToolTipRole and col == 3: + return QVariant( + _('The has cover indication is not fully\n' + 'reliable. Sometimes results marked as not\n' + 'having a cover will find a cover in the download\n' + 'cover stage, and vice versa.')) + return NONE def sort(self, col, order=Qt.AscendingOrder): @@ -769,7 +776,7 @@ class LogViewer(QDialog): # {{{ self.keep_updating = True self.last_html = None self.finished.connect(self.stop) - QTimer.singleShot(1000, self.update_log) + QTimer.singleShot(100, self.update_log) self.show() @@ -785,7 +792,7 @@ class LogViewer(QDialog): # {{{ html = self.log.html if html != self.last_html: self.last_html = html - self.tb.setHtml('
%s
'%html) + self.tb.setHtml('
%s
'%html) QTimer.singleShot(1000, self.update_log) # }}} @@ -885,5 +892,5 @@ if __name__ == '__main__': #DEBUG_DIALOG = True app = QApplication([]) d = FullFetch() - d.start(title='jurassic', authors=['crichton']) + d.start(title='great gatsby', authors=['fitzgerald']) diff --git a/src/calibre/utils/logging.py b/src/calibre/utils/logging.py index dbbca6806b..46b843565e 100644 --- a/src/calibre/utils/logging.py +++ b/src/calibre/utils/logging.py @@ -66,7 +66,7 @@ class HTMLStream(Stream): color = { DEBUG: '', INFO:'', - WARN: '', + WARN: '', ERROR: '' } normal = ''