diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index f27729ae8c..d83dc45a0f 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -10,6 +10,7 @@ Transform OEB content into FB2 markup import cStringIO from base64 import b64encode +from datetime import datetime import re try: @@ -79,38 +80,54 @@ class FB2MLizer(object): return text def fb2_header(self): - author_first = u'' - author_middle = u'' - author_last = u'' + metadata = {} + metadata['author_first'] = u'' + metadata['author_middle'] = u'' + metadata['author_last'] = u'' + metadata['title'] = self.oeb_book.metadata.title[0].value + metadata['appname'] = __appname__ + metadata['version'] = __version__ + metadata['date'] = '%i.%i.%i' % (datetime.now().day, datetime.now().month, datetime.now().year) + metadata['lang'] = u''.join(self.oeb_book.metadata.lang) if self.oeb_book.metadata.lang else 'en' + author_parts = self.oeb_book.metadata.creator[0].value.split(' ') - if len(author_parts) == 1: - author_last = author_parts[0] + metadata['author_last'] = author_parts[0] elif len(author_parts) == 2: - author_first = author_parts[0] - author_last = author_parts[1] + metadata['author_first'] = author_parts[0] + metadata['author_last'] = author_parts[1] else: - author_first = author_parts[0] - author_middle = ' '.join(author_parts[1:-2]) - author_last = author_parts[-1] + metadata['author_first'] = author_parts[0] + metadata['author_middle'] = ' '.join(author_parts[1:-2]) + metadata['author_last'] = author_parts[-1] + + for key, value in metadata.items(): + metadata[key] = prepare_string_for_xml(value) return u'' \ '' \ '' \ - '' \ + 'antique' \ '' \ - '%s' \ - '%s' \ - '%s' \ + '%(author_first)s' \ + '%(author_middle)s' \ + '%(author_last)s' \ '' \ - '%s' \ - '

' \ + '%(title)s' \ + '%(lang)s' \ '' \ '' \ - '%s %s' \ + '' \ + '' \ + '' \ + '' \ + '' \ + '%(appname)s %(version)s' \ + '%(date)s' \ + '1' \ + '1.0' \ '' \ - '' % tuple(map(prepare_string_for_xml, (author_first, author_middle, author_last, - self.oeb_book.metadata.title[0].value, __appname__, __version__))) + '' % metadata def fb2_footer(self): return u''