From ad4c7687c89c2865bbe94ecd40478f44fb037e10 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 20 Dec 2024 10:43:34 +0100 Subject: [PATCH] Allow specifying kepubify arguments --- cps/admin.py | 1 + cps/config_sql.py | 1 + cps/tasks/convert.py | 13 +++++++++++++ cps/templates/config_edit.html | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/cps/admin.py b/cps/admin.py index 71403e6c39..0e6f8b0bb5 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -1805,6 +1805,7 @@ def _configuration_update_helper(): _config_string(to_save, "config_calibre") _config_string(to_save, "config_binariesdir") _config_string(to_save, "config_kepubifypath") + _config_string(to_save, "config_kepubifyopts") if "config_binariesdir" in to_save: calibre_status = helper.check_calibre(config.config_binariesdir) if calibre_status: diff --git a/cps/config_sql.py b/cps/config_sql.py index 7e7d033d1c..5593825d2c 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -141,6 +141,7 @@ class _Settings(_Base): config_ldap_group_name = Column(String, default='calibreweb') config_kepubifypath = Column(String, default=None) + config_kepubifyopts = Column(String) config_converterpath = Column(String, default=None) config_binariesdir = Column(String, default=None) config_calibre = Column(String) diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index dc0af0c442..6d1e947b1e 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -227,7 +227,20 @@ def _convert_kepubify(self, file_path, format_old_ext, format_new_ext): filename = file_path + format_old_ext temp_file_path = os.path.dirname(file_path) quotes = [1, 3] + quotes_index = 4 command = [config.config_kepubifypath, filename, '-o', temp_file_path, '-i'] + if config.config_kepubifyopts: + parameters = re.findall(r"(--[\w-]+)(?:(\s(?:(\".+\")|(?:.+?)))(?:\s|$))?", + config.config_kepubifyopts, re.IGNORECASE | re.UNICODE) + if parameters: + for param in parameters: + command.append(strip_whitespaces(param[0])) + quotes_index += 1 + if param[1] != "": + parsed = strip_whitespaces(param[1]).strip("\"") + command.append(parsed) + quotes.append(quotes_index) + quotes_index += 1 try: p = process_open(command, quotes) except OSError as e: diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 4018db2e99..d9627c7398 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -340,6 +340,10 @@

+
+ + +
{% if feature_support['rar'] %}