pyanimeinfo.utils.download
download_file
- pyanimeinfo.utils.download.download_file(url, filename=None, output_directory=None, expected_size: int | None = None, desc=None, session=None, silent: bool = False, **kwargs)[source]
Download a file from a given URL to the local file system.
This function downloads a file from a specified URL and saves it to the local file system. It supports optional parameters such as specifying the output filename, output directory, and expected file size.
- Parameters:
url (str) – The URL from which to download the file.
filename (str, optional) – The local filename to save the downloaded file. If not provided, the function tries to extract it from the response headers.
output_directory (str, optional) – The directory where the downloaded file should be saved. If provided, the filename is combined with this directory.
expected_size (int, optional) – The expected size of the downloaded file in bytes. If specified, the function checks whether the downloaded file size matches the expected size.
desc (str, optional) – The description to be displayed during the download progress (e.g., in a progress bar).
session (requests.Session, optional) – An optional requests.Session object to be used for making the HTTP request.
silent (bool) – If True, suppresses the progress bar and download progress display.
**kwargs –
Additional keyword arguments to pass to the requests.get method.
- Returns:
The filename where the downloaded file is saved.
- Return type:
str
- Raises:
requests.exceptions.HTTPError – If the downloaded file size does not match the expected size (if provided).