mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add option to swap author first name and last name when reading metadata from a file name
This commit is contained in:
parent
17dff5c9bd
commit
e4164d71d2
@ -132,6 +132,15 @@ def metadata_from_filename(name, pat=None):
|
|||||||
au = match.group('author')
|
au = match.group('author')
|
||||||
aus = string_to_authors(au)
|
aus = string_to_authors(au)
|
||||||
mi.authors = aus
|
mi.authors = aus
|
||||||
|
if prefs['swap_author_names'] and mi.authors:
|
||||||
|
def swap(a):
|
||||||
|
parts = a.split()
|
||||||
|
if len(parts) > 1:
|
||||||
|
t = parts[-1]
|
||||||
|
parts = parts[:-1]
|
||||||
|
parts.insert(0, t)
|
||||||
|
return ' '.join(parts)
|
||||||
|
mi.authors = [swap(x) for x in mi.authors]
|
||||||
except (IndexError, ValueError):
|
except (IndexError, ValueError):
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
|
@ -56,6 +56,7 @@ class AddSave(QTabWidget, Ui_TabWidget):
|
|||||||
self.opt_read_metadata_from_filename.setChecked(not prefs['read_file_metadata'])
|
self.opt_read_metadata_from_filename.setChecked(not prefs['read_file_metadata'])
|
||||||
self.filename_pattern = FilenamePattern(self)
|
self.filename_pattern = FilenamePattern(self)
|
||||||
self.metadata_box.layout().insertWidget(0, self.filename_pattern)
|
self.metadata_box.layout().insertWidget(0, self.filename_pattern)
|
||||||
|
self.opt_swap_author_names.setChecked(prefs['swap_author_names'])
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
tmpl = preprocess_template(self.opt_template.text())
|
tmpl = preprocess_template(self.opt_template.text())
|
||||||
@ -87,6 +88,7 @@ class AddSave(QTabWidget, Ui_TabWidget):
|
|||||||
prefs['read_file_metadata'] = not bool(self.opt_read_metadata_from_filename.isChecked())
|
prefs['read_file_metadata'] = not bool(self.opt_read_metadata_from_filename.isChecked())
|
||||||
pattern = self.filename_pattern.commit()
|
pattern = self.filename_pattern.commit()
|
||||||
prefs['filename_pattern'] = pattern
|
prefs['filename_pattern'] = pattern
|
||||||
|
prefs['swap_author_names'] = bool(self.opt_swap_author_names.isChecked())
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>&Adding books</string>
|
<string>&Adding books</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
<item>
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="label_6">
|
<widget class="QLabel" name="label_6">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Here you can control how calibre will read metadata from the files you add to it. calibre can either read metadata from the contents of the file, or from the filename.</string>
|
<string>Here you can control how calibre will read metadata from the files you add to it. calibre can either read metadata from the contents of the file, or from the filename.</string>
|
||||||
@ -31,14 +31,24 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="1" column="0">
|
||||||
<widget class="QCheckBox" name="opt_read_metadata_from_filename">
|
<widget class="QCheckBox" name="opt_read_metadata_from_filename">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Read metadata only from &file name</string>
|
<string>Read metadata only from &file name</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="1" column="1">
|
||||||
|
<widget class="QCheckBox" name="opt_swap_author_names">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Swap the firstname and lastname of the author. This affects only metadata read from file names.</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>&Swap author firstname and lastname</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="2">
|
||||||
<widget class="QGroupBox" name="metadata_box">
|
<widget class="QGroupBox" name="metadata_box">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>&Configure metadata from file name</string>
|
<string>&Configure metadata from file name</string>
|
||||||
|
@ -649,6 +649,8 @@ def _prefs():
|
|||||||
help=_('Read metadata from files'))
|
help=_('Read metadata from files'))
|
||||||
c.add_opt('worker_process_priority', default='normal',
|
c.add_opt('worker_process_priority', default='normal',
|
||||||
help=_('The priority of worker processes'))
|
help=_('The priority of worker processes'))
|
||||||
|
c.add_opt('swap_author_names', default=False,
|
||||||
|
help=_('Swap author first and last names when reading metadata'))
|
||||||
|
|
||||||
c.add_opt('migrated', default=False, help='For Internal use. Don\'t modify.')
|
c.add_opt('migrated', default=False, help='For Internal use. Don\'t modify.')
|
||||||
return c
|
return c
|
||||||
|
Loading…
x
Reference in New Issue
Block a user