mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-20 21:21:35 +02:00
Enable mobi write support.
This commit is contained in:
@@ -11,13 +11,13 @@ import copy
|
||||
import re
|
||||
import numbers
|
||||
from lxml import etree
|
||||
from calibre.ebooks.oeb.base import namespace, barename
|
||||
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, urlnormalize
|
||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||
from calibre.ebooks.oeb.transforms.flatcss import KeyMapper
|
||||
from calibre.ebooks.mobi.utils import convert_color_for_font_tag
|
||||
from calibre.utils.imghdr import identify
|
||||
from polyglot.builtins import unicode_type, string_or_bytes
|
||||
from ebook_converter.ebooks.oeb.base import namespace, barename
|
||||
from ebook_converter.ebooks.oeb.base import XHTML, XHTML_NS, urlnormalize
|
||||
from ebook_converter.ebooks.oeb.stylizer import Stylizer
|
||||
from ebook_converter.ebooks.oeb.transforms.flatcss import KeyMapper
|
||||
from ebook_converter.ebooks.mobi.utils import convert_color_for_font_tag
|
||||
from ebook_converter.utils.imghdr import identify
|
||||
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes
|
||||
|
||||
MBP_NS = 'http://mobipocket.com/ns/mbp'
|
||||
|
||||
|
||||
@@ -175,9 +175,9 @@ def rescale_image(data, maxsizeb=IMAGE_MAX_SIZE, dimen=None):
|
||||
else:
|
||||
width = height = dimen
|
||||
data = scale_image(data, width=width, height=height, compression_quality=90)[-1]
|
||||
else:
|
||||
# else:
|
||||
# Replace transparent pixels with white pixels and convert to JPEG
|
||||
data = save_cover_data_to(data)
|
||||
#data = save_cover_data_to(data)
|
||||
if len(data) <= maxsizeb:
|
||||
return data
|
||||
orig_data = data # save it in case compression fails
|
||||
|
||||
@@ -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_): # {{{
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
from calibre.ebooks.oeb.base import XPath
|
||||
from ebook_converter.ebooks.oeb.base import XPath
|
||||
|
||||
|
||||
class CSSCleanup(object):
|
||||
|
||||
@@ -10,11 +10,11 @@ import re
|
||||
from struct import pack
|
||||
from io import BytesIO
|
||||
|
||||
from calibre.constants import iswindows, isosx
|
||||
from calibre.ebooks.mobi.utils import (utf8_text, to_base)
|
||||
from calibre.utils.localization import lang_as_iso639_1
|
||||
from calibre.ebooks.metadata import authors_to_sort_string
|
||||
from polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.constants import iswindows, isosx
|
||||
from ebook_converter.ebooks.mobi.utils import (utf8_text, to_base)
|
||||
from ebook_converter.utils.localization import lang_as_iso639_1
|
||||
from ebook_converter.ebooks.metadata import authors_to_sort_string
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
|
||||
EXTH_CODES = {
|
||||
'creator': 100,
|
||||
@@ -99,7 +99,7 @@ def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
|
||||
|
||||
# Write UUID as ASIN
|
||||
uuid = None
|
||||
from calibre.ebooks.oeb.base import OPF
|
||||
from ebook_converter.ebooks.oeb.base import OPF
|
||||
for x in metadata['identifier']:
|
||||
if (x.get(OPF('scheme'), None).lower() == 'uuid' or
|
||||
unicode_type(x).startswith('urn:uuid:')):
|
||||
|
||||
Reference in New Issue
Block a user