def reporthook(bar):
    """tqdm progress bar for downloads."""
    def hook(b=1, bsize=1, tsize=None):
        if tsize is not None:
            bar.total = tsize
        bar.update(b * bsize - bar.n)

    return hook