1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-21 05:31:30 +02:00

Enable mobi write support.

This commit is contained in:
2020-04-13 15:25:19 +02:00
parent 32b86ab224
commit a4533957f7
15 changed files with 77 additions and 90 deletions
@@ -11,9 +11,9 @@ from struct import pack
import io
from collections import OrderedDict, defaultdict
from calibre.ebooks.mobi.utils import (encint, encode_number_as_hex,
from ebook_converter.ebooks.mobi.utils import (encint, encode_number_as_hex,
encode_tbs, align_block, RECORD_SIZE, CNCX as CNCX_)
from polyglot.builtins import filter, iteritems, itervalues, map, range
from ebook_converter.polyglot.builtins import filter, iteritems, itervalues, map, range
class CNCX(CNCX_): # {{{
+12 -12
View File
@@ -9,16 +9,16 @@ __docformat__ = 'restructuredtext en'
import io, random, time
from struct import pack
from calibre.ebooks import normalize
from calibre.ebooks.mobi.writer2.serializer import Serializer
from calibre.ebooks.compression.palmdoc import compress_doc
from calibre.ebooks.mobi.langcodes import iana2mobi
from calibre.utils.filenames import ascii_filename
from calibre.ebooks.mobi.writer2 import (PALMDOC, UNCOMPRESSED)
from calibre.ebooks.mobi.utils import (encint, encode_trailing_data,
from ebook_converter.ebooks import normalize
from ebook_converter.ebooks.mobi.writer2.serializer import Serializer
from ebook_converter.ebooks.compression.palmdoc import compress_doc
from ebook_converter.ebooks.mobi.langcodes import iana2mobi
from ebook_converter.utils.filenames import ascii_filename
from ebook_converter.ebooks.mobi.writer2 import (PALMDOC, UNCOMPRESSED)
from ebook_converter.ebooks.mobi.utils import (encint, encode_trailing_data,
align_block, detect_periodical, RECORD_SIZE, create_text_record)
from calibre.ebooks.mobi.writer2.indexer import Indexer
from polyglot.builtins import iteritems, unicode_type, range
from ebook_converter.ebooks.mobi.writer2.indexer import Indexer
from ebook_converter.polyglot.builtins import iteritems, unicode_type, range
# Disabled as I dont care about uncrossable breaks
WRITE_UNCROSSABLE_BREAKS = False
@@ -201,7 +201,7 @@ class MobiWriter(object):
# header as well
bt = 0x103 if self.indexer.is_flat_periodical else 0x101
from calibre.ebooks.mobi.writer8.exth import build_exth
from ebook_converter.ebooks.mobi.writer8.exth import build_exth
exth = build_exth(metadata,
prefer_author_sort=self.opts.prefer_author_sort,
is_periodical=self.is_periodical,
@@ -374,9 +374,9 @@ class MobiWriter(object):
# }}}
def generate_joint_record0(self): # {{{
from calibre.ebooks.mobi.writer8.mobi import (MOBIHeader,
from ebook_converter.ebooks.mobi.writer8.mobi import (MOBIHeader,
HEADER_FIELDS)
from calibre.ebooks.mobi.writer8.exth import build_exth
from ebook_converter.ebooks.mobi.writer8.exth import build_exth
# Insert resource records
first_image_record = None
@@ -46,8 +46,14 @@ class Resources(object):
try:
return func(data)
except Exception:
if 'png' != what(None, data):
ext = what(None, data)
if ext not in ('png', 'gif'):
raise
if ext == 'gif':
with PersistentTemporaryFile(suffix='.gif') as pt:
pt.write(data)
return mobify_image(data)
with PersistentTemporaryFile(suffix='.png') as pt:
pt.write(data)
try:
@@ -12,13 +12,13 @@ import unicodedata
from collections import defaultdict
from io import BytesIO
from calibre.ebooks.mobi.mobiml import MBP_NS
from calibre.ebooks.mobi.utils import is_guide_ref_start
from calibre.ebooks.oeb.base import (
from ebook_converter.ebooks.mobi.mobiml import MBP_NS
from ebook_converter.ebooks.mobi.utils import is_guide_ref_start
from ebook_converter.ebooks.oeb.base import (
OEB_DOCS, XHTML, XHTML_NS, XML_NS, namespace, prefixname, urlnormalize
)
from polyglot.builtins import unicode_type, string_or_bytes
from polyglot.urllib import urldefrag
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes
from ebook_converter.polyglot.urllib import urldefrag
class Buf(BytesIO):