def __init__(self, header, stream, log, options): self.log = log self.encoding = options.input_encoding self.log.debug('202 byte header version found.') self.sections = [] for i in range(header.num_sections): self.sections.append(header.section_data(i)) self.header_record = HeaderRecord(self.section_data(0)) if self.header_record.version not in (2, 4): raise EreaderError('Unknown book version %i.' % self.header_record.version) from calibre.ebooks.metadata.pdb import get_metadata self.mi = get_metadata(stream, False)
def __init__(self, header, stream, log, options): self.log = log self.encoding = options.input_encoding self.log.debug('132 byte header version found.') self.sections = [] for i in range(header.num_sections): self.sections.append(header.section_data(i)) self.header_record = HeaderRecord(self.section_data(0)) if self.header_record.compression not in (2, 10): if self.header_record.compression in (260, 272): raise DRMError('eReader DRM is not supported.') else: raise EreaderError('Unknown book compression %i.' % self.header_record.compression) from calibre.ebooks.metadata.pdb import get_metadata self.mi = get_metadata(stream, False)
def __init__(self, header, stream, log, options): self.stream = stream self.log = log self.options = options # Mapping of section uid to our internal # list of sections. self.uid_section_number = OrderedDict() self.uid_text_secion_number = OrderedDict() self.uid_text_secion_encoding = {} self.uid_image_section_number = {} self.uid_composite_image_section_number = {} self.metadata_section_number = None self.default_encoding = 'latin-1' self.owner_id = None self.sections = [] # The Plucker record0 header self.header_record = HeaderRecord(header.section_data(0)) for i in range(1, header.num_sections): section_number = len(self.sections) # The length of the section header. # Where the actual data in the section starts. start = 8 section = None raw_data = header.section_data(i) # Every sections has a section header. section_header = SectionHeader(raw_data) # Store sections we care able. if section_header.type in (DATATYPE_PHTML, DATATYPE_PHTML_COMPRESSED): self.uid_text_secion_number[section_header.uid] = section_number section = SectionText(section_header, raw_data[start:]) elif section_header.type in (DATATYPE_TBMP, DATATYPE_TBMP_COMPRESSED): self.uid_image_section_number[section_header.uid] = section_number section = raw_data[start:] elif section_header.type == DATATYPE_METADATA: self.metadata_section_number = section_number section = SectionMetadata(raw_data[start:]) elif section_header.type == DATATYPE_COMPOSITE_IMAGE: self.uid_composite_image_section_number[section_header.uid] = section_number section = SectionCompositeImage(raw_data[start:]) # Store the section. if section: self.uid_section_number[section_header.uid] = section_number self.sections.append((section_header, section)) # Store useful information from the metadata section locally # to make access easier. if self.metadata_section_number: mdata_section = self.sections[self.metadata_section_number][1] for k, v in mdata_section.exceptional_uid_encodings.items(): self.uid_text_secion_encoding[k] = v self.default_encoding = mdata_section.default_encoding self.owner_id = mdata_section.owner_id # Get the metadata (tile, author, ...) with the metadata reader. from calibre.ebooks.metadata.pdb import get_metadata self.mi = get_metadata(stream, False)
def __init__(self, header, stream, log, options): self.stream = stream self.log = log self.options = options # Mapping of section uid to our internal # list of sections. self.uid_section_number = OrderedDict() self.uid_text_secion_number = OrderedDict() self.uid_text_secion_encoding = {} self.uid_image_section_number = {} self.uid_composite_image_section_number = {} self.metadata_section_number = None self.default_encoding = 'latin-1' self.owner_id = None self.sections = [] # The Plucker record0 header self.header_record = HeaderRecord(header.section_data(0)) for i in range(1, header.num_sections): section_number = len(self.sections) # The length of the section header. # Where the actual data in the section starts. start = 8 section = None raw_data = header.section_data(i) # Every sections has a section header. section_header = SectionHeader(raw_data) # Store sections we care able. if section_header.type in (DATATYPE_PHTML, DATATYPE_PHTML_COMPRESSED): self.uid_text_secion_number[ section_header.uid] = section_number section = SectionText(section_header, raw_data[start:]) elif section_header.type in (DATATYPE_TBMP, DATATYPE_TBMP_COMPRESSED): self.uid_image_section_number[ section_header.uid] = section_number section = raw_data[start:] elif section_header.type == DATATYPE_METADATA: self.metadata_section_number = section_number section = SectionMetadata(raw_data[start:]) elif section_header.type == DATATYPE_COMPOSITE_IMAGE: self.uid_composite_image_section_number[ section_header.uid] = section_number section = SectionCompositeImage(raw_data[start:]) # Store the section. if section: self.uid_section_number[section_header.uid] = section_number self.sections.append((section_header, section)) # Store useful information from the metadata section locally # to make access easier. if self.metadata_section_number: mdata_section = self.sections[self.metadata_section_number][1] for k, v in mdata_section.exceptional_uid_encodings.items(): self.uid_text_secion_encoding[k] = v self.default_encoding = mdata_section.default_encoding self.owner_id = mdata_section.owner_id # Get the metadata (tile, author, ...) with the metadata reader. from calibre.ebooks.metadata.pdb import get_metadata self.mi = get_metadata(stream, False)