Exemple #1
0
    def create_ncx(self):
        index_entries = read_ncx(self.kf8_sections, self.header.ncxidx,
                self.header.codec)
        remove = []

        # Add href and anchor info to the index entries
        for entry in index_entries:
            pos_fid = entry['pos_fid']
            if pos_fid is None:
                pos = entry['pos']
                fi = self.get_file_info(pos)
                if fi.filename is None:
                    raise ValueError('Index entry has invalid pos: %d'%pos)
                idtag = self.get_id_tag(pos).decode(self.header.codec)
                href = '%s/%s'%(fi.type, fi.filename)
            else:
                try:
                    href, idtag = self.get_id_tag_by_pos_fid(*pos_fid)
                except ValueError:
                    self.log.warn('Invalid entry in NCX (title: %s), ignoring'
                                  %entry['text'])
                    remove.append(entry)
                    continue

            entry['href'] = href
            entry['idtag'] = idtag

        for e in remove:
            index_entries.remove(e)

        # Build the TOC object
        return build_toc(index_entries)
Exemple #2
0
    def create_ncx(self):
        index_entries = read_ncx(self.kf8_sections, self.header.ncxidx,
                                 self.header.codec)
        remove = []

        # Add href and anchor info to the index entries
        for entry in index_entries:
            pos_fid = entry['pos_fid']
            if pos_fid is None:
                pos = entry['pos']
                fi = self.get_file_info(pos)
                if fi.filename is None:
                    raise ValueError('Index entry has invalid pos: %d' % pos)
                idtag = self.get_id_tag(pos).decode(self.header.codec)
                href = '%s/%s' % (fi.type, fi.filename)
            else:
                try:
                    href, idtag = self.get_id_tag_by_pos_fid(*pos_fid)
                except ValueError:
                    self.log.warn(
                        'Invalid entry in NCX (title: %s), ignoring' %
                        entry['text'])
                    remove.append(entry)
                    continue

            entry['href'] = href
            entry['idtag'] = idtag

        for e in remove:
            index_entries.remove(e)

        # Build the TOC object
        return build_toc(index_entries)
Exemple #3
0
    def create_ncx(self):
        index_entries = read_ncx(self.kf8_sections, self.header.ncxidx,
                self.header.codec)

        # Add href and anchor info to the index entries
        for entry in index_entries:
            pos_fid = entry['pos_fid']
            if pos_fid is None:
                pos = entry['pos']
                fi = self.get_file_info(pos)
                if fi.filename is None:
                    raise ValueError('Index entry has invalid pos: %d'%pos)
                idtag = self.get_id_tag(pos).decode(self.header.codec)
                href = '%s/%s'%(fi.type, fi.filename)
            else:
                href, idtag = self.get_id_tag_by_pos_fid(*pos_fid)

            entry['href'] = href
            entry['idtag'] = idtag

        # Build the TOC object
        return build_toc(index_entries)