This commit is contained in:
Kovid Goyal 2025-02-24 10:11:18 +05:30
parent f1bda707e9
commit 28cdb7c93f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -285,20 +285,7 @@ class EPUBInput(InputFormatPlugin):
raise ValueError(f'{path} is not a valid EPUB file (could not find opf)')
if is_kepub:
from calibre.ebooks.oeb.polish.container import Container
from calibre.ebooks.oeb.polish.errors import drm_message
from calibre.ebooks.oeb.polish.kepubify import check_for_kobo_drm, unkepubify_container
container = Container(os.getcwd(), opf, log)
if self.for_viewer:
log('Checking for Kobo DRM...')
with drm_message(_('The file {} is locked with DRM. It cannot be viewed').format(path)):
check_for_kobo_drm(container)
else:
log('Removing Kobo markup...')
with drm_message(_('The file {} is locked with DRM. It cannot be converted').format(path)):
unkepubify_container(container)
container.commit()
del container
self.unkepubify(path, opf, log)
opf = os.path.relpath(opf, os.getcwd())
parts = os.path.split(opf)
@ -370,6 +357,21 @@ class EPUBInput(InputFormatPlugin):
return os.path.abspath('content.opf')
def unkepubify(self, path: str, opf: str, log) -> None:
from calibre.ebooks.oeb.polish.container import Container
from calibre.ebooks.oeb.polish.errors import drm_message
from calibre.ebooks.oeb.polish.kepubify import check_for_kobo_drm, unkepubify_container
container = Container(os.getcwd(), opf, log)
if self.for_viewer:
log('Checking for Kobo DRM...')
with drm_message(_('The file {} is locked with DRM. It cannot be viewed').format(path)):
check_for_kobo_drm(container)
else:
log('Removing Kobo markup...')
with drm_message(_('The file {} is locked with DRM. It cannot be converted').format(path)):
unkepubify_container(container)
container.commit()
def convert_epub3_nav(self, nav_path, opf, log, opts):
from tempfile import NamedTemporaryFile