mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Also use editors as authors in EPUB 2
This commit is contained in:
parent
f7452f5211
commit
5ca15b9175
@ -544,6 +544,7 @@ class OPF: # {{{
|
|||||||
'and re:match(@name, concat("^calibre:", $name, "$"), "i"))]')
|
'and re:match(@name, concat("^calibre:", $name, "$"), "i"))]')
|
||||||
title_path = XPath('descendant::*[re:match(name(), "title", "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)))]')
|
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")]')
|
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")]')
|
tags_path = XPath('descendant::*[re:match(name(), "subject", "i")]')
|
||||||
isbn_path = XPath('descendant::*[re:match(name(), "identifier", "i") and '
|
isbn_path = XPath('descendant::*[re:match(name(), "identifier", "i") and '
|
||||||
@ -846,11 +847,14 @@ class OPF: # {{{
|
|||||||
ans = []
|
ans = []
|
||||||
for elem in self.authors_path(self.metadata):
|
for elem in self.authors_path(self.metadata):
|
||||||
ans.extend(string_to_authors(self.get_text(elem)))
|
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
|
return ans
|
||||||
|
|
||||||
@authors.setter
|
@authors.setter
|
||||||
def authors(self, val):
|
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:
|
for elem in remove:
|
||||||
elem.getparent().remove(elem)
|
elem.getparent().remove(elem)
|
||||||
# Ensure new author element is at the top of the list
|
# Ensure new author element is at the top of the list
|
||||||
@ -866,18 +870,16 @@ class OPF: # {{{
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def author_sort(self):
|
def author_sort(self):
|
||||||
matches = self.authors_path(self.metadata)
|
matches = self.authors_path(self.metadata) or self.editors_path(self.metadata)
|
||||||
if matches:
|
if matches:
|
||||||
for match in matches:
|
for match in matches:
|
||||||
ans = match.get('{%s}file-as'%self.NAMESPACES['opf'], None)
|
ans = match.get('{%s}file-as'%self.NAMESPACES['opf']) or match.get('file-as')
|
||||||
if not ans:
|
|
||||||
ans = match.get('file-as', None)
|
|
||||||
if ans:
|
if ans:
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
@author_sort.setter
|
@author_sort.setter
|
||||||
def author_sort(self, val):
|
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:
|
if matches:
|
||||||
for key in matches[0].attrib:
|
for key in matches[0].attrib:
|
||||||
if key.endswith('file-as'):
|
if key.endswith('file-as'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user