mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add author mapper to metadata download prefs as well
This commit is contained in:
parent
d1395dba2b
commit
889f07dcdc
@ -17,7 +17,7 @@ from urlparse import urlparse
|
||||
from urllib import quote
|
||||
|
||||
from calibre.customize.ui import metadata_plugins, all_metadata_plugins
|
||||
from calibre.ebooks.metadata import check_issn
|
||||
from calibre.ebooks.metadata import check_issn, authors_to_sort_string
|
||||
from calibre.ebooks.metadata.sources.base import create_log
|
||||
from calibre.ebooks.metadata.sources.prefs import msprefs
|
||||
from calibre.ebooks.metadata.xisbn import xisbn
|
||||
@ -503,6 +503,10 @@ def identify(log, abort, # {{{
|
||||
tm_rules = msprefs['tag_map_rules']
|
||||
if tm_rules:
|
||||
from calibre.ebooks.metadata.tag_mapper import map_tags
|
||||
am_rules = msprefs['author_map_rules']
|
||||
if am_rules:
|
||||
from calibre.ebooks.metadata.author_mapper import map_authors, compile_rules
|
||||
am_rules = compile_rules(am_rules)
|
||||
|
||||
max_tags = msprefs['max_tags']
|
||||
for r in results:
|
||||
@ -524,6 +528,13 @@ def identify(log, abort, # {{{
|
||||
return '%s, %s' % (surname, ' '.join(parts[:-1]))
|
||||
r.authors = [swap_to_ln_fn(a) for a in r.authors]
|
||||
|
||||
if am_rules:
|
||||
for r in results:
|
||||
new_authors = map_authors(r.authors, am_rules)
|
||||
if new_authors != r.authors:
|
||||
r.authors = new_authors
|
||||
r.author_sort = authors_to_sort_string(r.authors)
|
||||
|
||||
return results
|
||||
# }}}
|
||||
|
||||
|
@ -20,12 +20,10 @@ msprefs.defaults['fewer_tags'] = True
|
||||
msprefs.defaults['find_first_edition_date'] = False
|
||||
msprefs.defaults['append_comments'] = False
|
||||
msprefs.defaults['tag_map_rules'] = []
|
||||
msprefs.defaults['author_map_rules'] = []
|
||||
msprefs.defaults['id_link_rules'] = {}
|
||||
|
||||
# Google covers are often poor quality (scans/errors) but they have high
|
||||
# resolution, so they trump covers from better sources. So make sure they
|
||||
# are only used if no other covers are found.
|
||||
msprefs.defaults['cover_priorities'] = {'Google':2, 'Google Images':2, 'Big Book Search':2}
|
||||
|
||||
|
||||
|
||||
|
@ -323,8 +323,9 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.select_default_button.clicked.connect(self.fields_model.select_user_defaults)
|
||||
self.select_default_button.clicked.connect(self.changed_signal)
|
||||
self.set_as_default_button.clicked.connect(self.fields_model.commit_user_defaults)
|
||||
self.tag_map_rules = None
|
||||
self.tag_map_rules = self.author_map_rules = None
|
||||
self.tag_map_rules_button.clicked.connect(self.change_tag_map_rules)
|
||||
self.author_map_rules_button.clicked.connect(self.change_author_map_rules)
|
||||
|
||||
def configure_plugin(self):
|
||||
for index in self.sources_view.selectionModel().selectedRows():
|
||||
@ -358,12 +359,21 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.tag_map_rules = d.rules
|
||||
self.changed_signal.emit()
|
||||
|
||||
def change_author_map_rules(self):
|
||||
from calibre.gui2.author_mapper import RulesDialog
|
||||
d = RulesDialog(self)
|
||||
if msprefs.get('author_map_rules'):
|
||||
d.rules = msprefs['author_map_rules']
|
||||
if d.exec_() == d.Accepted:
|
||||
self.author_map_rules = d.rules
|
||||
self.changed_signal.emit()
|
||||
|
||||
def initialize(self):
|
||||
ConfigWidgetBase.initialize(self)
|
||||
self.sources_model.initialize()
|
||||
self.sources_view.resizeColumnsToContents()
|
||||
self.fields_model.initialize()
|
||||
self.tag_map_rules = None
|
||||
self.tag_map_rules = self.author_map_rules = None
|
||||
|
||||
def restore_defaults(self):
|
||||
ConfigWidgetBase.restore_defaults(self)
|
||||
@ -379,10 +389,15 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
msprefs['tag_map_rules'] = self.tag_map_rules
|
||||
else:
|
||||
msprefs.pop('tag_map_rules', None)
|
||||
if self.author_map_rules is not None:
|
||||
if self.author_map_rules:
|
||||
msprefs['author_map_rules'] = self.author_map_rules
|
||||
else:
|
||||
msprefs.pop('author_map_rules', None)
|
||||
return ConfigWidgetBase.commit(self)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from PyQt5.Qt import QApplication
|
||||
app = QApplication([])
|
||||
test_widget('Sharing', 'Metadata download')
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>781</width>
|
||||
<height>439</height>
|
||||
<height>492</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -30,6 +30,16 @@
|
||||
<widget class="QStackedWidget" name="stack">
|
||||
<widget class="QWidget" name="page">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="8" column="1">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Max. &number of tags to download:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_max_tags</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QCheckBox" name="opt_find_first_edition_date">
|
||||
<property name="text">
|
||||
@ -37,7 +47,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<item row="9" column="1">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Max. &time to wait after first match is found:</string>
|
||||
@ -47,7 +57,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<item row="10" column="1">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Max. time to wait after first &cover is found:</string>
|
||||
@ -57,7 +67,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="2">
|
||||
<item row="10" column="2">
|
||||
<widget class="QSpinBox" name="opt_wait_after_first_cover_result">
|
||||
<property name="suffix">
|
||||
<string> secs</string>
|
||||
@ -145,27 +155,30 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="2">
|
||||
<item row="8" column="2">
|
||||
<widget class="QSpinBox" name="opt_max_tags"/>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Max. &number of tags to download:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_max_tags</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="2">
|
||||
<item row="9" column="2">
|
||||
<widget class="QSpinBox" name="opt_wait_after_first_identify_result">
|
||||
<property name="suffix">
|
||||
<string> secs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="10">
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="opt_append_comments">
|
||||
<property name="toolTip">
|
||||
<string><p>When downloading comments, append the downloaded comments to any existing comment, instead of overwriting them.</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>When downloading comments, append the downloaded comments to any existing comment, instead of overwriting them.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Append comments to &existing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="11">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Metadata sources</string>
|
||||
@ -216,19 +229,6 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="opt_append_comments">
|
||||
<property name="toolTip">
|
||||
<string><p>When downloading comments, append the downloaded comments to any existing comment, instead of overwriting them.</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>When downloading comments, append the downloaded comments to any existing comment, instead of overwriting them.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Append comments to &existing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1" colspan="2">
|
||||
<widget class="QPushButton" name="tag_map_rules_button">
|
||||
<property name="text">
|
||||
@ -236,6 +236,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1" colspan="2">
|
||||
<widget class="QPushButton" name="author_map_rules_button">
|
||||
<property name="text">
|
||||
<string>Create rules to &transform author names</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_2"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user