MOBI Output: Ensure that MOBI files always have 8KB worth of null bytes at the end of record 0. This appears to be necessary for Amazon to be able to add DRM to calibre generated MOBI files sent to their publishing service.

This commit is contained in:
Kovid Goyal 2011-04-15 15:31:55 -06:00
parent d84a8a721a
commit 7736144410
3 changed files with 6 additions and 2 deletions

View File

@ -259,6 +259,7 @@ class MetadataUpdater(object):
trail = len(new_record0.getvalue()) % 4 trail = len(new_record0.getvalue()) % 4
pad = '\0' * (4 - trail) # Always pad w/ at least 1 byte pad = '\0' * (4 - trail) # Always pad w/ at least 1 byte
new_record0.write(pad) new_record0.write(pad)
new_record0.write('\0'*(1024*8))
# Rebuild the stream, update the pdbrecords pointers # Rebuild the stream, update the pdbrecords pointers
self.patchSection(0,new_record0.getvalue()) self.patchSection(0,new_record0.getvalue())

View File

@ -274,7 +274,7 @@ class MOBIHeader(object):
self.exth = EXTHHeader(self.raw[self.exth_offset:]) self.exth = EXTHHeader(self.raw[self.exth_offset:])
self.end_of_exth = self.exth_offset + self.exth.length self.end_of_exth = self.exth_offset + self.exth.length
self.bytes_after_exth = len(self.raw) - self.end_of_exth self.bytes_after_exth = self.fullname_offset - self.end_of_exth
def __str__(self): def __str__(self):
ans = ['*'*20 + ' MOBI Header '+ '*'*20] ans = ['*'*20 + ' MOBI Header '+ '*'*20]
@ -321,6 +321,9 @@ class MOBIHeader(object):
ans += '\n\n' + str(self.exth) ans += '\n\n' + str(self.exth)
ans += '\n\nBytes after EXTH: %d'%self.bytes_after_exth ans += '\n\nBytes after EXTH: %d'%self.bytes_after_exth
ans += '\nNumber of bytes after full name: %d' % (len(self.raw) - (self.fullname_offset +
self.fullname_length))
ans += '\nRecord 0 length: %d'%len(self.raw) ans += '\nRecord 0 length: %d'%len(self.raw)
return ans return ans

View File

@ -1511,7 +1511,7 @@ class MobiWriter(object):
record0.write(exth) record0.write(exth)
record0.write(title) record0.write(title)
record0 = record0.getvalue() record0 = record0.getvalue()
self._records[0] = record0 + ('\0' * (2452 - len(record0))) self._records[0] = record0 + ('\0' * (1024*8))
def _build_exth(self): def _build_exth(self):
oeb = self._oeb oeb = self._oeb