From 1086296d1dd44854493fd8c9d673ac7fd698f22b Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 9 Dec 2023 11:23:26 +0100 Subject: [PATCH] Make embed metadata configurable --- cps/admin.py | 1 + cps/config_sql.py | 1 + cps/helper.py | 5 ++--- cps/tasks/convert.py | 33 ++++++++++++++------------------- cps/templates/config_edit.html | 4 ++++ 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index a933f8bc..3af3e422 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -1745,6 +1745,7 @@ def _configuration_update_helper(): _config_checkbox_int(to_save, "config_uploading") _config_checkbox_int(to_save, "config_unicode_filename") + _config_checkbox_int(to_save, "config_embed_metadata") # Reboot on config_anonbrowse with enabled ldap, as decoraters are changed in this case reboot_required |= (_config_checkbox_int(to_save, "config_anonbrowse") and config.config_login_type == constants.LOGIN_LDAP) diff --git a/cps/config_sql.py b/cps/config_sql.py index 485c3fc2..ac8f7b5d 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -144,6 +144,7 @@ class _Settings(_Base): config_rarfile_location = Column(String, default=None) config_upload_formats = Column(String, default=','.join(constants.EXTENSIONS_UPLOAD)) config_unicode_filename = Column(Boolean, default=False) + config_embed_metadata = Column(Boolean, default=True) config_updatechannel = Column(Integer, default=constants.UPDATE_STABLE) diff --git a/cps/helper.py b/cps/helper.py index a8acc750..326e2355 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -942,14 +942,13 @@ def do_download_file(book, book_format, client, data, headers): df = gd.getFileFromEbooksFolder(book.path, book_name + "." + book_format) # log.debug('%s', time.time() - startTime) if df: - if config.config_binariesdir: + if config.config_binariesdir and config.config_embed_metadata: output_path = os.path.join(config.config_calibre_dir, book.path) if not os.path.exists(output_path): os.makedirs(output_path) output = os.path.join(config.config_calibre_dir, book.path, book_name + "." + book_format) gd.downloadFile(book.path, book_name + "." + book_format, output) filename, download_name = do_calibre_export(book, book_format) - # ToDo: delete path in calibre-folder structure else: return gd.do_gdrive_download(df, headers) else: @@ -963,7 +962,7 @@ def do_download_file(book, book_format, client, data, headers): if client == "kobo" and book_format == "kepub": headers["Content-Disposition"] = headers["Content-Disposition"].replace(".kepub", ".kepub.epub") - if config.config_binariesdir: + if config.config_binariesdir and config.config_embed_metadata: filename, download_name = do_calibre_export(book, book_format) else: download_name = book_name diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 5bee0773..a39b3f61 100755 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -238,28 +238,23 @@ class TaskConvert(CalibreTask): def _convert_calibre(self, file_path, format_old_ext, format_new_ext, has_cover): book_id = self.book_id try: - # Linux py2.7 encode as list without quotes no empty element for parameters - # linux py3.x no encode and as list without quotes no empty element for parameters - # windows py2.7 encode as string with quotes empty element for parameters is okay - # windows py 3.x no encode and as string with quotes empty element for parameters is okay - # separate handling for windows and linux - - quotes = [3, 5] - tmp_dir = get_temp_dir() - #tmp_dir = os.path.join(gettempdir(), 'calibre_web') - #if not os.path.isdir(tmp_dir): - # os.mkdir(tmp_dir) - calibredb_binarypath = os.path.join(config.config_binariesdir, SUPPORTED_CALIBRE_BINARIES["calibredb"]) - opf_command = [calibredb_binarypath, 'show_metadata', '--as-opf', str(book_id), '--with-library', config.config_calibre_dir] - p = process_open(opf_command, quotes) - p.wait() - path_tmp_opf = os.path.join(tmp_dir, "metadata_" + str(current_milli_time()) + ".opf") - with open(path_tmp_opf, 'w') as fd: - copyfileobj(p.stdout, fd) + if config.config_embed_metadata: + quotes = [3, 5] + tmp_dir = get_temp_dir() + calibredb_binarypath = os.path.join(config.config_binariesdir, SUPPORTED_CALIBRE_BINARIES["calibredb"]) + opf_command = [calibredb_binarypath, 'show_metadata', '--as-opf', str(book_id), + '--with-library', config.config_calibre_dir] + p = process_open(opf_command, quotes) + p.wait() + path_tmp_opf = os.path.join(tmp_dir, "metadata_" + str(current_milli_time()) + ".opf") + with open(path_tmp_opf, 'w') as fd: + copyfileobj(p.stdout, fd) quotes = [1, 2, 4, 6] command = [config.config_converterpath, (file_path + format_old_ext), - (file_path + format_new_ext), '--from-opf', path_tmp_opf] + (file_path + format_new_ext)] + if config.config_embed_metadata: + command.extend('--from-opf', path_tmp_opf) if has_cover: command.extend(['--cover', os.path.join(os.path.dirname(file_path), 'cover.jpg')]) quotes_index = 3 diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 736062f4..8e37b2e5 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -103,6 +103,10 @@ +
+ + +