Skip to content

Commit

Permalink
Edit book: Fix extra invalid entries being generated in the manifest …
Browse files Browse the repository at this point in the history
…when editing an AZW3 file that has no images.
  • Loading branch information
kovidgoyal committed May 1, 2014
1 parent d1870ea commit b55e526
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
17 changes: 16 additions & 1 deletion src/calibre/ebooks/mobi/reader/mobi8.py
Expand Up @@ -61,7 +61,8 @@ def reverse_tag_iter(block):

class Mobi8Reader(object):

def __init__(self, mobi6_reader, log):
def __init__(self, mobi6_reader, log, for_tweak=False):
self.for_tweak = for_tweak
self.mobi6_reader, self.log = mobi6_reader, log
self.header = mobi6_reader.book_header
self.encrypted_fonts = []
Expand Down Expand Up @@ -459,6 +460,20 @@ def write_opf(self, guide, toc, spine, resource_map):
def exclude(path):
return os.path.basename(path) == 'debug-raw.html'

# If there are no images then the azw3 input plugin dumps all
# binary records as .unknown images, remove them
if self.for_tweak and os.path.exists('images') and os.path.isdir('images'):
files = os.listdir('images')
unknown = [x for x in files if x.endswith('.unknown')]
if len(files) == len(unknown):
[os.remove('images/'+f) for f in files]

if self.for_tweak:
try:
os.remove('debug-raw.html')
except:
pass

opf.create_manifest_from_files_in([os.getcwdu()], exclude=exclude)
for entry in opf.manifest:
if entry.mime_type == 'text/html':
Expand Down
13 changes: 1 addition & 12 deletions src/calibre/ebooks/oeb/polish/container.py
Expand Up @@ -1022,20 +1022,9 @@ def do_explode(path, dest):
mr = MobiReader(stream, default_log, None, None)

with CurrentDir(dest):
mr = Mobi8Reader(mr, default_log)
mr = Mobi8Reader(mr, default_log, for_tweak=True)
opf = os.path.abspath(mr())
obfuscated_fonts = mr.encrypted_fonts
# If there are no images then the azw3 input plugin dumps all
# binary records as .unknown images, remove them
if os.path.exists('images') and os.path.isdir('images'):
files = os.listdir('images')
unknown = [x for x in files if x.endswith('.unknown')]
if len(files) == len(unknown):
[os.remove('images/'+f) for f in files]
try:
os.remove('debug-raw.html')
except:
pass

return opf, obfuscated_fonts

Expand Down

0 comments on commit b55e526

Please sign in to comment.