From a9f8b465b74291e336071955c969b352d64e5bc4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 13 Apr 2018 11:34:53 +0530 Subject: [PATCH] DRYer --- src/calibre/ebooks/oeb/polish/upgrade.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/upgrade.py b/src/calibre/ebooks/oeb/polish/upgrade.py index f97c13d15a..590f7c79a6 100644 --- a/src/calibre/ebooks/oeb/polish/upgrade.py +++ b/src/calibre/ebooks/oeb/polish/upgrade.py @@ -15,12 +15,18 @@ def add_properties(item, *props): item.set('properties', ' '.join(sorted(existing))) +def fix_font_mime_types(container): + for item in container.opf_xpath('//opf:manifest/opf:item[@href and @media-type]'): + mt = item.get('media-type') or '' + if mt.lower() not in OEB_FONTS: + name = container.href_to_name(item.get('href'), container.opf_name) + item.set('media-type', container.guess_type(name)) + + def collect_properties(container): for item in container.opf_xpath('//opf:manifest/opf:item[@href and @media-type]'): mt = item.get('media-type') or '' if mt.lower() not in OEB_DOCS: - if mt.lower() in OEB_FONTS and 'woff' not in mt.lower(): - item.set('media-type', 'application/font-sfnt') continue name = container.href_to_name(item.get('href'), container.opf_name) root = container.parsed(name) @@ -42,6 +48,7 @@ def epub_2_to_3(container, report): upgrade_metadata(container.opf) collect_properties(container) container.opf.set('version', '3.0') + fix_font_mime_types(container) container.dirty(container.opf_name)