diff --git a/src/calibre/ebooks/metadata/sources/identify.py b/src/calibre/ebooks/metadata/sources/identify.py
index 4ff63df1d0..4ac5ff72e9 100644
--- a/src/calibre/ebooks/metadata/sources/identify.py
+++ b/src/calibre/ebooks/metadata/sources/identify.py
@@ -494,9 +494,14 @@ def identify(log, abort, # {{{
log('We have %d merged results, merging took: %.2f seconds' %
(len(results), time.time() - start_time))
+ tm_rules = msprefs['tag_map_rules']
+ if tm_rules:
+ from calibre.ebooks.metadata.tag_mapper import map_tags
max_tags = msprefs['max_tags']
for r in results:
+ if tm_rules:
+ r.tags = map_tags(r.tags, tm_rules)
r.tags = r.tags[:max_tags]
if getattr(r.pubdate, 'year', 2000) <= UNDEFINED_DATE.year:
r.pubdate = None
diff --git a/src/calibre/ebooks/metadata/sources/prefs.py b/src/calibre/ebooks/metadata/sources/prefs.py
index 543f42c2ab..b5496c1797 100644
--- a/src/calibre/ebooks/metadata/sources/prefs.py
+++ b/src/calibre/ebooks/metadata/sources/prefs.py
@@ -19,6 +19,7 @@ msprefs.defaults['swap_author_names'] = False
msprefs.defaults['fewer_tags'] = True
msprefs.defaults['find_first_edition_date'] = False
msprefs.defaults['append_comments'] = False
+msprefs.defaults['tag_map_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
diff --git a/src/calibre/gui2/preferences/metadata_sources.py b/src/calibre/gui2/preferences/metadata_sources.py
index 14b8cf62af..c0be5fe703 100644
--- a/src/calibre/gui2/preferences/metadata_sources.py
+++ b/src/calibre/gui2/preferences/metadata_sources.py
@@ -319,6 +319,8 @@ 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_button.clicked.connect(self.change_tag_map_rules)
def configure_plugin(self):
for index in self.sources_view.selectionModel().selectedRows():
@@ -343,11 +345,21 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.stack.removeWidget(self.pc)
self.pc = None
+ def change_tag_map_rules(self):
+ from calibre.gui2.tag_mapper import RulesDialog
+ d = RulesDialog(self)
+ if msprefs.get('tag_map_rules'):
+ d.rules = msprefs['tag_map_rules']
+ if d.exec_() == d.Accepted:
+ self.tag_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
def restore_defaults(self):
ConfigWidgetBase.restore_defaults(self)
@@ -358,6 +370,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
def commit(self):
self.sources_model.commit()
self.fields_model.commit()
+ if self.tag_map_rules is not None:
+ if self.tag_map_rules:
+ msprefs['tag_map_rules'] = self.tag_map_rules
+ else:
+ msprefs.pop('tag_map_rules', None)
return ConfigWidgetBase.commit(self)
if __name__ == '__main__':
diff --git a/src/calibre/gui2/preferences/metadata_sources.ui b/src/calibre/gui2/preferences/metadata_sources.ui
index ceda2a99ed..dae30de71e 100644
--- a/src/calibre/gui2/preferences/metadata_sources.ui
+++ b/src/calibre/gui2/preferences/metadata_sources.ui
@@ -14,7 +14,16 @@
Form
-
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
0
-
@@ -28,7 +37,7 @@
- -
+
-
Max. &time to wait after first match is found:
@@ -38,7 +47,7 @@
- -
+
-
Max. time to wait after first &cover is found:
@@ -48,14 +57,14 @@
- -
+
-
secs
- -
+
-
<p>Different metadata sources have different sets of tags for the same book. If this option is checked, then calibre will use the smaller tag sets. These tend to be more like genres, while the larger tag sets tend to describe the books content.
@@ -69,6 +78,13 @@
+ -
+
+
+ Swap author names from FN LN to LN, FN
+
+
+
-
@@ -129,34 +145,27 @@
- -
-
-
- Swap author names from FN LN to LN, FN
-
-
+
-
+
- -
+
-
- Max. number of &tags to download:
+ Max. &number of tags to download:
opt_max_tags
- -
-
-
- -
+
-
secs
- -
+
-
Metadata sources
@@ -207,7 +216,7 @@
- -
+
-
<p>When downloading comments, append the downloaded comments to any existing comment, instead of overwriting them.
@@ -220,6 +229,13 @@
+ -
+
+
+ Create &rules to filter/transform tags
+
+
+