mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
d00ccaafba
commit
a9f8b465b7
@ -15,12 +15,18 @@ def add_properties(item, *props):
|
|||||||
item.set('properties', ' '.join(sorted(existing)))
|
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):
|
def collect_properties(container):
|
||||||
for item in container.opf_xpath('//opf:manifest/opf:item[@href and @media-type]'):
|
for item in container.opf_xpath('//opf:manifest/opf:item[@href and @media-type]'):
|
||||||
mt = item.get('media-type') or ''
|
mt = item.get('media-type') or ''
|
||||||
if mt.lower() not in OEB_DOCS:
|
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
|
continue
|
||||||
name = container.href_to_name(item.get('href'), container.opf_name)
|
name = container.href_to_name(item.get('href'), container.opf_name)
|
||||||
root = container.parsed(name)
|
root = container.parsed(name)
|
||||||
@ -42,6 +48,7 @@ def epub_2_to_3(container, report):
|
|||||||
upgrade_metadata(container.opf)
|
upgrade_metadata(container.opf)
|
||||||
collect_properties(container)
|
collect_properties(container)
|
||||||
container.opf.set('version', '3.0')
|
container.opf.set('version', '3.0')
|
||||||
|
fix_font_mime_types(container)
|
||||||
container.dirty(container.opf_name)
|
container.dirty(container.opf_name)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user