mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
EPUB3 metadata: Fix handling of <dc:creator> elements with multiple roles. Fixes #1699918 [Author with multiple roles in metadata shown as "Unknown"](https://bugs.launchpad.net/calibre/+bug/1699918)
This commit is contained in:
parent
321ebd2b24
commit
0ada3549c1
@ -79,7 +79,7 @@ def properties_for_id(item_id, refines):
|
||||
|
||||
|
||||
def properties_for_id_with_scheme(item_id, prefixes, refines):
|
||||
ans = {}
|
||||
ans = defaultdict(list)
|
||||
if item_id:
|
||||
for elem in refines[item_id]:
|
||||
key = elem.get('property')
|
||||
@ -95,7 +95,7 @@ def properties_for_id_with_scheme(item_id, prefixes, refines):
|
||||
if ns:
|
||||
scheme_ns = ns
|
||||
scheme = r
|
||||
ans[key] = (scheme_ns, scheme, val)
|
||||
ans[key].append((scheme_ns, scheme, val))
|
||||
return ans
|
||||
|
||||
|
||||
@ -420,7 +420,7 @@ Author = namedtuple('Author', 'name sort')
|
||||
|
||||
|
||||
def is_relators_role(props, q):
|
||||
role = props.get('role')
|
||||
for role in props.get('role'):
|
||||
if role:
|
||||
scheme_ns, scheme, role = role
|
||||
return role.lower() == q and (scheme_ns is None or (scheme_ns, scheme) == (reserved_prefixes['marc'], 'relators'))
|
||||
@ -434,7 +434,7 @@ def read_authors(root, prefixes, refines):
|
||||
aus = None
|
||||
file_as = props.get('file-as')
|
||||
if file_as:
|
||||
aus = file_as[-1]
|
||||
aus = file_as[-1][-1]
|
||||
else:
|
||||
aus = item.get(OPF('file-as')) or None
|
||||
return Author(normalize_whitespace(val), normalize_whitespace(aus))
|
||||
|
@ -149,6 +149,10 @@ class TestOPF3(unittest.TestCase):
|
||||
root = self.get_opf('''<dc:creator>a b</dc:creator><dc:creator opf:role="aut">c d</dc:creator>''')
|
||||
self.ae([Author('c d', None)], rl(root))
|
||||
self.ae(authors, st(root, authors))
|
||||
root = self.get_opf('''<dc:creator id="1">a b</dc:creator>'''
|
||||
'''<meta refines="#1" property="role">aut</meta>'''
|
||||
'''<meta refines="#1" property="role">cow</meta>''')
|
||||
self.ae([Author('a b', None)], rl(root))
|
||||
# }}}
|
||||
|
||||
def test_book_producer(self): # {{{
|
||||
@ -562,6 +566,7 @@ class TestRunner(unittest.main):
|
||||
def run(verbosity=4):
|
||||
TestRunner(verbosity=verbosity, exit=False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(verbosity=4)
|
||||
# }}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user