bili-auto 0.1.0__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,27 @@
1
+ # Redis 连接
2
+ REDIS_HOST=localhost
3
+ REDIS_PORT=6379
4
+ REDIS_DB=0
5
+
6
+ # Redis Key 配置
7
+ REDIS_KEY=bili:downloaded
8
+ COOKIE_REDIS_KEY=bili:auth:cookie
9
+ LOGIN_REDIS_PREFIX=bili:login:
10
+ VIDEO_REDIS_PREFIX=bili:video:
11
+ SCAN_FAV_LOCK_KEY=bili:scan_fav:lock
12
+ DOWNLOAD_LOCK_KEY=bili:download:lock
13
+
14
+ # 扫描收藏夹参数
15
+ SCAN_FAV_LOCK_TTL_SECONDS=30
16
+
17
+ # 登录参数
18
+ LOGIN_POLL_INTERVAL_SECONDS=10
19
+ LOGIN_MAX_POLLS=5
20
+ LOGIN_KEY_TTL_SECONDS=600
21
+
22
+ # 下载参数
23
+ DOWNLOAD_DIR=./downloads
24
+ DOWNLOAD_LOCK_TTL_SECONDS=7200
25
+ VIDEO_DONE_TTL_SECONDS=10800
26
+ MAX_DOWNLOADS_PER_RUN=10
27
+ DOWNLOAD_INTERVAL_SECONDS=3
bili_auto-0.1.0/.git ADDED
@@ -0,0 +1 @@
1
+ gitdir: ../.git/modules/bili-auto
@@ -0,0 +1,143 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
98
+ __pypackages__/
99
+
100
+ # Celery stuff
101
+ celerybeat-schedule
102
+ celerybeat.pid
103
+
104
+ # SageMath parsed files
105
+ *.sage.py
106
+
107
+ # Environments
108
+ .env
109
+ .venv
110
+ env/
111
+ venv/
112
+ ENV/
113
+ env.bak/
114
+ venv.bak/
115
+
116
+ # Spyder project settings
117
+ .spyderproject
118
+ .spyproject
119
+
120
+ # Rope project settings
121
+ .ropeproject
122
+
123
+ # mkdocs documentation
124
+ /site
125
+
126
+ # mypy
127
+ .mypy_cache/
128
+ .dmypy.json
129
+ dmypy.json
130
+
131
+ # Pyre type checker
132
+ .pyre/
133
+
134
+ # pytype static type analyzer
135
+ .pytype/
136
+
137
+ # Cython debug symbols
138
+ cython_debug/
139
+
140
+ # uv
141
+ __uv/
142
+ .python-version
143
+ uv.lock
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 colin
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.
@@ -0,0 +1,182 @@
1
+ Metadata-Version: 2.4
2
+ Name: bili-auto
3
+ Version: 0.1.0
4
+ Summary: Bilibili auto-download service: QR login, favorites scanning, async download with Redis queue
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Keywords: async,bilibili,download,fastapi
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: End Users/Desktop
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Topic :: Multimedia :: Video
14
+ Requires-Python: >=3.12
15
+ Requires-Dist: fastapi>=0.136.1
16
+ Requires-Dist: httpx>=0.28.1
17
+ Requires-Dist: pillow>=12.2.0
18
+ Requires-Dist: python-dotenv>=1.2.2
19
+ Requires-Dist: qrcode>=8.2
20
+ Requires-Dist: redis>=7.4.0
21
+ Requires-Dist: tqdm>=4.67.3
22
+ Requires-Dist: uvicorn>=0.46.0
23
+ Description-Content-Type: text/markdown
24
+
25
+ # bili-auto
26
+
27
+ 自动扫描 B 站收藏夹、将新视频入队,并以最高画质下载合并为 MP4 的异步工具。
28
+
29
+ > **免责声明**
30
+ >
31
+ > 本项目仅供个人学习与技术研究使用,请勿用于任何商业或违法用途。
32
+ >
33
+ > - 下载的视频版权归原作者及 B 站平台所有,请在 24 小时内删除,勿二次传播
34
+ > - 使用本工具须遵守 [哔哩哔哩用户协议](https://www.bilibili.com/blackboard/protocal.html) 及相关法律法规
35
+ > - 因使用本工具导致的账号封禁、法律责任等一切后果由使用者自行承担,与作者无关
36
+
37
+ ## 功能
38
+
39
+ - **扫码登录**:浏览器打开页面即可扫码,Cookie 存入 Redis,无需本地文件
40
+ - **收藏夹扫描**:调用 `/scan_fav` 接口自动扫描所有(或指定)收藏夹,增量入队新视频
41
+ - **最高画质下载**:DASH 流优先选最高分辨率 + 最高码率,支持 4K
42
+ - **音视频合并**:ffmpeg 合并后自动删除临时 m4s 文件
43
+ - **目录结构**:`下载目录/作者名/标题.mp4`
44
+ - **Redis 状态追踪**:每个视频有独立 hash 记录下载状态(ready / downloading / done / failed),完成后 3 小时自动过期
45
+ - **下载限流**:每次最多处理 10 个视频,每个间隔 3 秒,防止封禁
46
+ - **并发保护**:扫描锁 + 下载锁,防止重复执行
47
+ - **日志**:终端 + 文件双输出(`logs/bili_auto.log`、`logs/downloader.log`)
48
+
49
+ ## 依赖
50
+
51
+ - Python 3.12+
52
+ - Redis
53
+ - ffmpeg(需在系统 PATH 中)
54
+
55
+ ## 安装
56
+
57
+ **从 PyPI 安装(推荐):**
58
+
59
+ ```bash
60
+ pip install bili-auto
61
+ # 或
62
+ uv add bili-auto
63
+ ```
64
+
65
+ ## 配置
66
+
67
+ 复制示例文件并按需修改:
68
+
69
+ ```bash
70
+ cp .env.example .env
71
+ ```
72
+
73
+ | 变量 | 默认值 | 说明 |
74
+ |---|---|---|
75
+ | `REDIS_HOST` | `localhost` | Redis 主机 |
76
+ | `REDIS_PORT` | `6379` | Redis 端口 |
77
+ | `REDIS_DB` | `0` | Redis 数据库编号 |
78
+ | `DOWNLOAD_DIR` | `./downloads` | 视频保存根目录 |
79
+ | `MAX_DOWNLOADS_PER_RUN` | `10` | 每次 downloader 最多下载数 |
80
+ | `DOWNLOAD_INTERVAL_SECONDS` | `3` | 视频下载间隔(秒) |
81
+ | `VIDEO_DONE_TTL_SECONDS` | `10800` | done 状态 hash 过期时间(秒) |
82
+ | `LOGIN_MAX_POLLS` | `5` | 登录轮询最大次数 |
83
+ | `LOGIN_POLL_INTERVAL_SECONDS` | `10` | 登录轮询间隔(秒) |
84
+
85
+ ## 使用
86
+
87
+ ### 1. 启动 API 服务
88
+
89
+ ```bash
90
+ bili-auto
91
+ # 或(开发模式)
92
+ uvicorn bili_auto.api:app --host 0.0.0.0 --port 8000
93
+ ```
94
+
95
+ ### 2. 扫码登录
96
+
97
+ 浏览器打开 `http://localhost:8000/login_qrcode`,用 B 站 App 扫码,Cookie 自动写入 Redis。
98
+
99
+ ### 3. 扫描收藏夹
100
+
101
+ ```bash
102
+ # 扫描全部收藏夹
103
+ curl http://localhost:8000/scan_fav
104
+
105
+ # 扫描指定收藏夹
106
+ curl "http://localhost:8000/scan_fav?folder_name=我的收藏"
107
+ ```
108
+
109
+ ### 4. 执行下载
110
+
111
+ ```bash
112
+ bili-downloader
113
+ ```
114
+
115
+ 每次运行最多下载 `MAX_DOWNLOADS_PER_RUN` 个视频。可配合 cron 定时执行:
116
+
117
+ ```cron
118
+ # 每小时扫描一次收藏夹
119
+ 0 * * * * curl -s http://localhost:8000/scan_fav
120
+
121
+ # 每小时下载一次队列
122
+ 30 * * * * /path/to/.venv/bin/bili-downloader
123
+ ```
124
+
125
+ ### 5. Cookie 保活(可选)
126
+
127
+ ```bash
128
+ curl http://localhost:8000/keep_alive
129
+ ```
130
+
131
+ ### 6. 健康检查
132
+
133
+ ```bash
134
+ curl http://localhost:8000/health
135
+ ```
136
+
137
+ 返回示例:
138
+
139
+ ```json
140
+ {
141
+ "status": "ok",
142
+ "redis": "ok",
143
+ "ffmpeg": "ffmpeg version 7.1 Copyright (c) 2000-2024 the FFmpeg developers",
144
+ "logged_in": true,
145
+ "bilibili_api": "ok"
146
+ }
147
+ ```
148
+
149
+ | 字段 | 说明 |
150
+ |---|---|
151
+ | `status` | 整体状态:`ok` 全部正常,`degraded` 有项异常 |
152
+ | `redis` | Redis 连通性(`ok` 或错误信息) |
153
+ | `ffmpeg` | ffmpeg 版本行(`ok` 状态下)或错误信息 |
154
+ | `logged_in` | 是否已有登录 Cookie |
155
+ | `bilibili_api` | B 站接口是否可达 |
156
+
157
+ ## 项目结构
158
+
159
+ ```
160
+ bili-auto/
161
+ ├── src/
162
+ │ └── bili_auto/
163
+ │ ├── __init__.py
164
+ │ ├── api.py # FastAPI 服务:登录、扫描、Cookie 管理
165
+ │ └── downloader.py # 独立下载脚本:消费 Redis 队列
166
+ ├── .env # 本地配置(不提交)
167
+ ├── .env.example # 配置示例
168
+ ├── pyproject.toml
169
+ ├── logs/ # 日志目录(自动创建)
170
+ └── downloads/ # 视频下载目录(自动创建)
171
+ ```
172
+
173
+ ## Redis 数据结构
174
+
175
+ | Key | 类型 | 说明 |
176
+ |---|---|---|
177
+ | `bili:downloaded` | Set | 已完成下载的 BV 号 |
178
+ | `bili:auth:cookie` | String | 当前登录 Cookie |
179
+ | `bili:video:{bvid}` | Hash | 单视频状态(download: ready/downloading/done/failed) |
180
+ | `bili:login:{key}` | Hash | 二维码登录状态,10 分钟过期 |
181
+ | `bili:scan_fav:lock` | String | 扫描锁 |
182
+ | `bili:download:lock` | String | 下载锁 |
@@ -0,0 +1,158 @@
1
+ # bili-auto
2
+
3
+ 自动扫描 B 站收藏夹、将新视频入队,并以最高画质下载合并为 MP4 的异步工具。
4
+
5
+ > **免责声明**
6
+ >
7
+ > 本项目仅供个人学习与技术研究使用,请勿用于任何商业或违法用途。
8
+ >
9
+ > - 下载的视频版权归原作者及 B 站平台所有,请在 24 小时内删除,勿二次传播
10
+ > - 使用本工具须遵守 [哔哩哔哩用户协议](https://www.bilibili.com/blackboard/protocal.html) 及相关法律法规
11
+ > - 因使用本工具导致的账号封禁、法律责任等一切后果由使用者自行承担,与作者无关
12
+
13
+ ## 功能
14
+
15
+ - **扫码登录**:浏览器打开页面即可扫码,Cookie 存入 Redis,无需本地文件
16
+ - **收藏夹扫描**:调用 `/scan_fav` 接口自动扫描所有(或指定)收藏夹,增量入队新视频
17
+ - **最高画质下载**:DASH 流优先选最高分辨率 + 最高码率,支持 4K
18
+ - **音视频合并**:ffmpeg 合并后自动删除临时 m4s 文件
19
+ - **目录结构**:`下载目录/作者名/标题.mp4`
20
+ - **Redis 状态追踪**:每个视频有独立 hash 记录下载状态(ready / downloading / done / failed),完成后 3 小时自动过期
21
+ - **下载限流**:每次最多处理 10 个视频,每个间隔 3 秒,防止封禁
22
+ - **并发保护**:扫描锁 + 下载锁,防止重复执行
23
+ - **日志**:终端 + 文件双输出(`logs/bili_auto.log`、`logs/downloader.log`)
24
+
25
+ ## 依赖
26
+
27
+ - Python 3.12+
28
+ - Redis
29
+ - ffmpeg(需在系统 PATH 中)
30
+
31
+ ## 安装
32
+
33
+ **从 PyPI 安装(推荐):**
34
+
35
+ ```bash
36
+ pip install bili-auto
37
+ # 或
38
+ uv add bili-auto
39
+ ```
40
+
41
+ ## 配置
42
+
43
+ 复制示例文件并按需修改:
44
+
45
+ ```bash
46
+ cp .env.example .env
47
+ ```
48
+
49
+ | 变量 | 默认值 | 说明 |
50
+ |---|---|---|
51
+ | `REDIS_HOST` | `localhost` | Redis 主机 |
52
+ | `REDIS_PORT` | `6379` | Redis 端口 |
53
+ | `REDIS_DB` | `0` | Redis 数据库编号 |
54
+ | `DOWNLOAD_DIR` | `./downloads` | 视频保存根目录 |
55
+ | `MAX_DOWNLOADS_PER_RUN` | `10` | 每次 downloader 最多下载数 |
56
+ | `DOWNLOAD_INTERVAL_SECONDS` | `3` | 视频下载间隔(秒) |
57
+ | `VIDEO_DONE_TTL_SECONDS` | `10800` | done 状态 hash 过期时间(秒) |
58
+ | `LOGIN_MAX_POLLS` | `5` | 登录轮询最大次数 |
59
+ | `LOGIN_POLL_INTERVAL_SECONDS` | `10` | 登录轮询间隔(秒) |
60
+
61
+ ## 使用
62
+
63
+ ### 1. 启动 API 服务
64
+
65
+ ```bash
66
+ bili-auto
67
+ # 或(开发模式)
68
+ uvicorn bili_auto.api:app --host 0.0.0.0 --port 8000
69
+ ```
70
+
71
+ ### 2. 扫码登录
72
+
73
+ 浏览器打开 `http://localhost:8000/login_qrcode`,用 B 站 App 扫码,Cookie 自动写入 Redis。
74
+
75
+ ### 3. 扫描收藏夹
76
+
77
+ ```bash
78
+ # 扫描全部收藏夹
79
+ curl http://localhost:8000/scan_fav
80
+
81
+ # 扫描指定收藏夹
82
+ curl "http://localhost:8000/scan_fav?folder_name=我的收藏"
83
+ ```
84
+
85
+ ### 4. 执行下载
86
+
87
+ ```bash
88
+ bili-downloader
89
+ ```
90
+
91
+ 每次运行最多下载 `MAX_DOWNLOADS_PER_RUN` 个视频。可配合 cron 定时执行:
92
+
93
+ ```cron
94
+ # 每小时扫描一次收藏夹
95
+ 0 * * * * curl -s http://localhost:8000/scan_fav
96
+
97
+ # 每小时下载一次队列
98
+ 30 * * * * /path/to/.venv/bin/bili-downloader
99
+ ```
100
+
101
+ ### 5. Cookie 保活(可选)
102
+
103
+ ```bash
104
+ curl http://localhost:8000/keep_alive
105
+ ```
106
+
107
+ ### 6. 健康检查
108
+
109
+ ```bash
110
+ curl http://localhost:8000/health
111
+ ```
112
+
113
+ 返回示例:
114
+
115
+ ```json
116
+ {
117
+ "status": "ok",
118
+ "redis": "ok",
119
+ "ffmpeg": "ffmpeg version 7.1 Copyright (c) 2000-2024 the FFmpeg developers",
120
+ "logged_in": true,
121
+ "bilibili_api": "ok"
122
+ }
123
+ ```
124
+
125
+ | 字段 | 说明 |
126
+ |---|---|
127
+ | `status` | 整体状态:`ok` 全部正常,`degraded` 有项异常 |
128
+ | `redis` | Redis 连通性(`ok` 或错误信息) |
129
+ | `ffmpeg` | ffmpeg 版本行(`ok` 状态下)或错误信息 |
130
+ | `logged_in` | 是否已有登录 Cookie |
131
+ | `bilibili_api` | B 站接口是否可达 |
132
+
133
+ ## 项目结构
134
+
135
+ ```
136
+ bili-auto/
137
+ ├── src/
138
+ │ └── bili_auto/
139
+ │ ├── __init__.py
140
+ │ ├── api.py # FastAPI 服务:登录、扫描、Cookie 管理
141
+ │ └── downloader.py # 独立下载脚本:消费 Redis 队列
142
+ ├── .env # 本地配置(不提交)
143
+ ├── .env.example # 配置示例
144
+ ├── pyproject.toml
145
+ ├── logs/ # 日志目录(自动创建)
146
+ └── downloads/ # 视频下载目录(自动创建)
147
+ ```
148
+
149
+ ## Redis 数据结构
150
+
151
+ | Key | 类型 | 说明 |
152
+ |---|---|---|
153
+ | `bili:downloaded` | Set | 已完成下载的 BV 号 |
154
+ | `bili:auth:cookie` | String | 当前登录 Cookie |
155
+ | `bili:video:{bvid}` | Hash | 单视频状态(download: ready/downloading/done/failed) |
156
+ | `bili:login:{key}` | Hash | 二维码登录状态,10 分钟过期 |
157
+ | `bili:scan_fav:lock` | String | 扫描锁 |
158
+ | `bili:download:lock` | String | 下载锁 |
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "bili-auto"
7
+ version = "0.1.0"
8
+ description = "Bilibili auto-download service: QR login, favorites scanning, async download with Redis queue"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.12"
12
+ keywords = ["bilibili", "download", "fastapi", "async"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: End Users/Desktop",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Topic :: Multimedia :: Video",
20
+ ]
21
+ dependencies = [
22
+ "fastapi>=0.136.1",
23
+ "httpx>=0.28.1",
24
+ "pillow>=12.2.0",
25
+ "python-dotenv>=1.2.2",
26
+ "qrcode>=8.2",
27
+ "redis>=7.4.0",
28
+ "tqdm>=4.67.3",
29
+ "uvicorn>=0.46.0",
30
+ ]
31
+
32
+ [project.scripts]
33
+ bili-auto = "bili_auto.api:main"
34
+ bili-downloader = "bili_auto.downloader:main"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/bili_auto"]
File without changes