View Single Post
Old 12-15-2015, 09:54 AM   #2
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,803
Karma: 6000000
Join Date: Nov 2009
Device: many
Using the built in Quick Parser to parse OPF Metadata

Code:
    # Example of using the provided stream based QuickParser
    # to parse metadataxml (to look for cover id)
    # Also rebuilds the metadata xml in res
    ps = bk.qp
    ps.setContent(bk.getmetadataxml())
    res = []
    coverid = None
    # parse the metadataxml, store away cover_id and rebuild it
    for text, tagprefix, tagname, tagtype, tagattr in ps.parse_iter():
        if text is not None:
            # print(text)
            res.append(text)
        else:
            # print(tagprefix, tagname, tagtype, tagattr)
            if tagname == "meta" and tagattr.get("name",'') == "cover":
                coverid = tagattr["content"]
            res.append(ps.tag_info_to_xml(tagname, tagtype, tagattr))
    original_metadata = "".join(res)
KevinH is online now   Reply With Quote