Skip to content

cli

callback

callback(
    _: Annotated[
        bool | None,
        typer.Option(
            --version,
            callback=version_callback,
            is_eager=True,
        ),
    ] = None,
)

SoferAI's Torah Downloader

Source code in src/torah_dl/cli.py
77
78
79
80
81
82
83
84
85
86
87
@app.callback(invoke_without_command=True)
def callback(
    _: Annotated[
        bool | None,
        typer.Option("--version", callback=version_callback, is_eager=True),
    ] = None,
):
    """
    SoferAI's Torah Downloader
    """
    pass

download_url

download_url(
    url: Annotated[
        str, typer.Argument(help="URL to download")
    ],
    output_path: Annotated[
        Path,
        typer.Argument(
            help="Path to save the downloaded file"
        ),
    ] = Path("audio"),
)

Download a file from a URL and show progress.

Source code in src/torah_dl/cli.py
45
46
47
48
49
50
51
52
53
54
@app.command(name="download")
def download_url(
    url: Annotated[str, typer.Argument(help="URL to download")],
    output_path: Annotated[Path, typer.Argument(help="Path to save the downloaded file")] = Path("audio"),
):
    """Download a file from a URL and show progress."""
    with console.status("Extracting URL..."):
        extraction = extract(url)
    with console.status("Downloading file..."):
        download(extraction.download_url, output_path)

extract_url

extract_url(
    url: str,
    url_only: Annotated[
        bool,
        typer.Option(
            --url - only,
            help="Only output the download URL",
        ),
    ] = False,
)

Extract information from a given URL

Source code in src/torah_dl/cli.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@app.command(name="extract")
def extract_url(
    url: str,
    url_only: Annotated[bool, typer.Option("--url-only", help="Only output the download URL")] = False,
):
    """
    Extract information from a given URL
    """
    with console.status("Extracting URL..."):
        try:
            extraction = extract(url)
        except ExtractorNotFoundError:
            typer.echo(f"Extractor not found for URL: {url}", err=True)
            raise typer.Exit(1) from None

    if url_only:
        typer.echo(extraction.download_url)
    else:
        table = Table(box=None, pad_edge=False)
        table.add_row("Title", extraction.title, style="cyan")
        table.add_row("Download URL", extraction.download_url, style="green")
        console.print(table)

list_extractors_command

list_extractors_command()

List all available extractors.

Source code in src/torah_dl/cli.py
57
58
59
60
61
62
63
64
65
@app.command(name="list")
def list_extractors_command():
    """List all available extractors."""
    extractors = list_extractors()
    table = Table(box=None, pad_edge=False)
    table.add_row("Name", "Homepage")
    for name, homepage in extractors.items():
        table.add_row(name, homepage)
    console.print(table)

version_callback

version_callback(value: bool)

print version information to shell

Source code in src/torah_dl/cli.py
68
69
70
71
72
73
74
def version_callback(value: bool):
    """
    print version information to shell
    """
    if value:
        typer.echo(f"torah-dl version: {__version__}")
        raise typer.Exit()