def get_metadata(stream): if isinstance(stream, bytes): stream = DummyFile(stream) root = parse_opf(stream) ver = parse_opf_version(root.get('version')) opf = OPF(None, preparsed_opf=root, read_toc=False) return opf.to_book_metadata(), ver, opf.raster_cover, opf.first_spine_item()
def set_metadata(stream, mi, cover_prefix='', cover_data=None, apply_null=False, update_timestamp=False, force_identifiers=False): if isinstance(stream, bytes): stream = DummyFile(stream) root = parse_opf(stream) ver = parse_opf_version(root.get('version')) opfbytes, raster_cover = set_metadata_opf2( root, cover_prefix, mi, ver, cover_data=cover_data, apply_null=apply_null, update_timestamp=update_timestamp, force_identifiers=force_identifiers) return opfbytes, ver, raster_cover
def get_metadata(stream): if isinstance(stream, bytes): stream = DummyFile(stream) root = parse_opf(stream) ver = parse_opf_version(root.get('version')) opf = OPF(None, preparsed_opf=root, read_toc=False) return opf.to_book_metadata(), ver, opf.raster_cover, opf.first_spine_item( )
def set_metadata(stream, mi, cover_prefix='', cover_data=None, apply_null=False, update_timestamp=False, force_identifiers=False, add_missing_cover=True): if isinstance(stream, bytes): stream = DummyFile(stream) root = parse_opf(stream) ver = parse_opf_version(root.get('version')) f = set_metadata_opf2 if ver.major < 3 else set_metadata_opf3 opfbytes, raster_cover = f( root, cover_prefix, mi, ver, cover_data=cover_data, apply_null=apply_null, update_timestamp=update_timestamp, force_identifiers=force_identifiers, add_missing_cover=add_missing_cover) return opfbytes, ver, raster_cover
def set_metadata(stream, mi, cover_prefix='', cover_data=None, apply_null=False, update_timestamp=False, force_identifiers=False, add_missing_cover=True): root = parse_opf(stream) return apply_metadata(root, mi, cover_prefix=cover_prefix, cover_data=cover_data, apply_null=apply_null, update_timestamp=update_timestamp, force_identifiers=force_identifiers)
def get_metadata(stream): root = parse_opf(stream) return read_metadata(root)
def get_metadata(stream): if isinstance(stream, bytes): stream = DummyFile(stream) root = parse_opf(stream) ver = parse_opf_version(root.get('version')) return get_metadata2(root, ver)
del tag.attrib[k] def upgrade_metadata(root): data = Data() data.prefixes = read_prefixes(root) data.refines = read_refines(root) upgrade_identifiers(root, data) upgrade_title(root, data) upgrade_languages(root, data) upgrade_authors(root, data) upgrade_timestamp(root, data) upgrade_date(root, data) upgrade_rating(root, data) upgrade_series(root, data) upgrade_custom(root, data) upgrade_meta(root, data) upgrade_cover(root, data) remove_invalid_attrs_in_dc_metadata(root, data) set_last_modified(root, data.prefixes, data.refines) pretty_print_opf(root) if __name__ == '__main__': import sys root = parse_opf(open(sys.argv[-1], 'rb')) upgrade_metadata(root) print(etree.tostring(root))
def get_metadata(stream): if isinstance(stream, bytes): stream = DummyFile(stream) root = parse_opf(stream) return get_metadata_from_parsed(root)
def set_metadata(stream, mi, cover_prefix='', cover_data=None, apply_null=False, update_timestamp=False, force_identifiers=False, add_missing_cover=True): root = parse_opf(stream) return apply_metadata( root, mi, cover_prefix=cover_prefix, cover_data=cover_data, apply_null=apply_null, update_timestamp=update_timestamp, force_identifiers=force_identifiers)