Air2 - 高性能多线程下载引擎 Air2 是一个用 Python 编写的高性能命令行下载工具,支持多线程分块下载、断点续传、速度限制和美观的实时进度显示。它提供交互式命令行界面和单命令快速执行两种模式,兼顾易用性与强大性能。
✨ 主要优点 (中文)
- 🚀 极致下载速度 智能多线程分块:根据文件大小动态调整分块数量与大小(最大支持 16 MB 块),充分利用带宽资源。
大缓冲区优化:单次写入使用 1 MB 缓冲区,减少磁盘 I/O 开销。
高并发连接池:每个任务支持多达 16 个并发连接,线程池可容纳 200 个工作线程,大幅提升大文件下载效率。
- 🛠️ 完善的断点续传与错误恢复 支持从已下载的部分继续下载,避免重复传输。
内置智能重试机制(指数退避),对网络波动、临时服务器错误自动恢复。
下载前预分配文件空间,减少磁盘碎片并提高写入稳定性。
- 📊 美观且实时的进度反馈 基于 Rich 库构建的终端界面,提供彩色进度条、实时速度、预计剩余时间等关键信息。
支持多任务并行下载时独立显示每个任务的进度,一目了然。
速度计算采用平滑算法,避免数据剧烈跳动。
- 💻 两种使用模式,灵活高效 交互式命令行 (CLI):输入 air2 进入专属 Shell,支持命令补全(需 prompt_toolkit)、历史记录、快捷键操作。
单命令直接执行:如 air2 add 可直接添加并开始下载,适合脚本调用或一次性任务。
- 🔧 丰富的功能选项 可自定义线程数、输出目录、分块大小、速度限制、超时时间等。
内置 ZIP 解压功能,下载完成后可一键解压。
任务管理完善:暂停、恢复、取消、移除(可选删除文件)均支持。
- 📦 轻量依赖,易于部署 仅依赖 requests、urllib3、rich 等少量第三方库,安装简单。
支持 Python 3.7+,跨平台运行(Windows / macOS / Linux)。
✨ Key Advantages (English)
- 🚀 Blazing Fast Downloads Intelligent Multi-threaded Chunking: Dynamically adjusts chunk count and size (up to 16 MB per chunk) based on file size to fully saturate network bandwidth.
Large Buffer Optimization: Uses a 1 MB write buffer to minimize disk I/O overhead.
High-Concurrency Connection Pool: Up to 16 connections per task and a 200-worker thread pool dramatically accelerate large file downloads.
- 🛠️ Robust Resume & Error Recovery Seamless resume from interrupted downloads, avoiding redundant data transfer.
Built-in exponential backoff retry mechanism handles transient network issues and server errors gracefully.
File space pre-allocation reduces disk fragmentation and improves write stability.
- 📊 Beautiful, Real-Time Progress Feedback A Rich-powered terminal interface featuring colored progress bars, live speed, ETA, and more.
Multiple concurrent tasks are displayed independently with clear, organized status updates.
Smoothed speed calculation prevents erratic display fluctuations.
- 💻 Dual-Mode Operation for Maximum Flexibility Interactive CLI: Run air2 to enter a dedicated shell with command completion (via prompt_toolkit), history navigation, and keyboard shortcuts.
Single-Command Execution: Use commands like air2 add directly for scripting or one-off tasks.
- 🔧 Extensive Feature Set Fine-grained control over thread count, output directory, chunk size, speed limit, timeout, etc.
Built-in ZIP extraction for immediate unpacking of downloaded archives.
Full task lifecycle management: pause, resume, cancel, and remove (with optional file deletion).
- 📦 Lightweight & Cross-Platform Minimal dependencies (requests, urllib3, rich), easy to install via pip.
Compatible with Python 3.7+ and runs on Windows, macOS, and Linux.
📦 安装 / Installation 基础安装 (Basic) bash pip install requests rich urllib3 推荐安装 (增强体验 / Enhanced Experience) bash pip install prompt_toolkit # 启用命令补全与历史记录 / Enables command completion & history 将 air2.py 放置于 PATH 目录下,或直接运行 python air2.py。
🕹️ 使用方法 / Usage 交互模式 (Interactive Mode) 直接运行程序进入交互式 Shell:
bash python air2.py 然后输入命令进行操作:
text add https://example.com/file.zip --threads=16 start a1b2c3d4 pause a1b2c3d4 resume a1b2c3d4 cancel a1b2c3d4 remove a1b2c3d4 --delete unzip a1b2c3d4 /path/to/extract list status help exit 命令行模式 (Command-Line Mode) 支持单条命令直接执行,无需进入交互界面:
bash
添加并开始下载
python air2.py add https://example.com/file.zip --threads=16 --output=./downloads
开始已有任务
python air2.py start a1b2c3d4
暂停任务
python air2.py pause a1b2c3d4
列出所有任务
python air2.py list
解压已完成的 ZIP 任务
python air2.py unzip a1b2c3d4 ./extracted ⚙️ 添加任务选项 / Task Options 选项 说明 (中文) Description (English) --threads=N 下载线程数 (默认 8) Number of download threads (default 8) --output=DIR 保存目录 (默认当前目录) Output directory (default current dir) --chunk-size=SIZE 分块大小,支持 K/M/G 后缀 (如 10M) Chunk size with optional K/M/G suffix (e.g., 10M) --speed-limit=KB 速度限制 (KB/s),0 表示不限速 Speed limit in KB/s, 0 for unlimited 🗂️ 项目结构 / Project Structure text air2.py # 主程序文件 air2.log # 运行日志 (自动生成) ~/.air2_history # 命令历史记录 (需 prompt_toolkit) 🤝 贡献与反馈 / Contributing 欢迎提交 Issue 和 Pull Request 来改进 Air2。遇到问题或有功能建议,请在 GitHub 仓库中留言。
📄 许可证 / License 本项目采用 MIT License 开源,欢迎自由使用和修改。