hyperdownloader-core 1.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,225 @@
1
+ Metadata-Version: 2.4
2
+ Name: hyperdownloader-core
3
+ Version: 1.0.4
4
+ Summary: 高性能多线程下载引擎 — 完全解耦,不依赖任何 GUI 框架
5
+ Author: HyperDownloader Team
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/cyqmq/hyperDL
8
+ Project-URL: Repository, https://github.com/cyqmq/hyperDL
9
+ Project-URL: Bug Tracker, https://github.com/cyqmq/hyperDL/issues
10
+ Keywords: download,downloader,multi-thread,http,concurrent
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Internet :: WWW/HTTP
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: requests>=2.28.0
23
+ Provides-Extra: socks
24
+ Requires-Dist: PySocks>=1.7.1; extra == "socks"
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=7.0; extra == "dev"
27
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
28
+
29
+ # HyperDownloader Core
30
+
31
+ > **高性能多线程下载引擎** — 完全解耦,不依赖任何 GUI 框架。
32
+
33
+ ## 设计目标
34
+
35
+ `HyperDownloader Core` 是一个纯 Python 的多线程下载引擎,核心设计哲学是**完全解耦**:
36
+
37
+ - ✅ **零 GUI 依赖** — 核心库不含任何 GUI 代码,只通过回调传递纯数据
38
+ - ✅ **可插拔集成** — 任何 GUI 框架(Tkinter、PyQt、WxPython、Web 等)均可通过 `ProgressCallback` 驱动
39
+ - ✅ **面向接口** — 所有 UI 交互通过 `DownloadProgress` 数据类和回调函数实现
40
+ - ✅ **开箱即用** — `DownloadProgress` 已包含进度百分比、速度、ETA、分片状态等所有 UI 所需字段
41
+
42
+ ## 架构概览
43
+
44
+ ```
45
+ ┌─────────────────────────────────────────────────┐
46
+ │ HyperDownloader (Facade) │
47
+ │ 核心引擎入口,用户直接交互 │
48
+ ├─────────────────────────────────────────────────┤
49
+ │ DownloadScheduler │
50
+ │ 任务调度器(并发控制 / 排队 / 策略) │
51
+ ├────────────────────┬────────────────────────────┤
52
+ │ TaskDownloader │ TaskDownloader │
53
+ │ (单任务下载器) │ (单任务下载器) │
54
+ ├────────┬──────────┼────────┬───────────────────┤
55
+ │ Seg-0 │ Seg-1 │ Seg-0 │ Seg-1 │ Seg-2 │
56
+ │ (线程) │ (线程) │ (线程) │ (线程) │ (线程) │
57
+ └────────┴──────────┴────────┴───────────────────┘
58
+ ↑ 回调传纯数据,不依赖任何 GUI
59
+ ┌──────────────────────────────────┐
60
+ │ 任何 GUI / CLI / 其他项目 │
61
+ └──────────────────────────────────┘
62
+ ```
63
+
64
+ ## 快速开始
65
+
66
+ ### 安装
67
+
68
+ ```bash
69
+ pip install hyperdownloader-core
70
+ ```
71
+
72
+ 或直接使用源码:
73
+
74
+ ```bash
75
+ git clone https://github.com/cyqmq/hyperDL.git
76
+ cd hyperDL
77
+ pip install -r requirements.txt
78
+ ```
79
+
80
+ ### 基础用法
81
+
82
+ ```python
83
+ from hyperdownloader import HyperDownloader, DownloadTask
84
+
85
+ # 1. 创建引擎
86
+ dl = HyperDownloader(max_concurrent=5)
87
+
88
+ # 2. 定义进度回调(纯控制台输出,可替换为任何 UI 更新)
89
+ def on_progress(progress):
90
+ print(f"\r{progress.progress:.1f}% - {progress.speed/1024:.1f} KB/s", end="")
91
+
92
+ # 3. 创建下载任务
93
+ task = DownloadTask(
94
+ url="https://example.com/large-file.zip",
95
+ save_dir="./downloads",
96
+ on_progress=on_progress,
97
+ )
98
+
99
+ # 4. 开始下载
100
+ task_id = dl.download(task)
101
+
102
+ # 5. 等待完成
103
+ dl.wait_all()
104
+ dl.stop()
105
+ ```
106
+
107
+ ### 集成到 GUI 项目(示例:Tkinter)
108
+
109
+ ```python
110
+ # 完全相同的 API,只是把回调接入 Tkinter
111
+ def on_progress(progress):
112
+ # progress 是纯数据对象,可驱动任何 UI
113
+ progress_bar["value"] = progress.progress
114
+ speed_label.config(text=f"{progress.speed/1024:.1f} KB/s")
115
+ status_label.config(text=progress.status.name)
116
+
117
+ task = DownloadTask(url="...", save_dir="...", on_progress=on_progress)
118
+ ```
119
+
120
+ ## 核心特性
121
+
122
+ | 特性 | 说明 |
123
+ |------|------|
124
+ | 🚀 **多线程分片下载** | 支持 HTTP Range 请求,文件自动切分并发下载 |
125
+ | ⏸️ **暂停 / 恢复** | 支持断点续传,临时文件可自动恢复 |
126
+ | 🔄 **自动重试** | 指数退避重试策略,可配置重试次数 |
127
+ | 📊 **速度限制** | 全局速率限制(令牌桶算法) |
128
+ | 📋 **任务调度** | FIFO / LIFO / 优先级 三种策略 |
129
+ | 🔌 **完全解耦** | 纯数据回调,不依赖任何 GUI 框架 |
130
+ | 🌐 **代理支持** | HTTP / HTTPS / SOCKS5 |
131
+ | 🧪 **可测试** | 完整单元测试覆盖 |
132
+
133
+ ## 深入使用
134
+
135
+ ### 配置项
136
+
137
+ ```python
138
+ from hyperdownloader import DownloadConfig, Headers, ProxyConfig
139
+
140
+ config = DownloadConfig(
141
+ max_segments=8, # 最大分片数(线程数)
142
+ max_retries=5, # 最大重试次数
143
+ retry_delay=1.0, # 重试基秒(指数退避)
144
+ timeout=60.0, # 超时时间
145
+ speed_limit=500_000, # 限速 500 KB/s
146
+ resume=True, # 启用断点续传
147
+ headers=Headers(
148
+ user_agent="MyApp/1.0",
149
+ referer="https://example.com",
150
+ ),
151
+ proxy=ProxyConfig(
152
+ http="http://127.0.0.1:8080",
153
+ https="http://127.0.0.1:8080",
154
+ ),
155
+ )
156
+ ```
157
+
158
+ ### 调度策略
159
+
160
+ ```python
161
+ from hyperdownloader import HyperDownloader, SchedulerPolicy
162
+
163
+ # FIFO(先进先出,默认)
164
+ dl = HyperDownloader(policy=SchedulerPolicy.FIFO)
165
+
166
+ # LIFO(后进先出)
167
+ dl = HyperDownloader(policy=SchedulerPolicy.LIFO)
168
+
169
+ # 按优先级(高优先级任务先下载)
170
+ dl = HyperDownloader(policy=SchedulerPolicy.PRIORITY)
171
+
172
+ # 带优先级的任务
173
+ from hyperdownloader import DownloadTask
174
+ urgent = DownloadTask(url="...", save_dir="...", priority=10)
175
+ normal = DownloadTask(url="...", save_dir="...", priority=0)
176
+ ```
177
+
178
+ ### 任务管理
179
+
180
+ ```python
181
+ # 暂停
182
+ dl.pause(task_id)
183
+
184
+ # 恢复
185
+ dl.resume(task_id)
186
+
187
+ # 取消
188
+ dl.cancel(task_id)
189
+
190
+ # 查询状态
191
+ active = dl.active_tasks # list[DownloadTask]
192
+ pending = dl.pending_tasks # list[DownloadTask]
193
+ results = dl.completed_results # list[DownloadResult]
194
+ ```
195
+
196
+ ## 项目结构
197
+
198
+ ```
199
+ hyperdownloader-core/
200
+ ├── hyperdownloader/ # 核心库
201
+ │ ├── __init__.py # 包入口,导出公开 API
202
+ │ ├── enums.py # 枚举定义
203
+ │ ├── models.py # 数据模型(纯 dataclass)
204
+ │ ├── utils.py # 工具函数
205
+ │ ├── segment.py # 分片下载器
206
+ │ ├── downloader.py # 单任务下载器
207
+ │ ├── scheduler.py # 任务调度器
208
+ │ └── core.py # 引擎 Facade
209
+ ├── examples/ # 使用示例
210
+ │ ├── simple_download.py # 单文件下载
211
+ │ └── batch_download.py # 批量下载 + 暂停/恢复
212
+ ├── tests/ # 单元测试
213
+ ├── pyproject.toml # 项目配置
214
+ └── README.md
215
+ ```
216
+
217
+ ## 运行测试
218
+
219
+ ```bash
220
+ pytest tests/ -v
221
+ ```
222
+
223
+ ## 许可证
224
+
225
+ MIT
@@ -0,0 +1,197 @@
1
+ # HyperDownloader Core
2
+
3
+ > **高性能多线程下载引擎** — 完全解耦,不依赖任何 GUI 框架。
4
+
5
+ ## 设计目标
6
+
7
+ `HyperDownloader Core` 是一个纯 Python 的多线程下载引擎,核心设计哲学是**完全解耦**:
8
+
9
+ - ✅ **零 GUI 依赖** — 核心库不含任何 GUI 代码,只通过回调传递纯数据
10
+ - ✅ **可插拔集成** — 任何 GUI 框架(Tkinter、PyQt、WxPython、Web 等)均可通过 `ProgressCallback` 驱动
11
+ - ✅ **面向接口** — 所有 UI 交互通过 `DownloadProgress` 数据类和回调函数实现
12
+ - ✅ **开箱即用** — `DownloadProgress` 已包含进度百分比、速度、ETA、分片状态等所有 UI 所需字段
13
+
14
+ ## 架构概览
15
+
16
+ ```
17
+ ┌─────────────────────────────────────────────────┐
18
+ │ HyperDownloader (Facade) │
19
+ │ 核心引擎入口,用户直接交互 │
20
+ ├─────────────────────────────────────────────────┤
21
+ │ DownloadScheduler │
22
+ │ 任务调度器(并发控制 / 排队 / 策略) │
23
+ ├────────────────────┬────────────────────────────┤
24
+ │ TaskDownloader │ TaskDownloader │
25
+ │ (单任务下载器) │ (单任务下载器) │
26
+ ├────────┬──────────┼────────┬───────────────────┤
27
+ │ Seg-0 │ Seg-1 │ Seg-0 │ Seg-1 │ Seg-2 │
28
+ │ (线程) │ (线程) │ (线程) │ (线程) │ (线程) │
29
+ └────────┴──────────┴────────┴───────────────────┘
30
+ ↑ 回调传纯数据,不依赖任何 GUI
31
+ ┌──────────────────────────────────┐
32
+ │ 任何 GUI / CLI / 其他项目 │
33
+ └──────────────────────────────────┘
34
+ ```
35
+
36
+ ## 快速开始
37
+
38
+ ### 安装
39
+
40
+ ```bash
41
+ pip install hyperdownloader-core
42
+ ```
43
+
44
+ 或直接使用源码:
45
+
46
+ ```bash
47
+ git clone https://github.com/cyqmq/hyperDL.git
48
+ cd hyperDL
49
+ pip install -r requirements.txt
50
+ ```
51
+
52
+ ### 基础用法
53
+
54
+ ```python
55
+ from hyperdownloader import HyperDownloader, DownloadTask
56
+
57
+ # 1. 创建引擎
58
+ dl = HyperDownloader(max_concurrent=5)
59
+
60
+ # 2. 定义进度回调(纯控制台输出,可替换为任何 UI 更新)
61
+ def on_progress(progress):
62
+ print(f"\r{progress.progress:.1f}% - {progress.speed/1024:.1f} KB/s", end="")
63
+
64
+ # 3. 创建下载任务
65
+ task = DownloadTask(
66
+ url="https://example.com/large-file.zip",
67
+ save_dir="./downloads",
68
+ on_progress=on_progress,
69
+ )
70
+
71
+ # 4. 开始下载
72
+ task_id = dl.download(task)
73
+
74
+ # 5. 等待完成
75
+ dl.wait_all()
76
+ dl.stop()
77
+ ```
78
+
79
+ ### 集成到 GUI 项目(示例:Tkinter)
80
+
81
+ ```python
82
+ # 完全相同的 API,只是把回调接入 Tkinter
83
+ def on_progress(progress):
84
+ # progress 是纯数据对象,可驱动任何 UI
85
+ progress_bar["value"] = progress.progress
86
+ speed_label.config(text=f"{progress.speed/1024:.1f} KB/s")
87
+ status_label.config(text=progress.status.name)
88
+
89
+ task = DownloadTask(url="...", save_dir="...", on_progress=on_progress)
90
+ ```
91
+
92
+ ## 核心特性
93
+
94
+ | 特性 | 说明 |
95
+ |------|------|
96
+ | 🚀 **多线程分片下载** | 支持 HTTP Range 请求,文件自动切分并发下载 |
97
+ | ⏸️ **暂停 / 恢复** | 支持断点续传,临时文件可自动恢复 |
98
+ | 🔄 **自动重试** | 指数退避重试策略,可配置重试次数 |
99
+ | 📊 **速度限制** | 全局速率限制(令牌桶算法) |
100
+ | 📋 **任务调度** | FIFO / LIFO / 优先级 三种策略 |
101
+ | 🔌 **完全解耦** | 纯数据回调,不依赖任何 GUI 框架 |
102
+ | 🌐 **代理支持** | HTTP / HTTPS / SOCKS5 |
103
+ | 🧪 **可测试** | 完整单元测试覆盖 |
104
+
105
+ ## 深入使用
106
+
107
+ ### 配置项
108
+
109
+ ```python
110
+ from hyperdownloader import DownloadConfig, Headers, ProxyConfig
111
+
112
+ config = DownloadConfig(
113
+ max_segments=8, # 最大分片数(线程数)
114
+ max_retries=5, # 最大重试次数
115
+ retry_delay=1.0, # 重试基秒(指数退避)
116
+ timeout=60.0, # 超时时间
117
+ speed_limit=500_000, # 限速 500 KB/s
118
+ resume=True, # 启用断点续传
119
+ headers=Headers(
120
+ user_agent="MyApp/1.0",
121
+ referer="https://example.com",
122
+ ),
123
+ proxy=ProxyConfig(
124
+ http="http://127.0.0.1:8080",
125
+ https="http://127.0.0.1:8080",
126
+ ),
127
+ )
128
+ ```
129
+
130
+ ### 调度策略
131
+
132
+ ```python
133
+ from hyperdownloader import HyperDownloader, SchedulerPolicy
134
+
135
+ # FIFO(先进先出,默认)
136
+ dl = HyperDownloader(policy=SchedulerPolicy.FIFO)
137
+
138
+ # LIFO(后进先出)
139
+ dl = HyperDownloader(policy=SchedulerPolicy.LIFO)
140
+
141
+ # 按优先级(高优先级任务先下载)
142
+ dl = HyperDownloader(policy=SchedulerPolicy.PRIORITY)
143
+
144
+ # 带优先级的任务
145
+ from hyperdownloader import DownloadTask
146
+ urgent = DownloadTask(url="...", save_dir="...", priority=10)
147
+ normal = DownloadTask(url="...", save_dir="...", priority=0)
148
+ ```
149
+
150
+ ### 任务管理
151
+
152
+ ```python
153
+ # 暂停
154
+ dl.pause(task_id)
155
+
156
+ # 恢复
157
+ dl.resume(task_id)
158
+
159
+ # 取消
160
+ dl.cancel(task_id)
161
+
162
+ # 查询状态
163
+ active = dl.active_tasks # list[DownloadTask]
164
+ pending = dl.pending_tasks # list[DownloadTask]
165
+ results = dl.completed_results # list[DownloadResult]
166
+ ```
167
+
168
+ ## 项目结构
169
+
170
+ ```
171
+ hyperdownloader-core/
172
+ ├── hyperdownloader/ # 核心库
173
+ │ ├── __init__.py # 包入口,导出公开 API
174
+ │ ├── enums.py # 枚举定义
175
+ │ ├── models.py # 数据模型(纯 dataclass)
176
+ │ ├── utils.py # 工具函数
177
+ │ ├── segment.py # 分片下载器
178
+ │ ├── downloader.py # 单任务下载器
179
+ │ ├── scheduler.py # 任务调度器
180
+ │ └── core.py # 引擎 Facade
181
+ ├── examples/ # 使用示例
182
+ │ ├── simple_download.py # 单文件下载
183
+ │ └── batch_download.py # 批量下载 + 暂停/恢复
184
+ ├── tests/ # 单元测试
185
+ ├── pyproject.toml # 项目配置
186
+ └── README.md
187
+ ```
188
+
189
+ ## 运行测试
190
+
191
+ ```bash
192
+ pytest tests/ -v
193
+ ```
194
+
195
+ ## 许可证
196
+
197
+ MIT
@@ -0,0 +1,47 @@
1
+ """
2
+ HyperDownloader Core — 高性能多线程下载引擎
3
+ =============================================
4
+ 完全解耦,不依赖任何 GUI 框架,可无缝集成到其他 Python 项目中。
5
+ """
6
+
7
+ from .enums import DownloadStatus, SegmentStatus, SchedulerPolicy
8
+ from .models import (
9
+ DownloadTask,
10
+ DownloadConfig,
11
+ DownloadProgress,
12
+ DownloadSegment,
13
+ DownloadResult,
14
+ ProxyConfig,
15
+ Headers,
16
+ )
17
+ from .utils import format_bytes, format_speed, format_time, get_downloads_folder
18
+ from .core import HyperDownloader
19
+ from .config_manager import AppConfig, load_config, save_config
20
+
21
+ __all__ = [
22
+ # 枚举
23
+ "DownloadStatus",
24
+ "SegmentStatus",
25
+ "SchedulerPolicy",
26
+ # 数据模型
27
+ "DownloadTask",
28
+ "DownloadConfig",
29
+ "DownloadProgress",
30
+ "DownloadSegment",
31
+ "DownloadResult",
32
+ "ProxyConfig",
33
+ "Headers",
34
+ # 核心入口
35
+ "HyperDownloader",
36
+ # 配置管理
37
+ "AppConfig",
38
+ "load_config",
39
+ "save_config",
40
+ # 工具
41
+ "get_downloads_folder",
42
+ "format_bytes",
43
+ "format_speed",
44
+ "format_time",
45
+ ]
46
+
47
+ __version__ = "1.0.4"