Skip to content

Commit

Permalink
Add support for viewing kepub files, by treating them as plain epub f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
kovidgoyal committed May 3, 2014
1 parent 0d28842 commit bf51722
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/calibre/ebooks/__init__.py
Expand Up @@ -31,7 +31,7 @@ class ParserError(ValueError):
'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):

Expand Down
4 changes: 3 additions & 1 deletion src/calibre/ebooks/conversion/plumber.py
Expand Up @@ -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
Expand Down Expand Up @@ -702,6 +702,8 @@ def __init__(self, input, output, log, report_progress=DummyReporter(),
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...')
Expand Down
2 changes: 1 addition & 1 deletion src/calibre/ebooks/oeb/iterator/__init__.py
Expand Up @@ -14,7 +14,7 @@
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):

Expand Down
4 changes: 2 additions & 2 deletions src/calibre/ebooks/oeb/iterator/book.py
Expand Up @@ -75,7 +75,7 @@ def search(self, text, index, backwards=False):
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. '''
Expand All @@ -85,7 +85,7 @@ def __enter__(self, processed=False, only_input_plugin=False,
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
Expand Down
2 changes: 1 addition & 1 deletion src/calibre/gui2/__init__.py
Expand Up @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion src/calibre/gui2/viewer/main.py
Expand Up @@ -1017,7 +1017,7 @@ def load_ebook(self, pathtoebook, open_at=None):
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)
Expand Down

0 comments on commit bf51722

Please sign in to comment.