From 2f68116f789303437a6602dfb7762e7a48ce0063 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 17 Jun 2010 18:01:43 +0100 Subject: [PATCH] Option for sonys to use author_sort instead of author in the sony metadata --- src/calibre/devices/prs505/driver.py | 3 ++- src/calibre/devices/prs505/sony_cache.py | 8 ++++++-- src/calibre/devices/usbms/device.py | 1 + src/calibre/devices/usbms/deviceconfig.py | 7 ++++++- src/calibre/devices/usbms/driver.py | 2 +- src/calibre/gui2/device_drivers/configwidget.py | 10 +++++++++- src/calibre/gui2/device_drivers/configwidget.ui | 15 +++++++++++---- 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/calibre/devices/prs505/driver.py b/src/calibre/devices/prs505/driver.py index 38fac8b266..5860826778 100644 --- a/src/calibre/devices/prs505/driver.py +++ b/src/calibre/devices/prs505/driver.py @@ -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) diff --git a/src/calibre/devices/prs505/sony_cache.py b/src/calibre/devices/prs505/sony_cache.py index 727bdf68b2..e7d0e4686c 100644 --- a/src/calibre/devices/prs505/sony_cache.py +++ b/src/calibre/devices/prs505/sony_cache.py @@ -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,7 +435,10 @@ class XMLCache(object): if not ts: ts = title_sort(title) record.set('titleSorter', ts) - record.set('author', authors_to_string(book.authors)) + 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: ext = ext[1:].lower() diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 2f01b8dd41..d899c8e995 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -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 = '' diff --git a/src/calibre/devices/usbms/deviceconfig.py b/src/calibre/devices/usbms/deviceconfig.py index a8220261f3..9f40a07dd3 100644 --- a/src/calibre/devices/usbms/deviceconfig.py +++ b/src/calibre/devices/usbms/deviceconfig.py @@ -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: diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index 6f558b9b34..2fc8b0d814 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -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.+?)' else: return '(.+?)' diff --git a/src/calibre/gui2/device_drivers/configwidget.py b/src/calibre/gui2/device_drivers/configwidget.py index 585eed30df..3d9c9ab2ee 100644 --- a/src/calibre/gui2/device_drivers/configwidget.py +++ b/src/calibre/gui2/device_drivers/configwidget.py @@ -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() diff --git a/src/calibre/gui2/device_drivers/configwidget.ui b/src/calibre/gui2/device_drivers/configwidget.ui index d007599424..497ba43259 100644 --- a/src/calibre/gui2/device_drivers/configwidget.ui +++ b/src/calibre/gui2/device_drivers/configwidget.ui @@ -90,7 +90,14 @@ - + + + + Use author sort for author + + + + Extra customization @@ -103,10 +110,10 @@ - + - + Save &template: @@ -116,7 +123,7 @@ - +