mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When setting metadata in MOBI files fix cover not being updated if the mobi file has its first image record as the cover (this is the case for calibre produced MOBI files). Also remove obsolete MOBI writer code.
This commit is contained in:
parent
1195c37da5
commit
49a4e5e02f
@ -18,9 +18,6 @@ class MOBIOutput(OutputFormatPlugin):
|
|||||||
file_type = 'mobi'
|
file_type = 'mobi'
|
||||||
|
|
||||||
options = set([
|
options = set([
|
||||||
OptionRecommendation(name='rescale_images', recommended_value=False,
|
|
||||||
help=_('Modify images to meet Palm device size limitations.')
|
|
||||||
),
|
|
||||||
OptionRecommendation(name='prefer_author_sort',
|
OptionRecommendation(name='prefer_author_sort',
|
||||||
recommended_value=False, level=OptionRecommendation.LOW,
|
recommended_value=False, level=OptionRecommendation.LOW,
|
||||||
help=_('When present, use author sort field as author.')
|
help=_('When present, use author sort field as author.')
|
||||||
@ -167,12 +164,7 @@ class MOBIOutput(OutputFormatPlugin):
|
|||||||
mobimlizer(oeb, opts)
|
mobimlizer(oeb, opts)
|
||||||
self.check_for_periodical()
|
self.check_for_periodical()
|
||||||
write_page_breaks_after_item = input_plugin is not plugin_for_input_format('cbz')
|
write_page_breaks_after_item = input_plugin is not plugin_for_input_format('cbz')
|
||||||
from calibre.utils.config import tweaks
|
|
||||||
if tweaks.get('new_mobi_writer', True):
|
|
||||||
from calibre.ebooks.mobi.writer2.main import MobiWriter
|
from calibre.ebooks.mobi.writer2.main import MobiWriter
|
||||||
MobiWriter
|
|
||||||
else:
|
|
||||||
from calibre.ebooks.mobi.writer import MobiWriter
|
|
||||||
writer = MobiWriter(opts,
|
writer = MobiWriter(opts,
|
||||||
write_page_breaks_after_item=write_page_breaks_after_item)
|
write_page_breaks_after_item=write_page_breaks_after_item)
|
||||||
writer(oeb, output_path)
|
writer(oeb, output_path)
|
||||||
|
@ -9,16 +9,21 @@ __copyright__ = '2009, Kovid Goyal kovid@kovidgoyal.net and ' \
|
|||||||
'Marshall T. Vandegrift <llasram@gmail.com>'
|
'Marshall T. Vandegrift <llasram@gmail.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, cStringIO
|
import os, cStringIO, imghdr
|
||||||
from struct import pack, unpack
|
from struct import pack, unpack
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
from calibre.ebooks import normalize
|
from calibre.ebooks import normalize
|
||||||
from calibre.ebooks.mobi import MobiError
|
from calibre.ebooks.mobi import MobiError, MAX_THUMB_DIMEN
|
||||||
from calibre.ebooks.mobi.writer import rescale_image, MAX_THUMB_DIMEN
|
from calibre.ebooks.mobi.utils import rescale_image
|
||||||
from calibre.ebooks.mobi.langcodes import iana2mobi
|
from calibre.ebooks.mobi.langcodes import iana2mobi
|
||||||
from calibre.utils.date import now as nowf
|
from calibre.utils.date import now as nowf
|
||||||
|
|
||||||
|
def is_image(ss):
|
||||||
|
if ss is None:
|
||||||
|
return False
|
||||||
|
return imghdr.what(None, ss[:200]) is not None
|
||||||
|
|
||||||
class StreamSlicer(object):
|
class StreamSlicer(object):
|
||||||
|
|
||||||
def __init__(self, stream, start=0, stop=None):
|
def __init__(self, stream, start=0, stop=None):
|
||||||
@ -161,11 +166,10 @@ class MetadataUpdater(object):
|
|||||||
if id == 106:
|
if id == 106:
|
||||||
self.timestamp = content
|
self.timestamp = content
|
||||||
elif id == 201:
|
elif id == 201:
|
||||||
rindex, = self.cover_rindex, = unpack('>i', content)
|
rindex, = self.cover_rindex, = unpack('>I', content)
|
||||||
if rindex > 0 :
|
|
||||||
self.cover_record = self.record(rindex + image_base)
|
self.cover_record = self.record(rindex + image_base)
|
||||||
elif id == 202:
|
elif id == 202:
|
||||||
rindex, = self.thumbnail_rindex, = unpack('>i', content)
|
rindex, = self.thumbnail_rindex, = unpack('>I', content)
|
||||||
if rindex > 0 :
|
if rindex > 0 :
|
||||||
self.thumbnail_record = self.record(rindex + image_base)
|
self.thumbnail_record = self.record(rindex + image_base)
|
||||||
|
|
||||||
@ -416,17 +420,17 @@ class MetadataUpdater(object):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if self.cover_record is not None:
|
if is_image(self.cover_record):
|
||||||
size = len(self.cover_record)
|
size = len(self.cover_record)
|
||||||
cover = rescale_image(data, size)
|
cover = rescale_image(data, size)
|
||||||
if len(cover) <= size:
|
if len(cover) <= size:
|
||||||
cover += '\0' * (size - len(cover))
|
cover += b'\0' * (size - len(cover))
|
||||||
self.cover_record[:] = cover
|
self.cover_record[:] = cover
|
||||||
if self.thumbnail_record is not None:
|
if is_image(self.thumbnail_record):
|
||||||
size = len(self.thumbnail_record)
|
size = len(self.thumbnail_record)
|
||||||
thumbnail = rescale_image(data, size, dimen=MAX_THUMB_DIMEN)
|
thumbnail = rescale_image(data, size, dimen=MAX_THUMB_DIMEN)
|
||||||
if len(thumbnail) <= size:
|
if len(thumbnail) <= size:
|
||||||
thumbnail += '\0' * (size - len(thumbnail))
|
thumbnail += b'\0' * (size - len(thumbnail))
|
||||||
self.thumbnail_record[:] = thumbnail
|
self.thumbnail_record[:] = thumbnail
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -6,3 +6,8 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
class MobiError(Exception):
|
class MobiError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
MAX_THUMB_SIZE = 16 * 1024
|
||||||
|
MAX_THUMB_DIMEN = (180, 240)
|
||||||
|
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -21,6 +21,7 @@ from calibre.ebooks.mobi.writer2 import (PALMDOC, UNCOMPRESSED, RECORD_SIZE)
|
|||||||
from calibre.ebooks.mobi.utils import (rescale_image, encint,
|
from calibre.ebooks.mobi.utils import (rescale_image, encint,
|
||||||
encode_trailing_data, align_block, detect_periodical)
|
encode_trailing_data, align_block, detect_periodical)
|
||||||
from calibre.ebooks.mobi.writer2.indexer import Indexer
|
from calibre.ebooks.mobi.writer2.indexer import Indexer
|
||||||
|
from calibre.ebooks.mobi import MAX_THUMB_DIMEN, MAX_THUMB_SIZE
|
||||||
|
|
||||||
EXTH_CODES = {
|
EXTH_CODES = {
|
||||||
'creator': 100,
|
'creator': 100,
|
||||||
@ -46,9 +47,6 @@ EXTH_CODES = {
|
|||||||
# Disabled as I dont care about uncrossable breaks
|
# Disabled as I dont care about uncrossable breaks
|
||||||
WRITE_UNCROSSABLE_BREAKS = False
|
WRITE_UNCROSSABLE_BREAKS = False
|
||||||
|
|
||||||
MAX_THUMB_SIZE = 16 * 1024
|
|
||||||
MAX_THUMB_DIMEN = (180, 240)
|
|
||||||
|
|
||||||
class MobiWriter(object):
|
class MobiWriter(object):
|
||||||
COLLAPSE_RE = re.compile(r'[ \t\r\n\v]+')
|
COLLAPSE_RE = re.compile(r'[ \t\r\n\v]+')
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class PluginWidget(Widget, Ui_Form):
|
|||||||
|
|
||||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||||
Widget.__init__(self, parent,
|
Widget.__init__(self, parent,
|
||||||
['prefer_author_sort', 'rescale_images', 'toc_title',
|
['prefer_author_sort', 'toc_title',
|
||||||
'mobi_ignore_margins', 'mobi_toc_at_start',
|
'mobi_ignore_margins', 'mobi_toc_at_start',
|
||||||
'dont_compress', 'no_inline_toc', 'share_not_sync',
|
'dont_compress', 'no_inline_toc', 'share_not_sync',
|
||||||
'personal_doc']#, 'mobi_navpoints_only_deepest']
|
'personal_doc']#, 'mobi_navpoints_only_deepest']
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>521</width>
|
<width>588</width>
|
||||||
<height>342</height>
|
<height>342</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -14,48 +14,7 @@
|
|||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0">
|
<item row="7" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Title for Table of Contents:</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>opt_toc_title</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QLineEdit" name="opt_toc_title"/>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="opt_rescale_images">
|
|
||||||
<property name="text">
|
|
||||||
<string>Rescale images for &Palm devices</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="opt_prefer_author_sort">
|
|
||||||
<property name="text">
|
|
||||||
<string>Use author &sort for author</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="0">
|
|
||||||
<widget class="QCheckBox" name="opt_dont_compress">
|
|
||||||
<property name="text">
|
|
||||||
<string>Disable compression of the file contents</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QCheckBox" name="opt_no_inline_toc">
|
|
||||||
<property name="text">
|
|
||||||
<string>Do not add Table of Contents to book</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="8" column="0" colspan="2">
|
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Kindle options</string>
|
<string>Kindle options</string>
|
||||||
@ -98,7 +57,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="9" column="0">
|
<item row="8" column="0">
|
||||||
<spacer name="verticalSpacer_2">
|
<spacer name="verticalSpacer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -125,6 +84,40 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="4" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="opt_prefer_author_sort">
|
||||||
|
<property name="text">
|
||||||
|
<string>Use author &sort for author</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Title for Table of Contents:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>opt_toc_title</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="opt_toc_title"/>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QCheckBox" name="opt_dont_compress">
|
||||||
|
<property name="text">
|
||||||
|
<string>Disable compression of the file contents</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QCheckBox" name="opt_no_inline_toc">
|
||||||
|
<property name="text">
|
||||||
|
<string>Do not add Table of Contents to book</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user