Minor fixes

This commit is contained in:
Kovid Goyal 2010-11-19 10:20:24 -07:00
parent f4cab917ea
commit 0c78971db1
3 changed files with 10 additions and 11 deletions

View File

@ -5,17 +5,12 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import textwrap, cStringIO import textwrap
from urllib import unquote from urllib import unquote
from lxml import etree from lxml import etree
try:
from PIL import Image as PILImage
PILImage
except ImportError:
import Image as PILImage
from calibre import guess_type from calibre import guess_type
from calibre.utils.magick.draw import identify_data
class CoverManager(object): class CoverManager(object):
@ -126,9 +121,7 @@ class CoverManager(object):
if x.href == urlnormalize(href): if x.href == urlnormalize(href):
try: try:
raw = x.data raw = x.data
f = cStringIO.StringIO(raw) return identify_data(raw)[:2]
im = PILImage.open(f)
return im.size
except: except:
self.log.exception('Failed to read image dimensions') self.log.exception('Failed to read image dimensions')
return None, None return None, None

View File

@ -101,6 +101,8 @@ class PDFOutput(OutputFormatPlugin):
for item in m: for item in m:
if item.href == urlnormalize(href): if item.href == urlnormalize(href):
self.cover_data = item.data self.cover_data = item.data
if not isinstance(self.cover_data, basestring):
self.cover_data = None
def convert_text(self, oeb_book): def convert_text(self, oeb_book):
self.log.debug('Serializing oeb input to disk for processing...') self.log.debug('Serializing oeb input to disk for processing...')

View File

@ -176,6 +176,7 @@ class DoDownload(QObject):
set_metadata=set_metadata, set_metadata=set_metadata,
get_social_metadata=get_social_metadata) get_social_metadata=get_social_metadata)
self.timer = QTimer(self) self.timer = QTimer(self)
self.get_covers = get_covers
self.timer.timeout.connect(self.do_one, type=Qt.QueuedConnection) self.timer.timeout.connect(self.do_one, type=Qt.QueuedConnection)
self.db = db self.db = db
self.updated = set([]) self.updated = set([])
@ -222,6 +223,9 @@ class DoDownload(QObject):
id_, typ, ok, title = r id_, typ, ok, title = r
what = _('cover') if typ == 'cover' else _('metadata') what = _('cover') if typ == 'cover' else _('metadata')
which = _('Downloaded') if ok else _('Failed to get') which = _('Downloaded') if ok else _('Failed to get')
if self.get_covers or typ != 'cover' or ok:
# Do not show message when cover fetch fails if user didn't ask to
# download covers
self.pd.set_msg(_('%s %s for: %s') % (which, what, title)) self.pd.set_msg(_('%s %s for: %s') % (which, what, title))
self.pd.value += 1 self.pd.value += 1
if ok: if ok: