diff --git a/src/calibre/ebooks/metadata/sources/identify.py b/src/calibre/ebooks/metadata/sources/identify.py
index d40002cc80..b2faf00cef 100644
--- a/src/calibre/ebooks/metadata/sources/identify.py
+++ b/src/calibre/ebooks/metadata/sources/identify.py
@@ -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
# }}}
diff --git a/src/calibre/ebooks/metadata/sources/prefs.py b/src/calibre/ebooks/metadata/sources/prefs.py
index 0abdb69f66..7a995f37dc 100644
--- a/src/calibre/ebooks/metadata/sources/prefs.py
+++ b/src/calibre/ebooks/metadata/sources/prefs.py
@@ -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}
-
-
-
diff --git a/src/calibre/gui2/preferences/metadata_sources.py b/src/calibre/gui2/preferences/metadata_sources.py
index d23b83021b..58ac3214a7 100644
--- a/src/calibre/gui2/preferences/metadata_sources.py
+++ b/src/calibre/gui2/preferences/metadata_sources.py
@@ -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')
-
diff --git a/src/calibre/gui2/preferences/metadata_sources.ui b/src/calibre/gui2/preferences/metadata_sources.ui
index c0ba958c6e..072371f233 100644
--- a/src/calibre/gui2/preferences/metadata_sources.ui
+++ b/src/calibre/gui2/preferences/metadata_sources.ui
@@ -7,7 +7,7 @@
0
0
781
- 439
+ 492
@@ -30,6 +30,16 @@
+ -
+
+
+ Max. &number of tags to download:
+
+
+ opt_max_tags
+
+
+
-
@@ -37,7 +47,7 @@
- -
+
-
Max. &time to wait after first match is found:
@@ -47,7 +57,7 @@
- -
+
-
Max. time to wait after first &cover is found:
@@ -57,7 +67,7 @@
- -
+
-
secs
@@ -145,27 +155,30 @@
- -
+
-
- -
-
-
- Max. &number of tags to download:
-
-
- opt_max_tags
-
-
-
- -
+
-
secs
- -
+
-
+
+
+ <p>When downloading comments, append the downloaded comments to any existing comment, instead of overwriting them.
+
+
+ When downloading comments, append the downloaded comments to any existing comment, instead of overwriting them.
+
+
+ Append comments to &existing
+
+
+
+ -
Metadata sources
@@ -216,19 +229,6 @@
- -
-
-
- <p>When downloading comments, append the downloaded comments to any existing comment, instead of overwriting them.
-
-
- When downloading comments, append the downloaded comments to any existing comment, instead of overwriting them.
-
-
- Append comments to &existing
-
-
-
-
@@ -236,6 +236,13 @@
+ -
+
+
+ Create rules to &transform author names
+
+
+