Make embed metadata configurable

This commit is contained in:
Ozzie Isaacs 2023-12-09 11:23:26 +01:00
parent d341faf204
commit 1086296d1d
5 changed files with 22 additions and 22 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -238,19 +238,12 @@ 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
if config.config_embed_metadata:
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]
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")
@ -259,7 +252,9 @@ class TaskConvert(CalibreTask):
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

View File

@ -103,6 +103,10 @@
<input type="checkbox" id="config_unicode_filename" name="config_unicode_filename" {% if config.config_unicode_filename %}checked{% endif %}>
<label for="config_unicode_filename">{{_('Convert non-English characters in title and author while saving to disk')}}</label>
</div>
<div class="form-group">
<input type="checkbox" id="config_embed_metadata" name="config_embed_metadata" {% if config.config_embed_metadata %}checked{% endif %}>
<label for="config_embed_metadata">{{_('Embed Metadata to Ebook File on Download and Conversion')}}</label>
</div>
<div class="form-group">
<input type="checkbox" id="config_uploading" data-control="upload_settings" name="config_uploading" {% if config.config_uploading %}checked{% endif %}>
<label for="config_uploading">{{_('Enable Uploads')}} {{_('(Please ensure that users also have upload permissions)')}}</label>