From 51e94dcc65c59710bab76260b894476f74877c70 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 19 Oct 2020 08:30:17 +0530 Subject: [PATCH] Container: Make detecting OPF files a bit more robust --- src/calibre/ebooks/oeb/polish/container.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index 4c17fb0902..3f5ff12994 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -278,6 +278,7 @@ class Container(ContainerBase): # {{{ # Map of relative paths with '/' separators from root of unzipped ePub # to absolute paths on filesystem with os-specific separators opfpath = os.path.abspath(os.path.realpath(opfpath)) + all_opf_files = [] for dirpath, _dirnames, filenames in os.walk(self.root): for f in filenames: path = join(dirpath, f) @@ -289,6 +290,12 @@ class Container(ContainerBase): # {{{ self.opf_name = name self.opf_dir = os.path.dirname(path) self.mime_map[name] = guess_type('a.opf') + if path.lower().endswith('.opf'): + all_opf_files.append((name, os.path.dirname(path))) + + if not hasattr(self, 'opf_name') and all_opf_files: + self.opf_name, self.opf_dir = all_opf_files[0] + self.mime_map[self.opf_name] = guess_type('a.opf') if not hasattr(self, 'opf_name'): raise InvalidBook('Could not locate opf file: %r'%opfpath)