pypang 0.1.1__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.
pypang-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 huangzhong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pypang-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,419 @@
1
+ Metadata-Version: 2.4
2
+ Name: pypang
3
+ Version: 0.1.1
4
+ Summary: Baidu Netdisk client with CLI commands and a matching FastAPI Web UI.
5
+ Author: huangzhong
6
+ Maintainer: huangzhong
7
+ License: MIT License
8
+
9
+ Copyright (c) 2026 huangzhong
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: Homepage, https://github.com/HzForelsket/BaiduPanWeb
30
+ Project-URL: Repository, https://github.com/HzForelsket/BaiduPanWeb
31
+ Project-URL: Issues, https://github.com/HzForelsket/BaiduPanWeb/issues
32
+ Keywords: baidu,baidupan,netdisk,fastapi,cli
33
+ Classifier: Development Status :: 3 - Alpha
34
+ Classifier: Environment :: Console
35
+ Classifier: Environment :: Web Environment
36
+ Classifier: Framework :: FastAPI
37
+ Classifier: Intended Audience :: End Users/Desktop
38
+ Classifier: Intended Audience :: System Administrators
39
+ Classifier: License :: OSI Approved :: MIT License
40
+ Classifier: Operating System :: OS Independent
41
+ Classifier: Programming Language :: Python :: 3
42
+ Classifier: Programming Language :: Python :: 3.10
43
+ Classifier: Programming Language :: Python :: 3.11
44
+ Classifier: Programming Language :: Python :: 3.12
45
+ Classifier: Topic :: Internet
46
+ Classifier: Topic :: System :: Archiving
47
+ Classifier: Topic :: Utilities
48
+ Requires-Python: >=3.10
49
+ Description-Content-Type: text/markdown
50
+ License-File: LICENSE
51
+ Requires-Dist: fastapi<1.0,>=0.115
52
+ Requires-Dist: jinja2<4.0,>=3.1
53
+ Requires-Dist: python-multipart<1.0,>=0.0.9
54
+ Requires-Dist: requests<3.0,>=2.32
55
+ Requires-Dist: uvicorn<1.0,>=0.32
56
+ Dynamic: license-file
57
+
58
+ # pypang
59
+
60
+ 基于百度网盘开放平台接口实现,百度网盘命令行客户端,参考了 [bypy](https://github.com/houtianze/bypy) 的使用习惯,并补充了本地 Web UI 与纯 CLI 两套操作方式。
61
+
62
+ 项目目标:
63
+
64
+ - 适配最新百度网盘开放平台接口
65
+ - 默认兼容 `bypy` 的授权配置与应用目录
66
+ - 支持无图形界面的服务器环境
67
+ - 同时提供 Web UI 和 CLI 上传下载能力
68
+
69
+ ## 功能
70
+
71
+ - OAuth 授权,默认使用 `redirect_uri=oob`
72
+ - 兼容 `bypy` 默认应用信息
73
+ - 自动读取根目录 `config.json` 作为自定义配置
74
+ - 支持多配置下分别保存 token
75
+ - Web UI 文件浏览、上传、下载、重命名、移动、删除、建目录
76
+ - CLI 文件浏览、上传、下载、重命名、移动、删除、建目录
77
+ - 支持服务器端口映射后远程访问 Web UI
78
+ - Web UI 传输监控支持 `进行中 / 等待中 / 已完成` 三栏显示
79
+
80
+ ## 默认行为
81
+
82
+ 如果没有 `config.json`:
83
+
84
+ - 默认使用 `bypy` 的应用配置
85
+ - 默认应用目录为 `/apps/bypy`
86
+ - 默认授权方式为 `oob`
87
+ - 默认按无会员档位运行;上传分片默认跟随账号身份自动取最高可用值,CLI/Web 下载并发默认取 `8`
88
+
89
+ 如果存在 `config.json`:
90
+
91
+ - 会自动解析其中的应用配置
92
+ - Web UI 下拉列表中可切换预设
93
+ - 每套配置分别保存自己的 token
94
+
95
+ ## 支持的 `config.json` 格式
96
+
97
+ 多应用格式:
98
+
99
+ ```json
100
+ {
101
+ "default": "myapp",
102
+ "apps": [
103
+ {
104
+ "id": "bypy",
105
+ "label": "bypy",
106
+ "app_key": "q8WE4EpCsau1oS0MplgMKNBn",
107
+ "secret_key": "PA4MhwB5RE7DacKtoP2i8ikCnNzAqYTD",
108
+ "app_name": "bypy",
109
+ "app_root": "/apps/bypy"
110
+ },
111
+ {
112
+ "id": "myapp",
113
+ "label": "我的应用",
114
+ "app_key": "your-app-key",
115
+ "secret_key": "your-secret-key",
116
+ "app_name": "myapp",
117
+ "app_root": "/apps/myapp"
118
+ }
119
+ ]
120
+ }
121
+ ```
122
+
123
+ ## 安装
124
+
125
+ ### 从 PyPI 安装
126
+
127
+ ```powershell
128
+ pip install pypang
129
+ ```
130
+
131
+ 安装后可直接使用:
132
+
133
+ ```powershell
134
+ pypang serve
135
+ ```
136
+
137
+ ### 从源码安装
138
+
139
+ ```powershell
140
+ python -m venv .venv
141
+ .\.venv\Scripts\activate
142
+ python -m pip install --upgrade pip
143
+ python -m pip install -r requirements.txt
144
+ ```
145
+
146
+ ## 首次配置
147
+
148
+ 通过 `pip install pypang` 安装后,不需要修改 `site-packages` 里的文件。
149
+
150
+ 推荐方式是直接使用命令写入本地运行配置:
151
+
152
+ ```powershell
153
+ pypang config set --app-key your-app-key --secret-key your-secret-key --app-name myapp --app-root /apps/myapp --redirect-uri oob
154
+ ```
155
+
156
+ 配置会保存到本地运行状态文件中,默认路径为:
157
+
158
+ ```text
159
+ .runtime/state.json
160
+ ```
161
+
162
+ 如果你更习惯使用 `config.json`,可以在当前运行目录手动放置一个文件,例如:
163
+
164
+ ```json
165
+ {
166
+ "default": "myapp",
167
+ "apps": [
168
+ {
169
+ "id": "myapp",
170
+ "label": "我的应用",
171
+ "app_key": "your-app-key",
172
+ "secret_key": "your-secret-key",
173
+ "app_name": "myapp",
174
+ "app_root": "/apps/myapp"
175
+ }
176
+ ]
177
+ }
178
+ ```
179
+
180
+ 程序会优先读取当前工作目录下的 `config.json`。如果需要指定其他位置,可使用环境变量:
181
+
182
+ ```powershell
183
+ $env:BAIDUPANWEB_LEGACY_CONFIG = "D:\\path\\to\\config.json"
184
+ ```
185
+
186
+ ## CLI 使用
187
+
188
+ ### 1. 查看当前配置
189
+
190
+ ```powershell
191
+ pypang config show
192
+ ```
193
+
194
+ ### 2. 设置配置
195
+
196
+ 默认走 OOB 授权:
197
+
198
+ ```powershell
199
+ pypang config set --app-name bypy --app-root /apps/bypy --redirect-uri oob
200
+ ```
201
+
202
+ 如果只想修改监听地址而不影响 token:
203
+
204
+ ```powershell
205
+ pypang config set --listen-host 0.0.0.0 --listen-port 8080
206
+ ```
207
+
208
+ 如果需要启用会员能力对应的更大分片和更高下载并发,可额外设置:
209
+
210
+ ```powershell
211
+ pypang config set --membership-tier vip --upload-chunk-mb 16 --cli-download-workers 4 --web-download-workers 4
212
+ ```
213
+
214
+ ### 3. 获取授权链接
215
+
216
+ ```powershell
217
+ pypang auth url
218
+ ```
219
+
220
+ 浏览器打开后,百度会回到默认成功页:
221
+
222
+ ```text
223
+ http://openapi.baidu.com/oauth/2.0/login_success
224
+ ```
225
+
226
+ 从页面中复制 `code`,再执行:
227
+
228
+ ```powershell
229
+ pypang auth code <code>
230
+ ```
231
+
232
+ ### 4. 常用 CLI 命令
233
+
234
+ 查看用户信息:
235
+
236
+ ```powershell
237
+ pypang whoami
238
+ ```
239
+
240
+ 查看容量:
241
+
242
+ ```powershell
243
+ pypang quota
244
+ ```
245
+
246
+ 列出目录:
247
+
248
+ ```powershell
249
+ pypang ls /
250
+ ```
251
+
252
+ 创建目录:
253
+
254
+ ```powershell
255
+ pypang mkdir /apps/bypy/docs
256
+ ```
257
+
258
+ 上传文件:
259
+
260
+ ```powershell
261
+ pypang put .\local.txt /apps/bypy/docs/remote.txt
262
+ ```
263
+
264
+ 上传目标既可以是服务器文件,也可以是服务器目录:
265
+
266
+ ```powershell
267
+ pypang put .\local.txt /apps/bypy/docs/
268
+ pypang put .\local.txt /apps/bypy/docs/remote.txt
269
+ ```
270
+
271
+ 下载文件:
272
+
273
+ ```powershell
274
+ pypang get /apps/bypy/docs/remote.txt .\downloads\
275
+ ```
276
+
277
+ 下载命令默认支持断点续传;如果希望强制重新开始,可追加 `--no-resume`。
278
+
279
+ 重命名:
280
+
281
+ ```powershell
282
+ pypang rename /apps/bypy/docs/remote.txt archive.txt
283
+ ```
284
+
285
+ 移动:
286
+
287
+ ```powershell
288
+ pypang mv /apps/bypy/docs/archive.txt /apps/bypy/history
289
+ ```
290
+
291
+ 删除:
292
+
293
+ ```powershell
294
+ pypang rm /apps/bypy/history/archive.txt
295
+ ```
296
+
297
+ 命令别名:
298
+
299
+ - `ls` = `list`
300
+ - `put` = `upload`
301
+ - `get` = `download`
302
+ - `mv` = `move`
303
+ - `rm` = `delete`
304
+ - `whoami` = `info`
305
+
306
+ ## Web UI 使用
307
+
308
+ ### 本机启动
309
+
310
+ ```powershell
311
+ pypang serve
312
+ ```
313
+
314
+ 或指定地址:
315
+
316
+ ```powershell
317
+ pypang serve --host 127.0.0.1 --port 8080
318
+ ```
319
+
320
+ 浏览器访问:
321
+
322
+ ```text
323
+ http://127.0.0.1:8080
324
+ ```
325
+
326
+ ### 无图形界面服务器启动
327
+
328
+ 服务器上可直接对外监听:
329
+
330
+ ```powershell
331
+ pypang config set --listen-host 0.0.0.0 --listen-port 8080
332
+ pypang serve
333
+ ```
334
+
335
+ 然后通过公网 IP、内网穿透、反向代理或 SSH 端口转发访问:
336
+
337
+ ```text
338
+ http://服务器地址:8080
339
+ ```
340
+
341
+ 适合以下场景:
342
+
343
+ - Linux/Windows 无桌面服务器
344
+ - 家庭 NAS
345
+ - 云服务器
346
+ - 通过端口映射远程进入 Web UI 后上传下载文件
347
+
348
+ ### Web UI 授权流程
349
+
350
+ 当前默认使用 `oob`,所以即使服务器没有桌面环境也能工作:
351
+
352
+ 1. 从本地浏览器打开 Web UI
353
+ 2. 点击授权按钮
354
+ 3. 在百度返回页复制 `code`
355
+ 4. 回到 Web UI 手动提交 `code`
356
+ 5. 授权完成后即可在网页中上传、下载和管理文件
357
+
358
+ ## 主要接口适配
359
+
360
+ 上传流程按最新文档实现:
361
+
362
+ ```text
363
+ locateupload -> precreate -> superfile2 -> create
364
+ ```
365
+
366
+ 下载流程按最新文档实现:
367
+
368
+ ```text
369
+ filemetas(dlink=1) -> dlink + access_token + User-Agent
370
+ ```
371
+
372
+ 命令行下载和 Web UI 的“保存到服务器”默认会在本地生成 `.part` 临时文件,并基于 `Range` 请求自动续传未完成部分。
373
+
374
+ 当前下载恢复与校验行为:
375
+
376
+ - 下载任务开始前会先扫描目标目录,检查已有正式文件和 `.part` 文件
377
+ - 如果本地文件大小已满足远端大小,会优先做校验;校验通过则直接复用,不重复下载
378
+ - 如果校验失败,会删除错误文件后重新下载
379
+ - 远端 `md5` 合法时使用 MD5 校验;如果远端未提供合法 `md5`,则退回到大小校验
380
+ - Web UI 的“传输”卡片会显示 `进行中 / 等待中 / 已完成` 三栏;校验阶段会显示为 `校验中`
381
+
382
+ 后端日志默认会输出下载与校验关键阶段,例如:
383
+
384
+ - 下载任务开始
385
+ - 文件开始下载
386
+ - 发现可复用文件并开始校验
387
+ - MD5 校验通过或失败
388
+ - 文件完成或任务失败
389
+
390
+ ## 项目结构
391
+
392
+ ```text
393
+ pypang/
394
+ app.py
395
+ cli.py
396
+ client.py
397
+ config.py
398
+ storage.py
399
+ static/
400
+ templates/
401
+ app.list.json
402
+ config.json
403
+ README.md
404
+ requirements.txt
405
+ ```
406
+
407
+ ## 参考
408
+
409
+ - bypy: https://github.com/houtianze/bypy
410
+ - 百度网盘开放平台文档索引: https://pan.baidu.com/union/doc/nksg0sbfs
411
+ - OAuth 授权码模式: https://pan.baidu.com/union/doc/al0rwqzzl
412
+ - 文件列表: https://pan.baidu.com/union/doc/nksg0sat9
413
+ - 文件信息: https://pan.baidu.com/union/doc/Fksg0sbcm
414
+ - 上传域名: https://pan.baidu.com/union/doc/Mlvw5hfnr
415
+ - 预上传: https://pan.baidu.com/union/doc/3ksg0s9r7
416
+ - 分片上传: https://pan.baidu.com/union/doc/nksg0s9vi
417
+ - 创建文件: https://pan.baidu.com/union/doc/rksg0sa17
418
+ - 下载文件: https://pan.baidu.com/union/doc/pkuo3snyp
419
+ - 管理文件: https://pan.baidu.com/union/doc/mksg0s9l4