mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When converting books in the calibre GUI, override metadata from the input document. So if you have removed all the tags and comments in the calibre GUI for the book in the calibre GUI, but the actual file that is being converted still has tags and comments, they are ignored. This affects only conversions in the calibre GUI, not from the command line via ebook-convert. Fixes #8390 ("comments" still showing up on inserted metadata page, despite deleting the "comments")
This commit is contained in:
parent
f227086913
commit
682bf119d0
@ -72,7 +72,8 @@ class Plumber(object):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, input, output, log, report_progress=DummyReporter(),
|
def __init__(self, input, output, log, report_progress=DummyReporter(),
|
||||||
dummy=False, merge_plugin_recs=True, abort_after_input_dump=False):
|
dummy=False, merge_plugin_recs=True, abort_after_input_dump=False,
|
||||||
|
override_input_metadata=False):
|
||||||
'''
|
'''
|
||||||
:param input: Path to input file.
|
:param input: Path to input file.
|
||||||
:param output: Path to output file/directory
|
:param output: Path to output file/directory
|
||||||
@ -87,6 +88,7 @@ class Plumber(object):
|
|||||||
self.log = log
|
self.log = log
|
||||||
self.ui_reporter = report_progress
|
self.ui_reporter = report_progress
|
||||||
self.abort_after_input_dump = abort_after_input_dump
|
self.abort_after_input_dump = abort_after_input_dump
|
||||||
|
self.override_input_metadata = override_input_metadata
|
||||||
|
|
||||||
# Pipeline options {{{
|
# Pipeline options {{{
|
||||||
# Initialize the conversion options that are independent of input and
|
# Initialize the conversion options that are independent of input and
|
||||||
@ -924,7 +926,8 @@ OptionRecommendation(name='sr3_replace',
|
|||||||
self.opts.dest = self.opts.output_profile
|
self.opts.dest = self.opts.output_profile
|
||||||
|
|
||||||
from calibre.ebooks.oeb.transforms.metadata import MergeMetadata
|
from calibre.ebooks.oeb.transforms.metadata import MergeMetadata
|
||||||
MergeMetadata()(self.oeb, self.user_metadata, self.opts)
|
MergeMetadata()(self.oeb, self.user_metadata, self.opts,
|
||||||
|
override_input_metadata=self.override_input_metadata)
|
||||||
pr(0.2)
|
pr(0.2)
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import os
|
|||||||
from calibre.utils.date import isoformat, now
|
from calibre.utils.date import isoformat, now
|
||||||
from calibre import guess_type
|
from calibre import guess_type
|
||||||
|
|
||||||
def meta_info_to_oeb_metadata(mi, m, log):
|
def meta_info_to_oeb_metadata(mi, m, log, override_input_metadata=False):
|
||||||
from calibre.ebooks.oeb.base import OPF
|
from calibre.ebooks.oeb.base import OPF
|
||||||
if not mi.is_null('title'):
|
if not mi.is_null('title'):
|
||||||
m.clear('title')
|
m.clear('title')
|
||||||
@ -29,15 +29,23 @@ def meta_info_to_oeb_metadata(mi, m, log):
|
|||||||
if not mi.is_null('book_producer'):
|
if not mi.is_null('book_producer'):
|
||||||
m.filter('contributor', lambda x : x.role.lower() == 'bkp')
|
m.filter('contributor', lambda x : x.role.lower() == 'bkp')
|
||||||
m.add('contributor', mi.book_producer, role='bkp')
|
m.add('contributor', mi.book_producer, role='bkp')
|
||||||
|
elif override_input_metadata:
|
||||||
|
m.filter('contributor', lambda x : x.role.lower() == 'bkp')
|
||||||
if not mi.is_null('comments'):
|
if not mi.is_null('comments'):
|
||||||
m.clear('description')
|
m.clear('description')
|
||||||
m.add('description', mi.comments)
|
m.add('description', mi.comments)
|
||||||
|
elif override_input_metadata:
|
||||||
|
m.clear('description')
|
||||||
if not mi.is_null('publisher'):
|
if not mi.is_null('publisher'):
|
||||||
m.clear('publisher')
|
m.clear('publisher')
|
||||||
m.add('publisher', mi.publisher)
|
m.add('publisher', mi.publisher)
|
||||||
|
elif override_input_metadata:
|
||||||
|
m.clear('publisher')
|
||||||
if not mi.is_null('series'):
|
if not mi.is_null('series'):
|
||||||
m.clear('series')
|
m.clear('series')
|
||||||
m.add('series', mi.series)
|
m.add('series', mi.series)
|
||||||
|
elif override_input_metadata:
|
||||||
|
m.clear('series')
|
||||||
if not mi.is_null('isbn'):
|
if not mi.is_null('isbn'):
|
||||||
has = False
|
has = False
|
||||||
for x in m.identifier:
|
for x in m.identifier:
|
||||||
@ -46,19 +54,27 @@ def meta_info_to_oeb_metadata(mi, m, log):
|
|||||||
has = True
|
has = True
|
||||||
if not has:
|
if not has:
|
||||||
m.add('identifier', mi.isbn, scheme='ISBN')
|
m.add('identifier', mi.isbn, scheme='ISBN')
|
||||||
|
elif override_input_metadata:
|
||||||
|
m.filter('identifier', lambda x: x.scheme.lower() == 'isbn')
|
||||||
if not mi.is_null('language'):
|
if not mi.is_null('language'):
|
||||||
m.clear('language')
|
m.clear('language')
|
||||||
m.add('language', mi.language)
|
m.add('language', mi.language)
|
||||||
if not mi.is_null('series_index'):
|
if not mi.is_null('series_index'):
|
||||||
m.clear('series_index')
|
m.clear('series_index')
|
||||||
m.add('series_index', mi.format_series_index())
|
m.add('series_index', mi.format_series_index())
|
||||||
|
elif override_input_metadata:
|
||||||
|
m.clear('series_index')
|
||||||
if not mi.is_null('rating'):
|
if not mi.is_null('rating'):
|
||||||
m.clear('rating')
|
m.clear('rating')
|
||||||
m.add('rating', '%.2f'%mi.rating)
|
m.add('rating', '%.2f'%mi.rating)
|
||||||
|
elif override_input_metadata:
|
||||||
|
m.clear('rating')
|
||||||
if not mi.is_null('tags'):
|
if not mi.is_null('tags'):
|
||||||
m.clear('subject')
|
m.clear('subject')
|
||||||
for t in mi.tags:
|
for t in mi.tags:
|
||||||
m.add('subject', t)
|
m.add('subject', t)
|
||||||
|
elif override_input_metadata:
|
||||||
|
m.clear('subject')
|
||||||
if not mi.is_null('pubdate'):
|
if not mi.is_null('pubdate'):
|
||||||
m.clear('date')
|
m.clear('date')
|
||||||
m.add('date', isoformat(mi.pubdate))
|
m.add('date', isoformat(mi.pubdate))
|
||||||
@ -68,9 +84,14 @@ def meta_info_to_oeb_metadata(mi, m, log):
|
|||||||
if not mi.is_null('rights'):
|
if not mi.is_null('rights'):
|
||||||
m.clear('rights')
|
m.clear('rights')
|
||||||
m.add('rights', mi.rights)
|
m.add('rights', mi.rights)
|
||||||
|
elif override_input_metadata:
|
||||||
|
m.clear('rights')
|
||||||
if not mi.is_null('publication_type'):
|
if not mi.is_null('publication_type'):
|
||||||
m.clear('publication_type')
|
m.clear('publication_type')
|
||||||
m.add('publication_type', mi.publication_type)
|
m.add('publication_type', mi.publication_type)
|
||||||
|
elif override_input_metadata:
|
||||||
|
m.clear('publication_type')
|
||||||
|
|
||||||
if not m.timestamp:
|
if not m.timestamp:
|
||||||
m.add('timestamp', isoformat(now()))
|
m.add('timestamp', isoformat(now()))
|
||||||
|
|
||||||
@ -78,11 +99,12 @@ def meta_info_to_oeb_metadata(mi, m, log):
|
|||||||
class MergeMetadata(object):
|
class MergeMetadata(object):
|
||||||
'Merge in user metadata, including cover'
|
'Merge in user metadata, including cover'
|
||||||
|
|
||||||
def __call__(self, oeb, mi, opts):
|
def __call__(self, oeb, mi, opts, override_input_metadata=False):
|
||||||
self.oeb, self.log = oeb, oeb.log
|
self.oeb, self.log = oeb, oeb.log
|
||||||
m = self.oeb.metadata
|
m = self.oeb.metadata
|
||||||
self.log('Merging user specified metadata...')
|
self.log('Merging user specified metadata...')
|
||||||
meta_info_to_oeb_metadata(mi, m, oeb.log)
|
meta_info_to_oeb_metadata(mi, m, oeb.log,
|
||||||
|
override_input_metadata=override_input_metadata)
|
||||||
cover_id = self.set_cover(mi, opts.prefer_metadata_cover)
|
cover_id = self.set_cover(mi, opts.prefer_metadata_cover)
|
||||||
m.clear('cover')
|
m.clear('cover')
|
||||||
if cover_id is not None:
|
if cover_id is not None:
|
||||||
|
@ -12,17 +12,24 @@ from calibre.customize.ui import plugin_for_catalog_format
|
|||||||
from calibre.utils.logging import Log
|
from calibre.utils.logging import Log
|
||||||
|
|
||||||
def gui_convert(input, output, recommendations, notification=DummyReporter(),
|
def gui_convert(input, output, recommendations, notification=DummyReporter(),
|
||||||
abort_after_input_dump=False, log=None):
|
abort_after_input_dump=False, log=None, override_input_metadata=False):
|
||||||
recommendations = list(recommendations)
|
recommendations = list(recommendations)
|
||||||
recommendations.append(('verbose', 2, OptionRecommendation.HIGH))
|
recommendations.append(('verbose', 2, OptionRecommendation.HIGH))
|
||||||
if log is None:
|
if log is None:
|
||||||
log = Log()
|
log = Log()
|
||||||
plumber = Plumber(input, output, log, report_progress=notification,
|
plumber = Plumber(input, output, log, report_progress=notification,
|
||||||
abort_after_input_dump=abort_after_input_dump)
|
abort_after_input_dump=abort_after_input_dump,
|
||||||
|
override_input_metadata=override_input_metadata)
|
||||||
plumber.merge_ui_recommendations(recommendations)
|
plumber.merge_ui_recommendations(recommendations)
|
||||||
|
|
||||||
plumber.run()
|
plumber.run()
|
||||||
|
|
||||||
|
def gui_convert_override(input, output, recommendations, notification=DummyReporter(),
|
||||||
|
abort_after_input_dump=False, log=None):
|
||||||
|
gui_convert(input, output, recommendations, notification=notification,
|
||||||
|
abort_after_input_dump=abort_after_input_dump, log=log,
|
||||||
|
override_input_metadata=True)
|
||||||
|
|
||||||
def gui_catalog(fmt, title, dbspec, ids, out_file_name, sync, fmt_options, connected_device,
|
def gui_catalog(fmt, title, dbspec, ids, out_file_name, sync, fmt_options, connected_device,
|
||||||
notification=DummyReporter(), log=None):
|
notification=DummyReporter(), log=None):
|
||||||
if log is None:
|
if log is None:
|
||||||
|
@ -75,7 +75,7 @@ def convert_single_ebook(parent, db, book_ids, auto_conversion=False, out_format
|
|||||||
temp_files.append(d.cover_file)
|
temp_files.append(d.cover_file)
|
||||||
args = [in_file, out_file.name, recs]
|
args = [in_file, out_file.name, recs]
|
||||||
temp_files.append(out_file)
|
temp_files.append(out_file)
|
||||||
jobs.append(('gui_convert', args, desc, d.output_format.upper(), book_id, temp_files))
|
jobs.append(('gui_convert_override', args, desc, d.output_format.upper(), book_id, temp_files))
|
||||||
|
|
||||||
changed = True
|
changed = True
|
||||||
d.break_cycles()
|
d.break_cycles()
|
||||||
@ -185,7 +185,7 @@ class QueueBulk(QProgressDialog):
|
|||||||
|
|
||||||
args = [in_file, out_file.name, lrecs]
|
args = [in_file, out_file.name, lrecs]
|
||||||
temp_files.append(out_file)
|
temp_files.append(out_file)
|
||||||
self.jobs.append(('gui_convert', args, desc, self.output_format.upper(), book_id, temp_files))
|
self.jobs.append(('gui_convert_override', args, desc, self.output_format.upper(), book_id, temp_files))
|
||||||
|
|
||||||
self.changed = True
|
self.changed = True
|
||||||
self.setValue(self.i)
|
self.setValue(self.i)
|
||||||
|
@ -28,6 +28,9 @@ PARALLEL_FUNCS = {
|
|||||||
'gui_convert' :
|
'gui_convert' :
|
||||||
('calibre.gui2.convert.gui_conversion', 'gui_convert', 'notification'),
|
('calibre.gui2.convert.gui_conversion', 'gui_convert', 'notification'),
|
||||||
|
|
||||||
|
'gui_convert_override' :
|
||||||
|
('calibre.gui2.convert.gui_conversion', 'gui_convert_override', 'notification'),
|
||||||
|
|
||||||
'gui_catalog' :
|
'gui_catalog' :
|
||||||
('calibre.gui2.convert.gui_conversion', 'gui_catalog', 'notification'),
|
('calibre.gui2.convert.gui_conversion', 'gui_catalog', 'notification'),
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user