HTMLZ output: Make renaming of image files happen in filename order. Fixes #2072405 [EPUB to HTMLZ Converion Image Order Issue](https://bugs.launchpad.net/calibre/+bug/2072405)

This commit is contained in:
Kovid Goyal 2024-07-07 12:53:09 +05:30
parent eebbbf4782
commit 4175ef18ad
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -79,14 +79,15 @@ class OEB2HTML:
return self.links[href]
def map_resources(self, oeb_book):
for item in oeb_book.manifest:
if item.media_type in OEB_IMAGES:
from operator import attrgetter
images = sorted((item for item in oeb_book.manifest if item.media_type in OEB_IMAGES), key=attrgetter('href'))
for item in images:
if item.href not in self.images:
ext = os.path.splitext(item.href)[1]
fname = f'{len(self.images)}{ext}'
fname = fname.zfill(10)
fname = f'{len(self.images):06d}{ext}'
self.images[item.href] = fname
if item in oeb_book.spine:
for item in oeb_book.spine:
self.get_link_id(item.href)
root = item.data.find(XHTML('body'))
link_attrs = set(html.defs.link_attrs)
@ -96,7 +97,7 @@ class OEB2HTML:
try:
if not isinstance(el.tag, string_or_bytes):
continue
except:
except Exception:
continue
for attr in attribs:
if attr in link_attrs: