File size: 1,063 Bytes
c6fd5b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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")