def generate_downloader(headers: Dict[str, str], args: Any, max_per_hour: int=30
                        ) -> Callable[..., None]:
    """Create function to download with rate limiting and text progress."""

    def _downloader(url: str, dest: str) -> None:

        @rate_limited(max_per_hour, args)
        def _rate_limited_download() -> None:

            # Create parent directory of file, and its parents, if they don't exist.
            parent = os.path.dirname(dest)
            if not os.path.exists(parent):
                os.makedirs(parent)

            response = requests.get(url, headers=headers, stream=True)
            LOG.info(f"Downloading from '{url}'.")
            LOG.info(f"Trying to save to '{dest}'.")

            length = response.headers.get("content-length")
            if length is None:
                total_length = 0
            else:
                total_length = int(length)

            expected_size = (total_length / CHUNK_SIZE) + 1
            chunks = response.iter_content(chunk_size=CHUNK_SIZE)

            open(dest, "a", encoding=FORCED_ENCODING).close()
            # per http://stackoverflow.com/a/20943461
            with open(dest, "wb") as stream:
                for chunk in tui.progress.bar(chunks, expected_size=expected_size):
                    if not chunk:
                        return
                    stream.write(chunk)
                    stream.flush()

        _rate_limited_download()

    return _downloader
Create function to download with rate limiting and text progress.