mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Polish books: Do not error out on epub files containing an iTunesMetadata.plist file. Fixes #1127308 (polish books error)
This commit is contained in:
parent
f78b02f0d2
commit
2d2a894e05
@ -14,7 +14,7 @@ from urlparse import urlparse
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from calibre import guess_type, CurrentDir
|
||||
from calibre import guess_type as _guess_type, CurrentDir
|
||||
from calibre.customize.ui import (plugin_for_input_format,
|
||||
plugin_for_output_format)
|
||||
from calibre.ebooks.chardet import xml_to_unicode
|
||||
@ -35,7 +35,10 @@ from calibre.utils.zipfile import ZipFile
|
||||
|
||||
exists, join, relpath = os.path.exists, os.path.join, os.path.relpath
|
||||
|
||||
OEB_FONTS = {guess_type('a.ttf')[0], guess_type('b.ttf')[0]}
|
||||
def guess_type(x):
|
||||
return _guess_type(x)[0] or 'application/octet-stream'
|
||||
|
||||
OEB_FONTS = {guess_type('a.ttf'), guess_type('b.ttf')}
|
||||
OPF_NAMESPACES = {'opf':OPF2_NS, 'dc':DC11_NS}
|
||||
|
||||
class Container(object):
|
||||
@ -77,12 +80,12 @@ class Container(object):
|
||||
path = join(dirpath, f)
|
||||
name = self.abspath_to_name(path)
|
||||
self.name_path_map[name] = path
|
||||
self.mime_map[name] = guess_type(path)[0]
|
||||
self.mime_map[name] = guess_type(path)
|
||||
# Special case if we have stumbled onto the opf
|
||||
if path == opfpath:
|
||||
self.opf_name = name
|
||||
self.opf_dir = os.path.dirname(path)
|
||||
self.mime_map[name] = guess_type('a.opf')[0]
|
||||
self.mime_map[name] = guess_type('a.opf')
|
||||
|
||||
if not hasattr(self, 'opf_name'):
|
||||
raise InvalidBook('Book has no OPF file')
|
||||
@ -206,7 +209,7 @@ class Container(object):
|
||||
def parsed(self, name):
|
||||
ans = self.parsed_cache.get(name, None)
|
||||
if ans is None:
|
||||
mime = self.mime_map.get(name, guess_type(name)[0])
|
||||
mime = self.mime_map.get(name, guess_type(name))
|
||||
ans = self.parse(self.name_path_map[name], mime)
|
||||
self.parsed_cache[name] = ans
|
||||
return ans
|
||||
@ -341,7 +344,7 @@ class Container(object):
|
||||
name. Ensures uniqueness of href and id automatically. Returns
|
||||
generated item.'''
|
||||
id_prefix = id_prefix or 'id'
|
||||
media_type = media_type or guess_type(name)[0]
|
||||
media_type = media_type or guess_type(name)
|
||||
href = self.name_to_href(name, self.opf_name)
|
||||
base, ext = href.rpartition('.')[0::2]
|
||||
all_ids = {x.get('id') for x in self.opf_xpath('//*[@id]')}
|
||||
@ -476,7 +479,7 @@ class EpubContainer(Container):
|
||||
self.container = etree.fromstring(open(container_path, 'rb').read())
|
||||
opf_files = self.container.xpath((
|
||||
r'child::ocf:rootfiles/ocf:rootfile'
|
||||
'[@media-type="%s" and @full-path]'%guess_type('a.opf')[0]
|
||||
'[@media-type="%s" and @full-path]'%guess_type('a.opf')
|
||||
), namespaces={'ocf':OCF_NS}
|
||||
)
|
||||
if not opf_files:
|
||||
@ -555,7 +558,7 @@ class EpubContainer(Container):
|
||||
outpath = self.pathtoepub
|
||||
from calibre.ebooks.tweak import zip_rebuilder
|
||||
with open(join(self.root, 'mimetype'), 'wb') as f:
|
||||
f.write(guess_type('a.epub')[0])
|
||||
f.write(guess_type('a.epub'))
|
||||
zip_rebuilder(self.root, outpath)
|
||||
|
||||
# }}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user