diff --git a/src/calibre/ebooks/html/input.py b/src/calibre/ebooks/html/input.py
index 079e990de3..b22f7d2791 100644
--- a/src/calibre/ebooks/html/input.py
+++ b/src/calibre/ebooks/html/input.py
@@ -309,9 +309,9 @@ class HTMLInput(InputFormatPlugin):
def create_oebbook(self, htmlpath, basedir, opts, log, mi):
from calibre.ebooks.conversion.plumber import create_oebbook
- from calibre.ebooks.oeb.base import DirContainer, \
- rewrite_links, urlnormalize, urldefrag, BINARY_MIME, OEB_STYLES, \
- xpath
+ from calibre.ebooks.oeb.base import (DirContainer,
+ rewrite_links, urlnormalize, urldefrag, BINARY_MIME, OEB_STYLES,
+ xpath)
from calibre import guess_type
from calibre.ebooks.oeb.transforms.metadata import \
meta_info_to_oeb_metadata
@@ -345,7 +345,8 @@ class HTMLInput(InputFormatPlugin):
htmlfile_map = {}
for f in filelist:
path = f.path
- oeb.container = DirContainer(os.path.dirname(path), log)
+ oeb.container = DirContainer(os.path.dirname(path), log,
+ ignore_opf=True)
bname = os.path.basename(path)
id, href = oeb.manifest.generate(id='html',
href=ascii_filename(bname))
@@ -369,7 +370,7 @@ class HTMLInput(InputFormatPlugin):
for f in filelist:
path = f.path
dpath = os.path.dirname(path)
- oeb.container = DirContainer(dpath, log)
+ oeb.container = DirContainer(dpath, log, ignore_opf=True)
item = oeb.manifest.hrefs[htmlfile_map[path]]
rewrite_links(item.data, partial(self.resource_adder, base=dpath))
@@ -409,7 +410,7 @@ class HTMLInput(InputFormatPlugin):
if not item.linear: continue
toc.add(title, item.href)
- oeb.container = DirContainer(os.getcwdu(), oeb.log)
+ oeb.container = DirContainer(os.getcwdu(), oeb.log, ignore_opf=True)
return oeb
def link_to_local_path(self, link_, base=None):
@@ -456,7 +457,7 @@ class HTMLInput(InputFormatPlugin):
href=bhref)
self.oeb.log.debug('Added', link)
self.oeb.container = self.DirContainer(os.path.dirname(link),
- self.oeb.log)
+ self.oeb.log, ignore_opf=True)
# Load into memory
guessed = self.guess_type(href)[0]
media_type = guessed or self.BINARY_MIME
diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py
index f2c9696976..c07386e1fd 100644
--- a/src/calibre/ebooks/oeb/base.py
+++ b/src/calibre/ebooks/oeb/base.py
@@ -446,22 +446,23 @@ class NullContainer(object):
class DirContainer(object):
"""Filesystem directory container."""
- def __init__(self, path, log):
+ def __init__(self, path, log, ignore_opf=False):
self.log = log
if isbytestring(path):
path = path.decode(filesystem_encoding)
+ self.opfname = None
ext = os.path.splitext(path)[1].lower()
if ext == '.opf':
self.opfname = os.path.basename(path)
self.rootdir = os.path.dirname(path)
return
self.rootdir = path
- for path in self.namelist():
- ext = os.path.splitext(path)[1].lower()
- if ext == '.opf':
- self.opfname = path
- return
- self.opfname = None
+ if not ignore_opf:
+ for path in self.namelist():
+ ext = os.path.splitext(path)[1].lower()
+ if ext == '.opf':
+ self.opfname = path
+ return
def read(self, path):
if path is None: