This commit is contained in:
Kovid Goyal 2011-04-09 21:18:08 -06:00
parent dedc0979b1
commit 0d57316475
5 changed files with 31 additions and 10 deletions

View File

@ -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 = {}

View File

@ -7,7 +7,7 @@ __license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__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)

View File

@ -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))

View File

@ -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('<pre>%s</pre>'%html)
self.tb.setHtml('<pre style="font-family:monospace">%s</pre>'%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'])

View File

@ -66,7 +66,7 @@ class HTMLStream(Stream):
color = {
DEBUG: '<span style="color:green">',
INFO:'<span>',
WARN: '<span style="color:yellow">',
WARN: '<span style="color:blue">',
ERROR: '<span style="color:red">'
}
normal = '</span>'