1
from __future__ import with_statement
3
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
4
__docformat__ = 'restructuredtext en'
6
from calibre.customize.conversion import InputFormatPlugin
8
class MOBIInput(InputFormatPlugin):
11
author = 'Kovid Goyal'
12
description = 'Convert MOBI files (.mobi, .prc, .azw) to HTML'
13
file_types = set(['mobi', 'prc', 'azw'])
15
def convert(self, stream, options, file_ext, log,
17
from calibre.ebooks.mobi.reader import MobiReader
19
mr = MobiReader(stream, log, options.input_encoding,
22
mr.extract_content('.', parse_cache)
23
raw = parse_cache.pop('calibre_raw_mobi_markup', False)
25
if isinstance(raw, unicode):
26
raw = raw.encode('utf-8')
27
open('debug-raw.html', 'wb').write(raw)
28
for f, root in parse_cache.items():
29
with open(f, 'wb') as q:
30
q.write(html.tostring(root, encoding='utf-8', method='xml',
31
include_meta_content_type=False))
32
accelerators['pagebreaks'] = '//h:div[@class="mbp_pagebreak"]'
33
return mr.created_opf_path