Catalog generation: Handle invalid covers gracefully

This commit is contained in:
Kovid Goyal 2011-01-08 11:59:12 -07:00
commit 5483bb6f94

View File

@ -2861,25 +2861,17 @@ class EPUB_MOBI(CatalogPlugin):
self.updateProgressMicroStep("Thumbnail %d of %d" % \ self.updateProgressMicroStep("Thumbnail %d of %d" % \
(i,len(self.booksByTitle)), (i,len(self.booksByTitle)),
i/float(len(self.booksByTitle))) i/float(len(self.booksByTitle)))
# Check to see if source file exists
if 'cover' in title and os.path.isfile(title['cover']):
# Add the thumb spec to thumbs[]
thumbs.append("thumbnail_%d.jpg" % int(title['id']))
# Check to see if thumbnail exists thumb_file = 'thumbnail_%d.jpg' % int(title['id'])
thumb_fp = "%s/thumbnail_%d.jpg" % (image_dir,int(title['id'])) thumb_generated = True
thumb_file = 'thumbnail_%d.jpg' % int(title['id']) try:
if os.path.isfile(thumb_fp): self.generateThumbnail(title, image_dir, thumb_file)
# Check to see if cover is newer than thumbnail thumbs.append("thumbnail_%d.jpg" % int(title['id']))
# os.path.getmtime() = modified time except:
# os.path.ctime() = creation time thumb_generated = False
cover_timestamp = os.path.getmtime(title['cover'])
thumb_timestamp = os.path.getmtime(thumb_fp)
if thumb_timestamp < cover_timestamp: if not thumb_generated:
self.generateThumbnail(title, image_dir, thumb_file)
else:
self.generateThumbnail(title, image_dir, thumb_file)
else:
# Use default cover # Use default cover
if False and self.verbose: if False and self.verbose:
self.opts.log.warn(" using default cover for '%s'" % \ self.opts.log.warn(" using default cover for '%s'" % \