feat: add bilibili upload skill
This commit is contained in:
@@ -1,2 +1,22 @@
|
|||||||
# cd uploader/bilibili_uploader
|
from __future__ import annotations
|
||||||
# biliup.exe -u account.json login
|
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from conf import BASE_DIR
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
cli_path = Path(BASE_DIR) / "sau_cli.py"
|
||||||
|
subprocess.run(
|
||||||
|
[
|
||||||
|
sys.executable,
|
||||||
|
str(cli_path),
|
||||||
|
"bilibili",
|
||||||
|
"login",
|
||||||
|
"--account",
|
||||||
|
"creator",
|
||||||
|
],
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,42 +1,44 @@
|
|||||||
import time
|
import subprocess
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from uploader.bilibili_uploader.main import read_cookie_json_file, extract_keys_from_json, random_emoji, BilibiliUploader
|
|
||||||
from conf import BASE_DIR
|
from conf import BASE_DIR
|
||||||
from utils.constant import VideoZoneTypes
|
from utils.constant import VideoZoneTypes
|
||||||
from utils.files_times import generate_schedule_time_next_day, get_title_and_hashtags
|
from utils.files_times import generate_schedule_time_next_day, get_title_and_hashtags
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
filepath = Path(BASE_DIR) / "videos"
|
filepath = Path(BASE_DIR) / "videos"
|
||||||
# how to get cookie, see the file of get_bilibili_cookie.py.
|
|
||||||
account_file = Path(BASE_DIR / "cookies" / "bilibili_uploader" / "account.json")
|
|
||||||
if not account_file.exists():
|
|
||||||
print(f"{account_file.name} 配置文件不存在")
|
|
||||||
exit()
|
|
||||||
cookie_data = read_cookie_json_file(account_file)
|
|
||||||
cookie_data = extract_keys_from_json(cookie_data)
|
|
||||||
|
|
||||||
tid = VideoZoneTypes.SPORTS_FOOTBALL.value # 设置分区id
|
|
||||||
# 获取视频目录
|
|
||||||
folder_path = Path(filepath)
|
folder_path = Path(filepath)
|
||||||
# 获取文件夹中的所有文件
|
|
||||||
files = list(folder_path.glob("*.mp4"))
|
files = list(folder_path.glob("*.mp4"))
|
||||||
file_num = len(files)
|
file_num = len(files)
|
||||||
timestamps = generate_schedule_time_next_day(file_num, 1, daily_times=[16], timestamps=True)
|
publish_datetimes = generate_schedule_time_next_day(file_num, 1, daily_times=[16])
|
||||||
|
cli_path = Path(BASE_DIR) / "sau_cli.py"
|
||||||
|
|
||||||
for index, file in enumerate(files):
|
for index, file in enumerate(files):
|
||||||
title, tags = get_title_and_hashtags(str(file))
|
title, tags = get_title_and_hashtags(str(file))
|
||||||
# just avoid error, bilibili don't allow same title of video.
|
|
||||||
title += random_emoji()
|
|
||||||
tags_str = ','.join([tag for tag in tags])
|
|
||||||
# 打印视频文件名、标题和 hashtag
|
|
||||||
print(f"视频文件名:{file}")
|
print(f"视频文件名:{file}")
|
||||||
print(f"标题:{title}")
|
print(f"标题:{title}")
|
||||||
print(f"Hashtag:{tags}")
|
print(f"Hashtag:{tags}")
|
||||||
# I set desc same as title, do what u like.
|
|
||||||
desc = title
|
desc = title
|
||||||
bili_uploader = BilibiliUploader(cookie_data, file, title, desc, tid, tags, timestamps[index])
|
schedule_text = publish_datetimes[index].strftime("%Y-%m-%d %H:%M")
|
||||||
bili_uploader.upload()
|
command = [
|
||||||
|
sys.executable,
|
||||||
# life is beautiful don't so rush. be kind be patience
|
str(cli_path),
|
||||||
time.sleep(30)
|
"bilibili",
|
||||||
|
"upload-video",
|
||||||
|
"--account",
|
||||||
|
"creator",
|
||||||
|
"--file",
|
||||||
|
str(file),
|
||||||
|
"--title",
|
||||||
|
title,
|
||||||
|
"--desc",
|
||||||
|
desc,
|
||||||
|
"--tid",
|
||||||
|
str(VideoZoneTypes.SPORTS_FOOTBALL.value),
|
||||||
|
"--tags",
|
||||||
|
",".join(tags),
|
||||||
|
"--schedule",
|
||||||
|
schedule_text,
|
||||||
|
]
|
||||||
|
subprocess.run(command, check=True)
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
---
|
||||||
|
name: bilibili-upload
|
||||||
|
description: 当 agent 需要通过已安装的 `sau` CLI 完成 Bilibili 登录、账号校验或视频上传时使用这个 skill。优先使用 `sau bilibili ...`,程序会自动准备 `biliup`,不要求用户手动安装。
|
||||||
|
---
|
||||||
|
|
||||||
|
# Bilibili 上传 Skill
|
||||||
|
|
||||||
|
优先把 `sau` 作为主接口。
|
||||||
|
|
||||||
|
不要一开始就让用户自己找 `biliup` 或手动下载 release。
|
||||||
|
程序会在运行时自动检查、自动下载、自动更新 `biliup`。
|
||||||
|
|
||||||
|
## 功能概览
|
||||||
|
|
||||||
|
| 功能 | 命令入口 | 说明 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 登录 | `sau bilibili login --account <name>` | 生成或刷新指定账号的登录信息 |
|
||||||
|
| 校验 | `sau bilibili check --account <name>` | 检查指定账号当前是否有效 |
|
||||||
|
| 视频上传 | `sau bilibili upload-video ...` | 上传一条 Bilibili 视频 |
|
||||||
|
|
||||||
|
## 默认工作流
|
||||||
|
|
||||||
|
1. 先确认 `references/runtime-requirements.md`
|
||||||
|
2. 再确认 `references/cli-contract.md`
|
||||||
|
3. 执行匹配的 `sau bilibili ...` 命令
|
||||||
|
4. 如果命令失败,再看 `references/troubleshooting.md`
|
||||||
|
|
||||||
|
## 命令选择建议
|
||||||
|
|
||||||
|
- 用户没有登录信息,先用 `login`
|
||||||
|
- 用户只想确认账号状态,先用 `check`
|
||||||
|
- 用户要发视频,用 `upload-video`
|
||||||
|
|
||||||
|
## 执行前检查
|
||||||
|
|
||||||
|
- 优先确认当前环境能运行 `sau`
|
||||||
|
- 如果 `sau` 不在 PATH 中,可以用仓库里的 `sau_cli.py`
|
||||||
|
- 不要要求用户手动下载 `biliup`
|
||||||
|
- 第一次运行 Bilibili 命令时,程序可能会自动联网准备 `biliup`
|
||||||
|
|
||||||
|
## 模板文件
|
||||||
|
|
||||||
|
- `scripts/examples/bilibili_commands.ps1`
|
||||||
|
- `scripts/examples/bilibili_commands.sh`
|
||||||
|
- `scripts/examples/bilibili_cli_template.py`
|
||||||
|
|
||||||
|
## 参考文档
|
||||||
|
|
||||||
|
- 运行前提:`references/runtime-requirements.md`
|
||||||
|
- CLI 契约:`references/cli-contract.md`
|
||||||
|
- 故障排查:`references/troubleshooting.md`
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# Bilibili CLI 契约
|
||||||
|
|
||||||
|
这个 skill 默认假设当前环境已经安装并可调用 `sau` 命令。
|
||||||
|
|
||||||
|
## 命令列表
|
||||||
|
|
||||||
|
### 登录
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sau bilibili login --account <account>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 必填参数:
|
||||||
|
- `--account`
|
||||||
|
- 作用:
|
||||||
|
- 自动准备 `biliup`
|
||||||
|
- 触发 Bilibili 登录流程
|
||||||
|
|
||||||
|
### 校验账号
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sau bilibili check --account <account>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 必填参数:
|
||||||
|
- `--account`
|
||||||
|
- 预期输出:
|
||||||
|
- `valid`
|
||||||
|
- `invalid`
|
||||||
|
|
||||||
|
### 上传视频
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sau bilibili upload-video \
|
||||||
|
--account <account> \
|
||||||
|
--file <video-path> \
|
||||||
|
--title "<title>" \
|
||||||
|
--desc "<desc>" \
|
||||||
|
--tid <category-id> \
|
||||||
|
[--tags tag1,tag2] \
|
||||||
|
[--schedule "YYYY-MM-DD HH:MM"]
|
||||||
|
```
|
||||||
|
|
||||||
|
- 必填参数:
|
||||||
|
- `--account`
|
||||||
|
- `--file`
|
||||||
|
- `--title`
|
||||||
|
- `--desc`
|
||||||
|
- `--tid`
|
||||||
|
- 可选参数:
|
||||||
|
- `--tags`
|
||||||
|
- `--schedule`
|
||||||
|
|
||||||
|
## 额外说明
|
||||||
|
|
||||||
|
- `--tid` 第一版必须传
|
||||||
|
- `--tags` 使用逗号分隔
|
||||||
|
- `--schedule` 走 `sau` 统一时间格式
|
||||||
|
- 程序会自动准备和更新 `biliup`
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
# 运行前提
|
||||||
|
|
||||||
|
这个 skill 默认假设当前环境已经具备:
|
||||||
|
|
||||||
|
- 已安装 `social-auto-upload`
|
||||||
|
- 可以调用 `sau`,或者至少可以执行 `python sau_cli.py`
|
||||||
|
- 当前机器首次运行时可以联网访问 GitHub Release
|
||||||
|
|
||||||
|
## 关键说明
|
||||||
|
|
||||||
|
用户不需要自己安装 `biliup`。
|
||||||
|
|
||||||
|
当你执行 `sau bilibili ...` 时:
|
||||||
|
|
||||||
|
- 如果本地没有 `biliup`,程序会自动下载
|
||||||
|
- 如果上游 GitHub Release 有更新,程序会自动更新后再继续执行
|
||||||
|
|
||||||
|
## 推荐调用方式
|
||||||
|
|
||||||
|
### `sau` 已在 PATH 中
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sau bilibili --help
|
||||||
|
```
|
||||||
|
|
||||||
|
### 仓库内直接调用
|
||||||
|
|
||||||
|
PowerShell:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\.venv\Scripts\python.exe sau_cli.py bilibili --help
|
||||||
|
```
|
||||||
|
|
||||||
|
bash / zsh:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python sau_cli.py bilibili --help
|
||||||
|
```
|
||||||
|
|
||||||
|
## 首次运行注意事项
|
||||||
|
|
||||||
|
- 首次运行可能比其他平台更慢,因为要自动准备 `biliup`
|
||||||
|
- 如果网络无法访问 GitHub Release,Bilibili 命令会失败
|
||||||
|
- 一旦本地已经准备好 `biliup`,后续命令会直接复用
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
# Bilibili 常见问题
|
||||||
|
|
||||||
|
## 1. 首次运行很慢
|
||||||
|
|
||||||
|
这是正常情况。
|
||||||
|
|
||||||
|
原因通常是程序正在自动下载 `biliup`。
|
||||||
|
|
||||||
|
## 2. 自动下载失败
|
||||||
|
|
||||||
|
先检查:
|
||||||
|
|
||||||
|
- 当前网络是否能访问 GitHub
|
||||||
|
- GitHub Release 是否可访问
|
||||||
|
- 本地目录是否有写权限
|
||||||
|
|
||||||
|
## 3. `check` 返回 `invalid`
|
||||||
|
|
||||||
|
常见原因:
|
||||||
|
|
||||||
|
- 账号文件不存在
|
||||||
|
- 登录信息已失效
|
||||||
|
- `biliup renew` 失败
|
||||||
|
|
||||||
|
建议:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sau bilibili login --account <account>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. 上传失败
|
||||||
|
|
||||||
|
优先检查:
|
||||||
|
|
||||||
|
- `--tid` 是否正确
|
||||||
|
- 视频文件是否真实存在
|
||||||
|
- 标题、简介、标签是否符合平台要求
|
||||||
|
- 当前登录信息是否仍然有效
|
||||||
|
|
||||||
|
## 5. 上游更新后行为变化
|
||||||
|
|
||||||
|
当前 Bilibili 集成会自动跟随上游 `biliup` 最新 release。
|
||||||
|
|
||||||
|
如果上游命令行为变化,可能会影响本项目的 Bilibili CLI。
|
||||||
|
|
||||||
|
排障时请同时确认:
|
||||||
|
|
||||||
|
- 当前下载到的 `biliup` 版本
|
||||||
|
- 上游 release 是否有最近变更
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from conf import BASE_DIR
|
||||||
|
from utils.constant import VideoZoneTypes
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
cli_path = Path(BASE_DIR) / "sau_cli.py"
|
||||||
|
command = [
|
||||||
|
sys.executable,
|
||||||
|
str(cli_path),
|
||||||
|
"bilibili",
|
||||||
|
"upload-video",
|
||||||
|
"--account",
|
||||||
|
"creator",
|
||||||
|
"--file",
|
||||||
|
str(Path(BASE_DIR) / "videos" / "demo.mp4"),
|
||||||
|
"--title",
|
||||||
|
"Bilibili CLI Demo",
|
||||||
|
"--desc",
|
||||||
|
"Bilibili CLI Demo",
|
||||||
|
"--tid",
|
||||||
|
str(VideoZoneTypes.SPORTS_FOOTBALL.value),
|
||||||
|
"--tags",
|
||||||
|
"足球,测试",
|
||||||
|
"--schedule",
|
||||||
|
"2026-03-26 16:00",
|
||||||
|
]
|
||||||
|
subprocess.run(command, check=True)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# 登录
|
||||||
|
sau bilibili login --account creator
|
||||||
|
|
||||||
|
# 校验
|
||||||
|
sau bilibili check --account creator
|
||||||
|
|
||||||
|
# 上传视频
|
||||||
|
sau bilibili upload-video `
|
||||||
|
--account creator `
|
||||||
|
--file .\videos\demo.mp4 `
|
||||||
|
--title "Bilibili CLI Demo" `
|
||||||
|
--desc "Bilibili CLI Demo" `
|
||||||
|
--tid 249 `
|
||||||
|
--tags 足球,测试 `
|
||||||
|
--schedule "2026-03-26 16:00"
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# login
|
||||||
|
sau bilibili login --account creator
|
||||||
|
|
||||||
|
# check
|
||||||
|
sau bilibili check --account creator
|
||||||
|
|
||||||
|
# upload video
|
||||||
|
sau bilibili upload-video \
|
||||||
|
--account creator \
|
||||||
|
--file ./videos/demo.mp4 \
|
||||||
|
--title "Bilibili CLI Demo" \
|
||||||
|
--desc "Bilibili CLI Demo" \
|
||||||
|
--tid 249 \
|
||||||
|
--tags 足球,测试 \
|
||||||
|
--schedule "2026-03-26 16:00"
|
||||||
Reference in New Issue
Block a user