Skip to content

用于批量下载文件,支持同步和异步下载模式。无论是下载单个大文件还是批量下载多个文件,Batch Downloader 都提供了简单易用的接口,并支持分块下载、进度回调、自定义文件名等功能,帮助用户轻松管理下载任务。

License

Notifications You must be signed in to change notification settings

Zzhenping/batch_downloader

Repository files navigation

Batch Downloader

A simple Python package for downloading multiple files in parallel with chunked downloads.

Installation

pip install batch_downloader

Usage

def progress_callback(url: str, downloaded_size: int, total_size: int):
    if total_size > 0:
        progress = (downloaded_size / total_size) * 100
        print(f"Downloading {url}: {progress:.2f}%")
    else:
        print(f"Downloading {url}: {downloaded_size} bytes (total size unknown)")

downloader = BatchDownloader(
    urls=[
        "xxx",
        "xxx",
        ],
    output_dir="downloads",
    progress_callback=progress_callback,
)

results = downloader.download_all()

Async Usage

class TestAsyncBatchDownloader(unittest.TestCase):

    def progress_callback(self, url: str, downloaded_size: int, total_size: int):
        if total_size > 0:
            progress = (downloaded_size / total_size) * 100
            print(f"Downloading {url.split('/')[-1]}: {progress:.2f}% ({downloaded_size}/{total_size} bytes)")
        else:
            print(f"Downloading {url.split('/')[-1]}: {downloaded_size} bytes (total size unknown)")

    async def async_test_download(self):
        downloader = AsyncBatchDownloader(
            urls=[
                "xxx",
                "xxx",
            ],
            output_dir="downloads",
            progress_callback=self.progress_callback,
        )
        results = await downloader.download_all()
        self.assertTrue(isinstance(results, list))

    def test_download(self):
        asyncio.run(self.async_test_download())

if __name__ == "__main__":
    unittest.main()

About

用于批量下载文件,支持同步和异步下载模式。无论是下载单个大文件还是批量下载多个文件,Batch Downloader 都提供了简单易用的接口,并支持分块下载、进度回调、自定义文件名等功能,帮助用户轻松管理下载任务。

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages