From 9453d87b38d493a8847b66a020815209a64bf5d3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 28 Dec 2017 09:19:59 +0530 Subject: [PATCH] EPUB input: Handle books that erroneously set the mimetype for font files to text/plain --- .../ebooks/conversion/plugins/epub_input.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/epub_input.py b/src/calibre/ebooks/conversion/plugins/epub_input.py index c5742f2c7d..b6f857ef1f 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_input.py +++ b/src/calibre/ebooks/conversion/plugins/epub_input.py @@ -294,11 +294,22 @@ class EPUBInput(InputFormatPlugin): not_for_spine = set() for y in opf.itermanifest(): id_ = y.get('id', None) - if id_ and y.get('media-type', None) in { - 'application/vnd.adobe-page-template+xml', 'application/vnd.adobe.page-template+xml', - 'application/adobe-page-template+xml', 'application/adobe.page-template+xml', - 'application/text'}: - not_for_spine.add(id_) + if id_: + mt = y.get('media-type', None) + if mt in { + 'application/vnd.adobe-page-template+xml', + 'application/vnd.adobe.page-template+xml', + 'application/adobe-page-template+xml', + 'application/adobe.page-template+xml', + 'application/text' + }: + not_for_spine.add(id_) + ext = y.get('href', '').rpartition('.')[-1].lower() + if mt == 'text/plain' and ext in {'otf', 'ttf'}: + # some epub authoring software sets font mime types to + # text/plain + not_for_spine.add(id_) + y.set('media-type', 'application/font') seen = set() for x in list(opf.iterspine()):