From bf51722403e618e670785149df4b5f987004ee49 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 3 May 2014 21:25:17 +0530 Subject: [PATCH] Add support for viewing kepub files, by treating them as plain epub files --- src/calibre/ebooks/__init__.py | 2 +- src/calibre/ebooks/conversion/plumber.py | 4 +++- src/calibre/ebooks/oeb/iterator/__init__.py | 2 +- src/calibre/ebooks/oeb/iterator/book.py | 4 ++-- src/calibre/gui2/__init__.py | 2 +- src/calibre/gui2/viewer/main.py | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/calibre/ebooks/__init__.py b/src/calibre/ebooks/__init__.py index 3d01f8484b..25caf81778 100644 --- a/src/calibre/ebooks/__init__.py +++ b/src/calibre/ebooks/__init__.py @@ -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): diff --git a/src/calibre/ebooks/conversion/plumber.py b/src/calibre/ebooks/conversion/plumber.py index cb49801328..c9f2151647 100644 --- a/src/calibre/ebooks/conversion/plumber.py +++ b/src/calibre/ebooks/conversion/plumber.py @@ -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...') diff --git a/src/calibre/ebooks/oeb/iterator/__init__.py b/src/calibre/ebooks/oeb/iterator/__init__.py index 3e2dfc5df2..391c314cdf 100644 --- a/src/calibre/ebooks/oeb/iterator/__init__.py +++ b/src/calibre/ebooks/oeb/iterator/__init__.py @@ -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): diff --git a/src/calibre/ebooks/oeb/iterator/book.py b/src/calibre/ebooks/oeb/iterator/book.py index 8868e7cbb1..1878e2c6fd 100644 --- a/src/calibre/ebooks/oeb/iterator/book.py +++ b/src/calibre/ebooks/oeb/iterator/book.py @@ -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 diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index f3eec4eefa..1828957232 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -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')) diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py index 494683d88b..b47bc25a8b 100644 --- a/src/calibre/gui2/viewer/main.py +++ b/src/calibre/gui2/viewer/main.py @@ -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)