Skip to content

Processor old

TelegramDownloader

Bases: BaseModel

Methods:

Name Description
download

output_folder

output_folder: Path = Field(
    ...,
    description="The output directory for the downloaded files; same with `--dir`.",
    frozen=False,
    deprecated=False,
)

tdl

tdl: str

download

download(urls: list[str] | str) -> None
Source code in src/core/processor_old.py
def download(self, urls: list[str] | str) -> None:
    urls = ",".join(urls) if isinstance(urls, list) else urls
    command = [self.tdl, "download", "--dir", self.output_folder.as_posix(), "--url", urls]

    try:
        with subprocess.Popen(  # noqa: S603
            command,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True,
            encoding="utf-8",
            shell=False,
        ) as proc:
            if proc.stdout is None or proc.stderr is None:
                return
            return_code = proc.wait()
            if return_code == 0:
                logfire.info(f"Download completed successfully with exit code {return_code}")
                return
            logfire.error(f"Download failed with exit code {return_code}", _exc_info=True)
            return

    except Exception:
        logfire.error("An exception occurred during download", _exc_info=True)
        return