Add support for viewing kepub files, by treating them as plain epub files

This commit is contained in:
Kovid Goyal 2014-05-03 21:25:17 +05:30
parent 0d28842570
commit bf51722403
6 changed files with 9 additions and 7 deletions

View File

@ -31,7 +31,7 @@ BOOK_EXTENSIONS = ['lrf', 'rar', 'zip', 'rtf', 'lit', 'txt', 'txtz', 'text', 'ht
'epub', 'fb2', 'djv', 'djvu', 'lrx', 'cbr', 'cbz', 'cbc', 'oebzip',
'rb', 'imp', 'odt', 'chm', 'tpz', 'azw1', 'pml', 'pmlz', 'mbp', 'tan', 'snb',
'xps', 'oxps', 'azw4', 'book', 'zbf', 'pobi', 'docx', 'docm', 'md',
'textile', 'markdown', 'ibook', 'iba', 'azw3', 'ps']
'textile', 'markdown', 'ibook', 'iba', 'azw3', 'ps', 'kepub']
class HTMLRenderer(object):

View File

@ -77,7 +77,7 @@ class Plumber(object):
def __init__(self, input, output, log, report_progress=DummyReporter(),
dummy=False, merge_plugin_recs=True, abort_after_input_dump=False,
override_input_metadata=False, for_regex_wizard=False):
override_input_metadata=False, for_regex_wizard=False, view_kepub=False):
'''
:param input: Path to input file.
:param output: Path to output file/directory
@ -702,6 +702,8 @@ OptionRecommendation(name='search_replace',
if not input_fmt:
raise ValueError('Input file must have an extension')
input_fmt = input_fmt[1:].lower().replace('original_', '')
if view_kepub and input_fmt.lower() == 'kepub':
input_fmt = 'epub'
self.archive_input_tdir = None
if input_fmt in ARCHIVE_FMTS:
self.log('Processing archive...')

View File

@ -14,7 +14,7 @@ from calibre.customize.ui import available_input_formats
def is_supported(path):
ext = os.path.splitext(path)[1].replace('.', '').lower()
ext = re.sub(r'(x{0,1})htm(l{0,1})', 'html', ext)
return ext in available_input_formats()
return ext in available_input_formats() or ext == 'kepub'
class UnsupportedFormatError(Exception):

View File

@ -75,7 +75,7 @@ class EbookIterator(BookmarksMixin):
return i
def __enter__(self, processed=False, only_input_plugin=False,
run_char_count=True, read_anchor_map=True,
run_char_count=True, read_anchor_map=True, view_kepub=False,
extract_embedded_fonts_for_qt=False):
''' Convert an ebook file into an exploded OEB book suitable for
display in viewers/preprocessing etc. '''
@ -85,7 +85,7 @@ class EbookIterator(BookmarksMixin):
self.delete_on_exit = []
self._tdir = TemporaryDirectory('_ebook_iter')
self.base = self._tdir.__enter__()
plumber = Plumber(self.pathtoebook, self.base, self.log)
plumber = Plumber(self.pathtoebook, self.base, self.log, view_kepub=view_kepub)
plumber.setup_options()
if self.pathtoebook.lower().endswith('.opf'):
plumber.opts.dont_package = True

View File

@ -158,7 +158,7 @@ def _config(): # {{{
help=_('Options for the LRF ebook viewer'))
c.add_opt('internally_viewed_formats', default=['LRF', 'EPUB', 'LIT',
'MOBI', 'PRC', 'POBI', 'AZW', 'AZW3', 'HTML', 'FB2', 'PDB', 'RB',
'SNB', 'HTMLZ'], help=_(
'SNB', 'HTMLZ', 'KEPUB'], help=_(
'Formats that are viewed using the internal viewer'))
c.add_opt('column_map', default=ALL_COLUMNS,
help=_('Columns to be displayed in the book list'))

View File

@ -1017,7 +1017,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
self.iterator = EbookIterator(pathtoebook)
self.open_progress_indicator(_('Loading ebook...'))
worker = Worker(target=partial(self.iterator.__enter__,
extract_embedded_fonts_for_qt=True))
extract_embedded_fonts_for_qt=True, view_kepub=True))
worker.start()
while worker.isAlive():
worker.join(0.1)