human
Complete this python program:
def download_cover(log, title=None, authors=None, identifiers={}, timeout=30):
assistant
#Here is the Python code you requested.

    """Synchronous cover download. Returns the "best" cover as per user
    prefs/cover resolution.
    Returned cover is a tuple: (plugin, width, height, fmt, data)
    Returns None if no cover is found.
    """
    rq = Queue()
    abort = Event()
    run_download(log, rq, abort, title=title, authors=authors, identifiers=identifiers, timeout=timeout, get_best_cover=True)
    results = []
    while True:
        try:
            results.append(rq.get_nowait())
        except Empty:
            break
    cp = msprefs[u'cover_priorities']
    def keygen(result):
        (plugin, width, height, fmt, data) = result
        return (cp.get(plugin.name, 1), (1 / (width * height)))
    results.sort(key=keygen)
    return (results[0] if results else None)