'Read all metadata specified by the user. Command line options override
metadata from a specified OPF file.'

def read_user_metadata(self):

    from calibre.ebooks.metadata import MetaInformation
    from calibre.ebooks.metadata.opf2 import OPF
    mi = MetaInformation(None, [])
    if (self.opts.read_metadata_from_opf is not None):
        self.opts.read_metadata_from_opf = os.path.abspath(self.opts.read_metadata_from_opf)
        opf = OPF(open(self.opts.read_metadata_from_opf, 'rb'), os.path.dirname(self.opts.read_metadata_from_opf))
        mi = opf.to_book_metadata()
    self.opts_to_mi(mi)
    if mi.cover:
        if (mi.cover.startswith('http:') or mi.cover.startswith('https:')):
            mi.cover = self.download_cover(mi.cover)
        ext = mi.cover.rpartition('.')[(-1)].lower().strip()
        if (ext not in ('png', 'jpg', 'jpeg', 'gif')):
            ext = 'jpg'
        mi.cover_data = (ext, open(mi.cover, 'rb').read())
        mi.cover = None
    self.user_metadata = mi
