diff --git a/src/calibre/ebooks/lrf/lrfparser.py b/src/calibre/ebooks/lrf/lrfparser.py index d74841515c..566f0b38f1 100644 --- a/src/calibre/ebooks/lrf/lrfparser.py +++ b/src/calibre/ebooks/lrf/lrfparser.py @@ -5,16 +5,16 @@ __copyright__ = '2008, Kovid Goyal ' import sys, array, os, re, codecs, logging from calibre import setup_cli_handlers, sanitize_file_name -from calibre.utils.config import OptionParser +from calibre.utils.config import OptionParser from calibre.ebooks.lrf.meta import LRFMetaFile from calibre.ebooks.lrf.objects import get_object, PageTree, StyleObject, \ Font, Text, TOCObject, BookAttr, ruby_tags - + class LRFDocument(LRFMetaFile): - + class temp(object): pass - + def __init__(self, stream): LRFMetaFile.__init__(self, stream) self.scramble_key = self.xor_key @@ -23,11 +23,11 @@ class LRFDocument(LRFMetaFile): self.image_map = {} self.toc = '' self.keep_parsing = True - + def parse(self): self._parse_objects() self.metadata = LRFDocument.temp() - for a in ('title', 'title_reading', 'author', 'author_reading', 'book_id', + for a in ('title', 'title_reading', 'author', 'author_reading', 'book_id', 'classification', 'free_text', 'publisher', 'label', 'category'): setattr(self.metadata, a, getattr(self, a)) self.doc_info = LRFDocument.temp() @@ -37,7 +37,7 @@ class LRFDocument(LRFMetaFile): self.device_info = LRFDocument.temp() for a in ('dpi', 'width', 'height'): setattr(self.device_info, a, getattr(self, a)) - + def _parse_objects(self): self.objects = {} self._file.seek(self.object_index_offset) @@ -68,15 +68,15 @@ class LRFDocument(LRFMetaFile): attr = h[0] if hasattr(obj, attr): self.ruby_tags[attr] = getattr(obj, attr) - + def __iter__(self): for pt in self.page_trees: yield pt - + def write_files(self): for obj in self.image_map.values() + self.font_map.values(): - open(obj.file, 'wb').write(obj.stream) - + open(obj.file, 'wb').write(obj.stream) + def to_xml(self, write_files=True): bookinfo = u'\n\n\n' bookinfo += u'%s\n'%(self.metadata.title_reading, self.metadata.title) @@ -113,7 +113,7 @@ class LRFDocument(LRFMetaFile): pages += unicode(page) pages += close traversed_objects = [int(i) for i in re.findall(r'objid="(\w+)"', pages)] + [pt_id] - + objects = u'\n\n' styles = u'\n