From 5ca15b9175427685b67a3b5961a555677a7d2d14 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 14 Nov 2021 18:03:35 +0530 Subject: [PATCH] Also use editors as authors in EPUB 2 --- src/calibre/ebooks/metadata/opf2.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index 148c392f47..5febf2688b 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -544,6 +544,7 @@ class OPF: # {{{ 'and re:match(@name, concat("^calibre:", $name, "$"), "i"))]') title_path = XPath('descendant::*[re:match(name(), "title", "i")]') authors_path = XPath('descendant::*[re:match(name(), "creator", "i") and (@role="aut" or @opf:role="aut" or (not(@role) and not(@opf:role)))]') + editors_path = XPath('descendant::*[re:match(name(), "creator", "i") and (@role="edt" or @opf:role="edt")]') bkp_path = XPath('descendant::*[re:match(name(), "contributor", "i") and (@role="bkp" or @opf:role="bkp")]') tags_path = XPath('descendant::*[re:match(name(), "subject", "i")]') isbn_path = XPath('descendant::*[re:match(name(), "identifier", "i") and ' @@ -846,11 +847,14 @@ class OPF: # {{{ ans = [] for elem in self.authors_path(self.metadata): ans.extend(string_to_authors(self.get_text(elem))) + if not ans: + for elem in self.editors_path(self.metadata): + ans.extend(string_to_authors(self.get_text(elem))) return ans @authors.setter def authors(self, val): - remove = list(self.authors_path(self.metadata)) + remove = list(self.authors_path(self.metadata)) or list(self.editors_path(self.metadata)) for elem in remove: elem.getparent().remove(elem) # Ensure new author element is at the top of the list @@ -866,18 +870,16 @@ class OPF: # {{{ @property def author_sort(self): - matches = self.authors_path(self.metadata) + matches = self.authors_path(self.metadata) or self.editors_path(self.metadata) if matches: for match in matches: - ans = match.get('{%s}file-as'%self.NAMESPACES['opf'], None) - if not ans: - ans = match.get('file-as', None) + ans = match.get('{%s}file-as'%self.NAMESPACES['opf']) or match.get('file-as') if ans: return ans @author_sort.setter def author_sort(self, val): - matches = self.authors_path(self.metadata) + matches = self.authors_path(self.metadata) or self.editors_path(self.metadata) if matches: for key in matches[0].attrib: if key.endswith('file-as'):