diff --git a/cps/helper.py b/cps/helper.py index 975a2523..4f2470f1 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -1007,10 +1007,17 @@ def do_calibre_export(book_id, book_format, ): tmp_dir = get_temp_dir() calibredb_binarypath = get_calibre_binarypath("calibredb") temp_file_name = str(uuid4()) - opf_command = [calibredb_binarypath, 'export', '--dont-write-opf', '--with-library', config.config_calibre_dir, + my_env = os.environ.copy() + if config.config_calibre_split: + my_env['CALIBRE_OVERRIDE_DATABASE_PATH'] = os.path.join(config.config_calibre_dir, "metadata.db") + library_path = config.config_calibre_split_dir + else: + library_path = config.config_calibre_dir + opf_command = [calibredb_binarypath, 'export', '--dont-write-opf', '--with-library', library_path, '--to-dir', tmp_dir, '--formats', book_format, "--template", "{}".format(temp_file_name), str(book_id)] - p = process_open(opf_command, quotes) + # CALIBRE_OVERRIDE_DATABASE_PATH + p = process_open(opf_command, quotes, my_env) _, err = p.communicate() if err: log.error('Metadata embedder encountered an error: %s', err) diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 8cb29197..21f99668 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -251,9 +251,16 @@ class TaskConvert(CalibreTask): quotes = [3, 5] tmp_dir = get_temp_dir() calibredb_binarypath = os.path.join(config.config_binariesdir, SUPPORTED_CALIBRE_BINARIES["calibredb"]) + my_env = os.environ.copy() + if config.config_calibre_split: + my_env['CALIBRE_OVERRIDE_DATABASE_PATH'] = os.path.join(config.config_calibre_dir, "metadata.db") + library_path = config.config_calibre_split_dir + else: + library_path = config.config_calibre_dir + opf_command = [calibredb_binarypath, 'show_metadata', '--as-opf', str(self.book_id), - '--with-library', config.config_calibre_dir] - p = process_open(opf_command, quotes) + '--with-library', library_path] + p = process_open(opf_command, quotes, my_env) p.wait() path_tmp_opf = os.path.join(tmp_dir, "metadata_" + str(uuid4()) + ".opf") with open(path_tmp_opf, 'w') as fd: diff --git a/cps/templates/config_db.html b/cps/templates/config_db.html index e79bb630..5b6ac7ff 100644 --- a/cps/templates/config_db.html +++ b/cps/templates/config_db.html @@ -18,7 +18,7 @@
- +