'Generate a thumbnail cover for each book.
Generate or retrieve a thumbnail for each cover. If nonexistent or faulty
cover data, substitute default cover. Checks for updated default cover.
At completion, writes self.opts.thumb_width to archive.
Inputs:
books_by_title (list): books to catalog
Output:
thumbs (list): list of referenced thumbnails'

def generate_thumbnails(self):

    self.update_progress_full_step(_('Thumbnails'))
    thumbs = ['thumbnail_default.jpg']
    image_dir = ('%s/images' % self.catalog_path)
    for (i, title) in enumerate(self.books_by_title):
        self.update_progress_micro_step(('%s    %d    of    %d' % (_('Thumbnail'), i, len(self.books_by_title))), (i / float(len(self.books_by_title))))
        thumb_file = ('thumbnail_%d.jpg' % int(title['id']))
        thumb_generated = True
        valid_cover = True
        try:
            self.generate_thumbnail(title, image_dir, thumb_file)
            thumbs.append(('thumbnail_%d.jpg' % int(title['id'])))
        except:
            if (('cover' in title) and os.path.exists(title['cover'])):
                valid_cover = False
                self.opts.log.warn(("    ***    Invalid    cover    file    for    '%s'***" % title['title']))
                if (not self.error):
                    self.error.append('Invalid    cover    files')
                self.error.append(("Warning:    invalid    cover    file    for    '%s',    default    cover    substituted.\n" % title['title']))
            thumb_generated = False
        if (not thumb_generated):
            self.opts.log.warn(("                    using    default    cover    for    '%s'    (%d)" % (title['title'], title['id'])))
            default_thumb_fp = os.path.join(image_dir, 'thumbnail_default.jpg')
            cover = os.path.join(self.catalog_path, 'DefaultCover.png')
            title['cover'] = cover
            if (not os.path.exists(cover)):
                shutil.copyfile(I('default_cover.png'), cover)
            if os.path.isfile(default_thumb_fp):
                cover_timestamp = os.path.getmtime(cover)
                thumb_timestamp = os.path.getmtime(default_thumb_fp)
                if (thumb_timestamp < cover_timestamp):
                    if (self.DEBUG and self.opts.verbose):
                        self.opts.log.warn(('updating    thumbnail_default    for    %s' % title['title']))
                    self.generate_thumbnail(title, image_dir, ('thumbnail_default.jpg' if valid_cover else thumb_file))
            else:
                if (self.DEBUG and self.opts.verbose):
                    self.opts.log.warn('                    generating    new    thumbnail_default.jpg')
                self.generate_thumbnail(title, image_dir, ('thumbnail_default.jpg' if valid_cover else thumb_file))
            title['cover'] = None
    try:
        with ZipFile(self.thumbs_path, mode='a') as zfw:
            zfw.writestr('thumb_width', self.opts.thumb_width)
    except Exception as err:
        raise ValueError(('There    was    an    error    writing    to    the    thumbnail    cache:    %s\nTry    deleting    it.    Underlying    error:    %s' % (force_unicode(self.thumbs_path), as_unicode(err))))
    self.thumbs = thumbs
