def get_epub_metadata(filepath, read_cover_image=True, read_toc=True):
if not zipfile.is_zipfile(filepath):<EOL><INDENT>raise EPubException('<STR_LIT>')<EOL><DEDENT>zf = zipfile.ZipFile(filepath, '<STR_LIT:r>', compression=zipfile.ZIP_DEFLATED, allowZip64=True)<EOL>container = zf.read('<STR_LIT>')<EOL>container_xmldoc = minidom.parseString(container)<EOL>opf_filepath = container_xmldoc.getElementsByTagName('<STR_LIT>')[<NUM_LIT:0>].attributes['<STR_LIT>'].value<EOL>opf = zf.read(os.path.normpath(opf_filepath))<EOL>opf_xmldoc = minidom.parseString(opf)<EOL>authors_html = None<EOL>try:<EOL><INDENT>authors_html = minidom.parseString(zf.read('<STR_LIT>'))<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>publish_date_html = None<EOL>try:<EOL><INDENT>publish_date_html = minidom.parseString(zf.read('<STR_LIT>'))<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>file_size_in_bytes = os.path.getsize(filepath)<EOL>data = odict({<EOL>'<STR_LIT>': _discover_epub_version(opf_xmldoc),<EOL>'<STR_LIT:title>': _discover_title(opf_xmldoc),<EOL>'<STR_LIT>': _discover_language(opf_xmldoc),<EOL>'<STR_LIT:description>': _discover_description(opf_xmldoc),<EOL>'<STR_LIT>': _discover_authors(opf_xmldoc, authors_html=authors_html),<EOL>'<STR_LIT>': _discover_publisher(opf_xmldoc),<EOL>'<STR_LIT>': _discover_publication_date(opf_xmldoc,<EOL>date_html=publish_date_html),<EOL>'<STR_LIT>': _discover_identifiers(opf_xmldoc),<EOL>'<STR_LIT>': _discover_subject(opf_xmldoc),<EOL>'<STR_LIT>': file_size_in_bytes,<EOL>})<EOL>if read_cover_image:<EOL><INDENT>cover_image_content, cover_image_extension = _discover_cover_image(zf, opf_xmldoc, opf_filepath)<EOL>data.cover_image_content = cover_image_content<EOL>data.cover_image_extension = cover_image_extension<EOL><DEDENT>if read_toc:<EOL><INDENT>data.toc = _discover_toc(zf, opf_xmldoc, opf_filepath)<EOL><DEDENT>return data<EOL>
References: http://idpf.org/epub/201 and http://idpf.org/epub/301
1. Parse META-INF/container.xml file and find the .OPF file path.
2. In the .OPF file, find the metadata