EPUB 3 metadata: If the book contains a "subtitle" append it to the main title when reading metadata. Fixes #1950762 [Add subtitle to calibre title](https://bugs.launchpad.net/calibre/+bug/1950762)

This commit is contained in:
Kovid Goyal 2021-11-29 15:15:21 +05:30
parent 02e8bc631c
commit 61e2d4e175
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -358,10 +358,26 @@ def find_main_title(root, refines, remove_blanks=False):
return main_title
def find_subtitle(root, refines):
for title in XPath('./opf:metadata/dc:title')(root):
if not title.text or not title.text.strip():
continue
props = properties_for_id(title.get('id'), refines)
q = props.get('title-type') or ''
if 'subtitle' in q or 'sub-title' in q:
return title
@simple_text
def read_title(root, prefixes, refines):
main_title = find_main_title(root, refines)
return None if main_title is None else main_title.text.strip()
if main_title is None:
return None
ans = main_title.text.strip()
st = find_subtitle(root, refines)
if st is not None and st is not main_title:
ans += ': ' + st.text.strip()
return ans
@simple_text
@ -380,6 +396,9 @@ def read_title_sort(root, prefixes, refines):
def set_title(root, prefixes, refines, title, title_sort=None):
main_title = find_main_title(root, refines, remove_blanks=True)
st = find_subtitle(root, refines)
if st is not None:
remove_element(st, refines)
if main_title is None:
m = XPath('./opf:metadata')(root)[0]
main_title = m.makeelement(DC('title'))