mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-17 07:13:42 +01:00
Initial import
This commit is contained in:
55
ebook_converter/ebooks/oeb/transforms/guide.py
Normal file
55
ebook_converter/ebooks/oeb/transforms/guide.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
class Clean(object):
|
||||
'''Clean up guide, leaving only known values '''
|
||||
|
||||
def __call__(self, oeb, opts):
|
||||
self.oeb, self.log, self.opts = oeb, oeb.log, opts
|
||||
|
||||
if 'cover' not in self.oeb.guide:
|
||||
covers = []
|
||||
for x in ('other.ms-coverimage-standard', 'coverimagestandard',
|
||||
'other.ms-titleimage-standard', 'other.ms-titleimage',
|
||||
'other.ms-coverimage', 'other.ms-thumbimage-standard',
|
||||
'other.ms-thumbimage', 'thumbimagestandard'):
|
||||
if x in self.oeb.guide:
|
||||
href = self.oeb.guide[x].href
|
||||
try:
|
||||
item = self.oeb.manifest.hrefs[href]
|
||||
except KeyError:
|
||||
continue
|
||||
else:
|
||||
covers.append([self.oeb.guide[x], len(item.data)])
|
||||
|
||||
covers.sort(key=lambda x: x[1], reverse=True)
|
||||
if covers:
|
||||
ref = covers[0][0]
|
||||
if len(covers) > 1:
|
||||
self.log('Choosing %s:%s as the cover'%(ref.type, ref.href))
|
||||
ref.type = 'cover'
|
||||
self.oeb.guide.refs['cover'] = ref
|
||||
|
||||
if ('start' in self.oeb.guide and 'text' not in self.oeb.guide):
|
||||
# Prefer text to start as per the OPF 2.0 spec
|
||||
x = self.oeb.guide['start']
|
||||
self.oeb.guide.add('text', x.title, x.href)
|
||||
self.oeb.guide.remove('start')
|
||||
|
||||
for x in list(self.oeb.guide):
|
||||
if x.lower() not in {
|
||||
'cover', 'titlepage', 'masthead', 'toc', 'title-page',
|
||||
'copyright-page', 'text', 'index', 'glossary',
|
||||
'acknowledgements', 'bibliography', 'colophon',
|
||||
'copyright-page', 'dedication', 'epigraph', 'foreword',
|
||||
'loi', 'lot', 'notes', 'preface'}:
|
||||
item = self.oeb.guide[x]
|
||||
if item.title and item.title.lower() == 'start':
|
||||
continue
|
||||
self.oeb.guide.remove(x)
|
||||
Reference in New Issue
Block a user