mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Option for sonys to use author_sort instead of author in the sony metadata
This commit is contained in:
parent
5e71cbddf3
commit
2f68116f78
@ -55,6 +55,7 @@ class PRS505(USBMS):
|
||||
|
||||
SUPPORTS_SUB_DIRS = True
|
||||
MUST_READ_METADATA = True
|
||||
SUPPORTS_USE_AUTHOR_SORT = True
|
||||
EBOOK_DIR_MAIN = 'database/media/books'
|
||||
|
||||
EXTRA_CUSTOMIZATION_MESSAGE = _('Comma separated list of metadata fields '
|
||||
@ -125,7 +126,7 @@ class PRS505(USBMS):
|
||||
d = os.path.dirname(paths[source_id])
|
||||
if not os.path.exists(d):
|
||||
os.makedirs(d)
|
||||
return XMLCache(paths, prefixes)
|
||||
return XMLCache(paths, prefixes, self.settings().use_author_sort)
|
||||
|
||||
def books(self, oncard=None, end_session=True):
|
||||
debug_print('PRS505: starting fetching books for card', oncard)
|
||||
|
@ -60,12 +60,13 @@ def uuid():
|
||||
|
||||
class XMLCache(object):
|
||||
|
||||
def __init__(self, paths, prefixes):
|
||||
def __init__(self, paths, prefixes, use_author_sort):
|
||||
if DEBUG:
|
||||
debug_print('Building XMLCache...')
|
||||
pprint(paths)
|
||||
self.paths = paths
|
||||
self.prefixes = prefixes
|
||||
self.use_author_sort = use_author_sort
|
||||
|
||||
# Parse XML files {{{
|
||||
parser = etree.XMLParser(recover=True)
|
||||
@ -434,6 +435,9 @@ class XMLCache(object):
|
||||
if not ts:
|
||||
ts = title_sort(title)
|
||||
record.set('titleSorter', ts)
|
||||
if self.use_author_sort and book.author_sort is not None:
|
||||
record.set('author', book.author_sort)
|
||||
else:
|
||||
record.set('author', authors_to_string(book.authors))
|
||||
ext = os.path.splitext(path)[1]
|
||||
if ext:
|
||||
|
@ -80,6 +80,7 @@ class Device(DeviceConfig, DevicePlugin):
|
||||
|
||||
SUPPORTS_SUB_DIRS = False
|
||||
MUST_READ_METADATA = False
|
||||
SUPPORTS_USE_AUTHOR_SORT = False
|
||||
|
||||
EBOOK_DIR_MAIN = ''
|
||||
EBOOK_DIR_CARD_A = ''
|
||||
|
@ -32,6 +32,8 @@ class DeviceConfig(object):
|
||||
help=_('Place files in sub directories if the device supports them'))
|
||||
c.add_opt('read_metadata', default=True,
|
||||
help=_('Read metadata from files on device'))
|
||||
c.add_opt('use_author_sort', default=False,
|
||||
help=_('Use author sort instead of author'))
|
||||
c.add_opt('save_template', default=cls._default_save_template(),
|
||||
help=_('Template to control how books are saved'))
|
||||
c.add_opt('extra_customization',
|
||||
@ -47,7 +49,8 @@ class DeviceConfig(object):
|
||||
def config_widget(cls):
|
||||
from calibre.gui2.device_drivers.configwidget import ConfigWidget
|
||||
cw = ConfigWidget(cls.settings(), cls.FORMATS, cls.SUPPORTS_SUB_DIRS,
|
||||
cls.MUST_READ_METADATA, cls.EXTRA_CUSTOMIZATION_MESSAGE)
|
||||
cls.MUST_READ_METADATA, cls.SUPPORTS_USE_AUTHOR_SORT,
|
||||
cls.EXTRA_CUSTOMIZATION_MESSAGE)
|
||||
return cw
|
||||
|
||||
@classmethod
|
||||
@ -58,6 +61,8 @@ class DeviceConfig(object):
|
||||
proxy['use_subdirs'] = config_widget.use_subdirs()
|
||||
if not cls.MUST_READ_METADATA:
|
||||
proxy['read_metadata'] = config_widget.read_metadata()
|
||||
if not cls.SUPPORTS_USE_AUTHOR_SORT:
|
||||
proxy['use_author_sort'] = config_widget.use_author_sort()
|
||||
if cls.EXTRA_CUSTOMIZATION_MESSAGE:
|
||||
ec = unicode(config_widget.opt_extra_customization.text()).strip()
|
||||
if not ec:
|
||||
|
@ -299,7 +299,7 @@ class USBMS(CLI, Device):
|
||||
def replfunc(match):
|
||||
if match.group(1) in ['title', 'series', 'series_index', 'isbn']:
|
||||
return '(?P<' + match.group(1) + '>.+?)'
|
||||
elif match.group(1) == 'authors':
|
||||
elif match.group(1) in ['authors', 'author_sort']:
|
||||
return '(?P<author>.+?)'
|
||||
else:
|
||||
return '(.+?)'
|
||||
|
@ -11,7 +11,8 @@ from calibre.gui2.device_drivers.configwidget_ui import Ui_ConfigWidget
|
||||
class ConfigWidget(QWidget, Ui_ConfigWidget):
|
||||
|
||||
def __init__(self, settings, all_formats, supports_subdirs,
|
||||
must_read_metadata, extra_customization_message):
|
||||
must_read_metadata, supports_use_author_sort,
|
||||
extra_customization_message):
|
||||
|
||||
QWidget.__init__(self)
|
||||
Ui_ConfigWidget.__init__(self)
|
||||
@ -38,6 +39,10 @@ class ConfigWidget(QWidget, Ui_ConfigWidget):
|
||||
self.opt_read_metadata.setChecked(self.settings.read_metadata)
|
||||
else:
|
||||
self.opt_read_metadata.hide()
|
||||
if supports_use_author_sort:
|
||||
self.opt_use_author_sort.setChecked(self.settings.use_author_sort)
|
||||
else:
|
||||
self.opt_use_author_sort.hide()
|
||||
if extra_customization_message:
|
||||
self.extra_customization_label.setText(extra_customization_message)
|
||||
if settings.extra_customization:
|
||||
@ -69,3 +74,6 @@ class ConfigWidget(QWidget, Ui_ConfigWidget):
|
||||
|
||||
def read_metadata(self):
|
||||
return self.opt_read_metadata.isChecked()
|
||||
|
||||
def use_author_sort(self):
|
||||
return self.opt_use_author_sort.isChecked()
|
||||
|
@ -90,7 +90,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="opt_use_author_sort">
|
||||
<property name="text">
|
||||
<string>Use author sort for author</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="extra_customization_label">
|
||||
<property name="text">
|
||||
<string>Extra customization</string>
|
||||
@ -103,10 +110,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<item row="7" column="0">
|
||||
<widget class="QLineEdit" name="opt_extra_customization"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Save &template:</string>
|
||||
@ -116,7 +123,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="5" column="0">
|
||||
<widget class="QLineEdit" name="opt_save_template"/>
|
||||
</item>
|
||||
</layout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user