From 28cdb7c93faf4428bcc0d5cd0cd241a47617e2fc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 24 Feb 2025 10:11:18 +0530 Subject: [PATCH] ... --- .../ebooks/conversion/plugins/epub_input.py | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/epub_input.py b/src/calibre/ebooks/conversion/plugins/epub_input.py index e83d0e902f..25051692e9 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_input.py +++ b/src/calibre/ebooks/conversion/plugins/epub_input.py @@ -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