2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
3
from __future__ import with_statement
6
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
7
__docformat__ = 'restructuredtext en'
11
'''Clean up guide, leaving only a pointer to the cover'''
13
def __call__(self, oeb, opts):
14
from calibre.ebooks.oeb.base import urldefrag
15
self.oeb, self.log, self.opts = oeb, oeb.log, opts
17
if 'cover' not in self.oeb.guide:
19
for x in ('other.ms-coverimage-standard',
20
'other.ms-titleimage-standard', 'other.ms-titleimage',
21
'other.ms-coverimage', 'other.ms-thumbimage-standard',
22
'other.ms-thumbimage'):
23
if x in self.oeb.guide:
24
href = self.oeb.guide[x].href
25
item = self.oeb.manifest.hrefs[href]
26
covers.append([self.oeb.guide[x], len(item.data)])
27
covers.sort(cmp=lambda x,y:cmp(x[1], y[1]), reverse=True)
31
self.log('Choosing %s:%s as the cover'%(ref.type, ref.href))
33
self.oeb.guide.refs['cover'] = ref
35
for x in list(self.oeb.guide):
36
href = urldefrag(self.oeb.guide[x].href)[0]
37
if x.lower() not in ('cover', 'titlepage', 'masthead', 'toc',
38
'title-page', 'copyright-page', 'start'):
39
self.oeb.guide.remove(x)