73
73
def clean_text(self, text):
74
74
# Condense empty paragraphs into a line break.
75
text = re.sub(r'(?miu)(<p>\s*</p>\s*){3,}', '<p><empty-line /></p>', text)
75
text = re.sub(r'(?miu)(<p>\s*</p>\s*){3,}', '<empty-line />', text)
76
76
# Remove empty paragraphs.
77
77
text = re.sub(r'(?miu)<p>\s*</p>', '', text)
78
78
# Clean up pargraph endings.
102
102
def fb2_header(self):
104
metadata['author_first'] = u''
105
metadata['author_middle'] = u''
106
metadata['author_last'] = u''
107
104
metadata['title'] = self.oeb_book.metadata.title[0].value
108
105
metadata['appname'] = __appname__
109
106
metadata['version'] = __version__
115
112
metadata['id'] = None
116
113
metadata['cover'] = self.get_cover()
118
author_parts = self.oeb_book.metadata.creator[0].value.split(' ')
119
if len(author_parts) == 1:
120
metadata['author_last'] = author_parts[0]
121
elif len(author_parts) == 2:
122
metadata['author_first'] = author_parts[0]
123
metadata['author_last'] = author_parts[1]
125
metadata['author_first'] = author_parts[0]
126
metadata['author_middle'] = ' '.join(author_parts[1:-2])
127
metadata['author_last'] = author_parts[-1]
115
metadata['author'] = u''
116
for auth in self.oeb_book.metadata.creator:
120
author_parts = auth.value.split(' ')
121
if len(author_parts) == 1:
122
author_last = author_parts[0]
123
elif len(author_parts) == 2:
124
author_first = author_parts[0]
125
author_last = author_parts[1]
127
author_first = author_parts[0]
128
author_middle = ' '.join(author_parts[1:-1])
129
author_last = author_parts[-1]
130
metadata['author'] += '<author>'
131
metadata['author'] += '<first-name>%s</first-name>' % prepare_string_for_xml(author_first)
133
metadata['author'] += '<middle-name>%s</middle-name>' % prepare_string_for_xml(author_middle)
134
metadata['author'] += '<last-name>%s</last-name>' % prepare_string_for_xml(author_last)
135
metadata['author'] += '</author>'
136
if not metadata['author']:
137
metadata['author'] = u'<author><first-name></first-name><last-name><last-name></author>'
139
metadata['sequence'] = u''
140
if self.oeb_book.metadata.series:
142
if self.oeb_book.metadata.series_index:
143
index = self.oeb_book.metadata.series_index[0]
144
metadata['sequence'] = u'<sequence name="%s" number="%s" />' % (prepare_string_for_xml(u'%s' % self.oeb_book.metadata.series[0]), index)
129
146
identifiers = self.oeb_book.metadata['identifier']
130
147
for x in identifiers:
136
153
metadata['id'] = str(uuid.uuid4())
138
155
for key, value in metadata.items():
139
if not key == 'cover':
156
if key not in ('author', 'cover', 'sequence'):
140
157
metadata[key] = prepare_string_for_xml(value)
142
159
return u'<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:xlink="http://www.w3.org/1999/xlink">' \
143
160
'<description>' \
145
162
'<genre>antique</genre>' \
147
'<first-name>%(author_first)s</first-name>' \
148
'<middle-name>%(author_middle)s</middle-name>' \
149
'<last-name>%(author_last)s</last-name>' \
151
164
'<book-title>%(title)s</book-title>' \
153
166
'<lang>%(lang)s</lang>' \
154
168
'</title-info>' \
155
169
'<document-info>' \
157
'<first-name></first-name>' \
158
'<middle-name></middle-name>' \
159
'<last-name></last-name>' \
161
171
'<program-used>%(appname)s %(version)s</program-used>' \
162
172
'<date>%(date)s</date>' \
163
173
'<id>%(id)s</id>' \