mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
MOBI metadata: Handle setting of non-ascii titles correctly
This commit is contained in:
parent
e84310af63
commit
d45da57047
@ -187,6 +187,8 @@ class MetadataUpdater(object):
|
|||||||
def create_exth(self, new_title=None, exth=None):
|
def create_exth(self, new_title=None, exth=None):
|
||||||
# Add an EXTH block to record 0, rewrite the stream
|
# Add an EXTH block to record 0, rewrite the stream
|
||||||
# self.hexdump(self.record0)
|
# self.hexdump(self.record0)
|
||||||
|
if isinstance(new_title, unicode):
|
||||||
|
new_title = new_title.encode(self.codec, 'replace')
|
||||||
|
|
||||||
# Fetch the existing title
|
# Fetch the existing title
|
||||||
title_offset, = unpack('>L', self.record0[0x54:0x58])
|
title_offset, = unpack('>L', self.record0[0x54:0x58])
|
||||||
@ -219,12 +221,7 @@ class MetadataUpdater(object):
|
|||||||
new_record0 = StringIO()
|
new_record0 = StringIO()
|
||||||
new_record0.write(self.record0[:0x10 + mobi_header_length])
|
new_record0.write(self.record0[:0x10 + mobi_header_length])
|
||||||
new_record0.write(exth)
|
new_record0.write(exth)
|
||||||
if new_title:
|
new_record0.write(new_title if new_title else title_in_file)
|
||||||
#new_record0.write(new_title.encode(self.codec, 'replace'))
|
|
||||||
new_title = (new_title or _('Unknown')).encode(self.codec, 'replace')
|
|
||||||
new_record0.write(new_title)
|
|
||||||
else:
|
|
||||||
new_record0.write(title_in_file)
|
|
||||||
|
|
||||||
# Pad to a 4-byte boundary
|
# Pad to a 4-byte boundary
|
||||||
trail = len(new_record0.getvalue()) % 4
|
trail = len(new_record0.getvalue()) % 4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user