import logging import sys from tqdm import tqdm from .utils import env_bool from .voices import voice_manager log = logging.getLogger(__name__) def calculate_total_size() -> int: """ Calculate the total size of all files to be downloaded based on selected categories. """ total_size = 0 total_size += voice_manager.get_voices_size_if_missing() return total_size def prerequisites_download_pipeline() -> None: """ Manage the download pipeline for different categories of files. """ if env_bool("OFFLINE", False): log.info("Skipping download due to OFFLINE environment variable") return total_size = calculate_total_size() if total_size > 0: log.info(f"Will download {total_size:,} bytes") miniters = None if sys.stdout.isatty() else total_size with tqdm(total=total_size, unit="iB", unit_scale=True, desc="Downloading...", miniters=miniters) as global_bar: voice_manager.download_voice_files(global_bar) else: log.info("No files to download")