Skip to content

Commit f4271c4

Browse files
committed
Merge branch 'release/1.0.7'
2 parents c6c8968 + 66a03d9 commit f4271c4

2 files changed

Lines changed: 15 additions & 23 deletions

File tree

src/epublius/metadata.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,32 +106,22 @@ def get_file_soup(self):
106106

107107
def get_chapter_title(self):
108108
'''
109-
Retrieve chapter title based on the text of <h1> or
109+
Retrieve chapter title based on the text of <title> or
110110
taking a guess from the file name
111111
(i.e. front-cover.xhtml -> "Front Cover")
112112
113113
Special characters in the title are escaped before
114114
the ch_title varible is returned.
115115
'''
116116

117-
h1 = self.soup.find_all('h1')
118-
119-
if len(h1) == 1:
120-
ch_title = self.soup.h1.get_text()
121-
122-
elif len(h1) > 1:
123-
print("[WARNING] {} has multiple h1 tags"
124-
.format(self.contents[self.index]))
125-
ch_title = h1.pop(0).get_text()
117+
title_node = self.soup.title
126118

119+
if (title_node is not None) and \
120+
(title_node.string is not None):
121+
ch_title = title_node.string
127122
else:
128-
# Strip extension from file name
129-
basename = self.contents[self.index].split('.')[0]
130-
131-
# Replace hypens with spaces (if any)
123+
basename = os.path.splitext(self.contents[self.index])[0]
132124
title_words = basename.replace('-', ' ')
133-
134-
# Create a titlecased version of title words
135125
ch_title = title_words.title()
136126

137127
return html.escape(ch_title)

src/thoth_wrapper.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ def get_title(thoth_data):
1919
def get_html_pub_url(thoth_data):
2020
for publication in thoth_data["publications"]:
2121
if publication['publicationType'] == 'HTML':
22-
try:
23-
url = publication['locations'][0]['fullTextUrl']
24-
except IndexError:
25-
raise IndexError('HTML edition defined in Thoth but '
26-
'location URL not specified. Please, '
27-
'add it and re-run the process.')
22+
locations = publication.get('locations', [])
2823
break
2924
else:
30-
raise SystemExit('HTML edition data not found in Thoth.',
25+
raise ValueError('HTML edition data not found in Thoth.',
3126
'Please add it and re-run the process.')
3227

28+
try:
29+
url = locations[0]['fullTextUrl']
30+
except IndexError:
31+
raise IndexError('HTML edition defined in Thoth but '
32+
'location URL not specified. Please, '
33+
'add it and re-run the process.')
34+
3335
return url
3436

3537
def run():

0 commit comments

Comments
 (0)