'Return the cover image as a bytestring (in JPEG format) or None.
WARNING: Using as_path will copy the cover to a temp file and return
the path to the temp file. You should delete the temp file when you are
done with it.
:param as_file: If True return the image as an open file object (a SpooledTemporaryFile)
:param as_image: If True return the image as a QImage object'

def cover(self, index, index_is_id=False, as_file=False, as_image=False, as_path=False):

    id = (index if index_is_id else self.id(index))
    path = os.path.join(self.library_path, self.path(id, index_is_id=True), 'cover.jpg')
    if os.access(path, os.R_OK):
        try:
            f = lopen(path, 'rb')
        except (IOError, OSError):
            time.sleep(0.2)
            f = lopen(path, 'rb')
        with f:
            if as_path:
                pt = PersistentTemporaryFile('_dbcover.jpg')
                with pt:
                    shutil.copyfileobj(f, pt)
                return pt.name
            if as_file:
                ret = SpooledTemporaryFile(SPOOL_SIZE)
                shutil.copyfileobj(f, ret)
                ret.seek(0)
            else:
                ret = f.read()
                if as_image:
                    from PyQt5.Qt import QImage
                    i = QImage()
                    i.loadFromData(ret)
                    ret = i
        return ret
