earshot-cli 0.4.0__tar.gz → 0.6.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.
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/PKG-INFO +19 -1
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/README.md +16 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/pyproject.toml +6 -2
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/auth.py +23 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/cli.py +175 -5
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/compose.py +22 -1
- earshot_cli-0.6.0/src/earshot/hardsub.py +379 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/subtitle.py +4 -1
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_compose.py +24 -0
- earshot_cli-0.6.0/tests/test_credential_lifecycle.py +118 -0
- earshot_cli-0.6.0/tests/test_hardsub.py +221 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_wizard.py +16 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/uv.lock +465 -1
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/.github/workflows/ci.yml +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/.github/workflows/publish.yml +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/.gitignore +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/LICENSE +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/scripts/download_models.sh +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/__init__.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/capture.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/config.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/deliver.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/extract.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/live.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/models.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/transcribe.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/src/earshot/transcribe_cloud.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/conftest.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_auth.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_config.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_deliver.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_deliver_api.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_do_deliver.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_extract.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_live.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_me.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_subtitle.py +0 -0
- {earshot_cli-0.4.0 → earshot_cli-0.6.0}/tests/test_ua.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: earshot-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: 旁听剪藏:跨平台桌面端系统声录制 → 本地转写 → 投递知识库(默认 ExoMind,可插拔)
|
|
5
5
|
Project-URL: Homepage, https://github.com/helloworldtang/earshot
|
|
6
6
|
Project-URL: Repository, https://github.com/helloworldtang/earshot
|
|
@@ -29,6 +29,8 @@ Requires-Dist: sherpa-onnx>=1.13.8
|
|
|
29
29
|
Requires-Dist: soundcard>=0.4.3
|
|
30
30
|
Requires-Dist: soxr>=0.5
|
|
31
31
|
Requires-Dist: yt-dlp>=2025.1
|
|
32
|
+
Provides-Extra: ocr
|
|
33
|
+
Requires-Dist: rapidocr>=3.10; extra == 'ocr'
|
|
32
34
|
Description-Content-Type: text/markdown
|
|
33
35
|
|
|
34
36
|
# earshot
|
|
@@ -137,6 +139,14 @@ earshot login # 浏览器打开授权页,点「授权登录」即完成(已
|
|
|
137
139
|
earshot me # 显示凭据状态与服务连通性(「凭据状态:有效」即就绪)
|
|
138
140
|
```
|
|
139
141
|
|
|
142
|
+
凭据生命周期闭环(login → me → update → logout):
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
earshot update --api-key <新key> # 替换 API Key(新 key 从 exomind 管理端复制;缺省交互粘贴)
|
|
146
|
+
earshot logout # 清除本地凭据(保留服务器地址;exomind-cli/fireCut 共用该配置会一并失效)
|
|
147
|
+
earshot help [命令] # 查看帮助(如 earshot help listen)
|
|
148
|
+
```
|
|
149
|
+
|
|
140
150
|
没有 ExoMind 账号?投递可换任意 webhook(`--deliver webhook --webhook <url>`),或 `--deliver none` 只本地存档,两者都不需要登录。
|
|
141
151
|
|
|
142
152
|
`earshot` 与 `earshot-cli` 两个命令名等价可用;`earshot doctor` 可做完整环境自检。
|
|
@@ -156,6 +166,9 @@ uv tool install "earshot-cli @ https://github.com/helloworldtang/earshot/archive
|
|
|
156
166
|
```
|
|
157
167
|
|
|
158
168
|
- **零系统依赖**:ffmpeg 已随 Python wheel 内置([imageio-ffmpeg](https://pypi.org/project/imageio-ffmpeg),MoviePy 同款),无需 brew/apt。
|
|
169
|
+
- **硬字幕 OCR 为可选依赖**(`earshot ocr`,字幕烧在画面里、无音轨的视频用):装主包后补一条
|
|
170
|
+
`uv tool install --force --with "earshot-cli[ocr]" earshot-cli`(或首装就用 `uv tool install "earshot-cli[ocr]"`),
|
|
171
|
+
约多下载 100MB(含 PP-OCR ONNX 模型,复用主依赖 onnxruntime 运行时,不引入 paddlepaddle)。
|
|
159
172
|
- **模型首次运行自动下载**:SenseVoice int8 + silero VAD(~230MB,默认走 hf-mirror,`HF_ENDPOINT` 可覆盖),装完不再下。
|
|
160
173
|
- **投递免装 CLI**:默认直连 ExoMind HTTP API(复用 `~/.exomind/config.json` 凭据);没有凭据但有 exomind CLI 时自动回退;也支持任意 webhook。
|
|
161
174
|
- **独立登录免装 emcli**:`earshot login` 设备流浏览器授权,直接写入 `~/.exomind/config.json`(与 emcli 共用同一凭据文件);已装 emcli 且登录过则无需再登。
|
|
@@ -190,6 +203,11 @@ earshot listen --note "B站·xxx第3期"
|
|
|
190
203
|
# B站等视频链接直拉字幕(高信噪比:无环境噪音/打断;AI 字幕需登录态)
|
|
191
204
|
earshot video "https://www.bilibili.com/video/BVxxxx" --cookies-from-browser chrome
|
|
192
205
|
|
|
206
|
+
# 硬字幕视频 OCR 提取(字幕烧在画面里、无音轨;本地文件或链接均可,链接模式下载完即删不留全片)
|
|
207
|
+
earshot ocr ./录屏.mp4
|
|
208
|
+
earshot ocr "https://www.bilibili.com/video/BVxxxx"
|
|
209
|
+
# 长视频可降采样:--fps 0.5(<1 会漏短字幕);字幕不在底部条带时:--region full
|
|
210
|
+
|
|
193
211
|
# 已有音视频文件(录屏 mp4 / 语音 m4a / 播客 mp3)
|
|
194
212
|
earshot audio recording.mp4 --title "通勤听书笔记" --deliver none
|
|
195
213
|
|
|
@@ -104,6 +104,14 @@ earshot login # 浏览器打开授权页,点「授权登录」即完成(已
|
|
|
104
104
|
earshot me # 显示凭据状态与服务连通性(「凭据状态:有效」即就绪)
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
+
凭据生命周期闭环(login → me → update → logout):
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
earshot update --api-key <新key> # 替换 API Key(新 key 从 exomind 管理端复制;缺省交互粘贴)
|
|
111
|
+
earshot logout # 清除本地凭据(保留服务器地址;exomind-cli/fireCut 共用该配置会一并失效)
|
|
112
|
+
earshot help [命令] # 查看帮助(如 earshot help listen)
|
|
113
|
+
```
|
|
114
|
+
|
|
107
115
|
没有 ExoMind 账号?投递可换任意 webhook(`--deliver webhook --webhook <url>`),或 `--deliver none` 只本地存档,两者都不需要登录。
|
|
108
116
|
|
|
109
117
|
`earshot` 与 `earshot-cli` 两个命令名等价可用;`earshot doctor` 可做完整环境自检。
|
|
@@ -123,6 +131,9 @@ uv tool install "earshot-cli @ https://github.com/helloworldtang/earshot/archive
|
|
|
123
131
|
```
|
|
124
132
|
|
|
125
133
|
- **零系统依赖**:ffmpeg 已随 Python wheel 内置([imageio-ffmpeg](https://pypi.org/project/imageio-ffmpeg),MoviePy 同款),无需 brew/apt。
|
|
134
|
+
- **硬字幕 OCR 为可选依赖**(`earshot ocr`,字幕烧在画面里、无音轨的视频用):装主包后补一条
|
|
135
|
+
`uv tool install --force --with "earshot-cli[ocr]" earshot-cli`(或首装就用 `uv tool install "earshot-cli[ocr]"`),
|
|
136
|
+
约多下载 100MB(含 PP-OCR ONNX 模型,复用主依赖 onnxruntime 运行时,不引入 paddlepaddle)。
|
|
126
137
|
- **模型首次运行自动下载**:SenseVoice int8 + silero VAD(~230MB,默认走 hf-mirror,`HF_ENDPOINT` 可覆盖),装完不再下。
|
|
127
138
|
- **投递免装 CLI**:默认直连 ExoMind HTTP API(复用 `~/.exomind/config.json` 凭据);没有凭据但有 exomind CLI 时自动回退;也支持任意 webhook。
|
|
128
139
|
- **独立登录免装 emcli**:`earshot login` 设备流浏览器授权,直接写入 `~/.exomind/config.json`(与 emcli 共用同一凭据文件);已装 emcli 且登录过则无需再登。
|
|
@@ -157,6 +168,11 @@ earshot listen --note "B站·xxx第3期"
|
|
|
157
168
|
# B站等视频链接直拉字幕(高信噪比:无环境噪音/打断;AI 字幕需登录态)
|
|
158
169
|
earshot video "https://www.bilibili.com/video/BVxxxx" --cookies-from-browser chrome
|
|
159
170
|
|
|
171
|
+
# 硬字幕视频 OCR 提取(字幕烧在画面里、无音轨;本地文件或链接均可,链接模式下载完即删不留全片)
|
|
172
|
+
earshot ocr ./录屏.mp4
|
|
173
|
+
earshot ocr "https://www.bilibili.com/video/BVxxxx"
|
|
174
|
+
# 长视频可降采样:--fps 0.5(<1 会漏短字幕);字幕不在底部条带时:--region full
|
|
175
|
+
|
|
160
176
|
# 已有音视频文件(录屏 mp4 / 语音 m4a / 播客 mp3)
|
|
161
177
|
earshot audio recording.mp4 --title "通勤听书笔记" --deliver none
|
|
162
178
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "earshot-cli"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.6.0"
|
|
4
4
|
description = "旁听剪藏:跨平台桌面端系统声录制 → 本地转写 → 投递知识库(默认 ExoMind,可插拔)"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -36,6 +36,10 @@ dependencies = [
|
|
|
36
36
|
"yt-dlp>=2025.1",
|
|
37
37
|
]
|
|
38
38
|
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
# ocr 命令:硬字幕画面 OCR(PP-OCR ONNX 模型内置,复用主依赖 onnxruntime 运行时,不引 paddlepaddle)
|
|
41
|
+
ocr = ["rapidocr>=3.10"]
|
|
42
|
+
|
|
39
43
|
[project.urls]
|
|
40
44
|
Homepage = "https://github.com/helloworldtang/earshot"
|
|
41
45
|
Repository = "https://github.com/helloworldtang/earshot"
|
|
@@ -73,7 +77,7 @@ strict = true
|
|
|
73
77
|
files = ["src", "tests"]
|
|
74
78
|
# sherpa-onnx / soundcard 未随 wheel 提供 py.typed —— 与其假装,不如显式忽略
|
|
75
79
|
[[tool.mypy.overrides]]
|
|
76
|
-
module = ["sherpa_onnx.*", "soundcard.*", "onnxruntime.*", "imageio_ffmpeg.*", "soxr.*", "yt_dlp.*"]
|
|
80
|
+
module = ["sherpa_onnx.*", "soundcard.*", "onnxruntime.*", "imageio_ffmpeg.*", "soxr.*", "yt_dlp.*", "rapidocr.*"]
|
|
77
81
|
ignore_missing_imports = true
|
|
78
82
|
|
|
79
83
|
[[tool.mypy.overrides]]
|
|
@@ -148,3 +148,26 @@ def save_credentials(
|
|
|
148
148
|
path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
149
149
|
path.chmod(0o600)
|
|
150
150
|
return path
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def clear_credentials(config_path: Path | None = None) -> Path | None:
|
|
154
|
+
"""清除配置里的 api_key(置空,保留 base_url 等其他字段)——登出只清本地。
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
config_path: 配置文件路径,测试注入;缺省 ``~/.exomind/config.json``。
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
实际写入的配置文件路径;文件不存在或本就没有凭据时返回 None(无事可做)。
|
|
161
|
+
"""
|
|
162
|
+
path = config_path if config_path is not None else Path.home() / EXOMIND_CONFIG_FILENAME
|
|
163
|
+
try:
|
|
164
|
+
raw = json.loads(path.read_text(encoding="utf-8"))
|
|
165
|
+
except (OSError, ValueError):
|
|
166
|
+
return None
|
|
167
|
+
if not isinstance(raw, dict) or not raw.get("api_key"):
|
|
168
|
+
return None
|
|
169
|
+
data = {k: v for k, v in raw.items() if isinstance(v, str)}
|
|
170
|
+
data["api_key"] = ""
|
|
171
|
+
path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
172
|
+
path.chmod(0o600)
|
|
173
|
+
return path
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""earshot CLI:listen / audio / devices / doctor。"""
|
|
1
|
+
"""earshot CLI:listen / audio / video / ocr / devices / doctor。"""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -13,12 +13,21 @@ from pathlib import Path
|
|
|
13
13
|
import numpy as np
|
|
14
14
|
|
|
15
15
|
from earshot import __version__
|
|
16
|
-
from earshot.auth import device_login, save_credentials, verify_key
|
|
16
|
+
from earshot.auth import clear_credentials, device_login, save_credentials, verify_key
|
|
17
17
|
from earshot.capture import blackhole_missing_hint, list_capture_devices, pick_device, record_to_wav
|
|
18
|
-
from earshot.compose import
|
|
18
|
+
from earshot.compose import (
|
|
19
|
+
NoteMeta,
|
|
20
|
+
add_punctuation,
|
|
21
|
+
derive_title,
|
|
22
|
+
drop_cta,
|
|
23
|
+
group_paragraphs,
|
|
24
|
+
outbox_path,
|
|
25
|
+
render_markdown,
|
|
26
|
+
)
|
|
19
27
|
from earshot.config import DEFAULT_EXOMIND_BASE_URL, Settings, load_settings
|
|
20
28
|
from earshot.deliver import DeliveryResult, deliver_exomind, deliver_exomind_api, deliver_webhook
|
|
21
29
|
from earshot.extract import ExtractError, ffmpeg_available, to_wav16k, wav_duration
|
|
30
|
+
from earshot.hardsub import FrameOcr, HardsubError, download_video, extract_hardsub, is_url, make_rapidocr_engine
|
|
22
31
|
from earshot.live import LiveSession
|
|
23
32
|
from earshot.models import ensure_models
|
|
24
33
|
from earshot.subtitle import SubtitleError, fetch_video_note
|
|
@@ -69,6 +78,16 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
69
78
|
help="浏览器名(chrome/safari/firefox/edge),拉 AI 字幕(ai-zh)通常需要登录态",
|
|
70
79
|
)
|
|
71
80
|
|
|
81
|
+
p_ocr = sub.add_parser("ocr", help="硬字幕视频 OCR 提取(字幕烧在画面里、无音轨的场景)")
|
|
82
|
+
_add_common(p_ocr)
|
|
83
|
+
p_ocr.add_argument("path_or_url", nargs="?", help="视频文件路径或链接(B站等;缺省时交互询问)")
|
|
84
|
+
p_ocr.add_argument("--fps", type=float, default=1.0, help="抽帧采样率(默认 1;长视频可 0.5,<1 会漏短字幕)")
|
|
85
|
+
p_ocr.add_argument(
|
|
86
|
+
"--region", choices=["bottom", "full"], default="bottom", help="识别区域(默认 bottom 底部字幕条带)"
|
|
87
|
+
)
|
|
88
|
+
p_ocr.add_argument("--min-score", type=float, default=0.55, help="行级置信度阈值,低于则丢弃(默认 0.55)")
|
|
89
|
+
p_ocr.add_argument("--cookies-from-browser", help="浏览器名(chrome/safari/firefox/edge),下载需要登录态的视频时用")
|
|
90
|
+
|
|
72
91
|
p_deliver = sub.add_parser("deliver", help="补投/重投 outbox 里的笔记")
|
|
73
92
|
p_deliver.add_argument("file", type=Path, help="笔记 md 路径")
|
|
74
93
|
p_deliver.add_argument("--title", help="标题(默认取首行 # 标题)")
|
|
@@ -84,6 +103,14 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
84
103
|
p_login.add_argument("--base-url", default=DEFAULT_EXOMIND_BASE_URL, help="exomind API 地址")
|
|
85
104
|
p_login.add_argument("--force", action="store_true", help="跳过「凭据仍有效」检查,无条件重新登录")
|
|
86
105
|
|
|
106
|
+
p_update = sub.add_parser("update", help="替换 API Key(新 key 从 exomind 管理端复制;获取凭据用 login)")
|
|
107
|
+
p_update.add_argument("--api-key", default=None, help="新 API Key(不填则交互粘贴)")
|
|
108
|
+
|
|
109
|
+
sub.add_parser("logout", help="清除本地凭据(保留服务器地址;exomind-cli/fireCut 共用该配置,会一并失效)")
|
|
110
|
+
|
|
111
|
+
p_help = sub.add_parser("help", help="显示帮助:earshot help [命令]")
|
|
112
|
+
p_help.add_argument("topic", nargs="?", default=None, help="要查看帮助的命令名")
|
|
113
|
+
|
|
87
114
|
sub.add_parser("devices", help="列出可用采集设备")
|
|
88
115
|
sub.add_parser("doctor", help="环境自检")
|
|
89
116
|
p_clean = sub.add_parser("clean", help="清理过期留档(outbox+tmp)")
|
|
@@ -117,6 +144,10 @@ def _run_pipeline(
|
|
|
117
144
|
chapter_breaks: list[float] | None = None,
|
|
118
145
|
) -> int:
|
|
119
146
|
"""组装 md → 落 outbox → 投递,返回退出码。"""
|
|
147
|
+
kept = drop_cta(segments) # 滤粉丝互动话术(求三连/关注),四路统一
|
|
148
|
+
if dropped := len(segments) - len(kept):
|
|
149
|
+
print(f"已滤除 {dropped} 句粉丝互动话术(三连/关注类)")
|
|
150
|
+
segments = kept
|
|
120
151
|
if not any(s.text.strip() for s in segments):
|
|
121
152
|
print("未识别到语音内容(检查系统输出/设备,或音频本身无人声)")
|
|
122
153
|
return EXIT_NO_CONTENT
|
|
@@ -428,6 +459,90 @@ def cmd_video(args: argparse.Namespace, settings: Settings) -> int:
|
|
|
428
459
|
return _run_pipeline(segments, note_meta, args, settings, chapter_breaks=meta.chapter_starts)
|
|
429
460
|
|
|
430
461
|
|
|
462
|
+
def cmd_ocr(args: argparse.Namespace, settings: Settings) -> int:
|
|
463
|
+
target = args.path_or_url
|
|
464
|
+
if not target:
|
|
465
|
+
if not _interactive():
|
|
466
|
+
print("✗ 缺少视频路径或链接:earshot ocr <file|url>(或交互模式直接 earshot)")
|
|
467
|
+
return EXIT_FAIL
|
|
468
|
+
clip = _clipboard_text()
|
|
469
|
+
if clip.lower().startswith("http"):
|
|
470
|
+
target = _prompt("视频路径或链接", default=_short_url(clip), prefill=True)
|
|
471
|
+
else:
|
|
472
|
+
target = _prompt("视频路径或链接(本地文件 / B站链接)")
|
|
473
|
+
if not target:
|
|
474
|
+
print("✗ 未提供视频路径或链接")
|
|
475
|
+
return EXIT_FAIL
|
|
476
|
+
url_mode = is_url(target)
|
|
477
|
+
title, uploader, source_url = "", "-", ""
|
|
478
|
+
if not url_mode: # 本地文件先校验存在性(免费检查,先于引擎构建与报「引擎未安装」)
|
|
479
|
+
video_path = Path(target).expanduser()
|
|
480
|
+
if not video_path.is_file():
|
|
481
|
+
print(f"✗ 文件不存在: {video_path}")
|
|
482
|
+
return EXIT_FAIL
|
|
483
|
+
title = video_path.stem
|
|
484
|
+
try:
|
|
485
|
+
engine = make_rapidocr_engine() # 引擎先建:未装 [ocr] extra 时尽早失败,别等下载完
|
|
486
|
+
except HardsubError as e:
|
|
487
|
+
print(f"✗ {e}")
|
|
488
|
+
return EXIT_FAIL
|
|
489
|
+
|
|
490
|
+
tmp_dir = settings.home / "tmp"
|
|
491
|
+
tmp_dir.mkdir(parents=True, exist_ok=True)
|
|
492
|
+
if url_mode:
|
|
493
|
+
try:
|
|
494
|
+
dl = download_video(target, tmp_dir, cookies_browser=args.cookies_from_browser)
|
|
495
|
+
except HardsubError as e:
|
|
496
|
+
print(f"✗ {e}")
|
|
497
|
+
return EXIT_FAIL
|
|
498
|
+
video_path = dl.path
|
|
499
|
+
title, uploader, source_url = dl.title, dl.uploader, target
|
|
500
|
+
print(f"→ 已下载:{title}(UP:{uploader})")
|
|
501
|
+
print(f"→ 硬字幕 OCR 中({args.fps}fps,区域 {args.region})…")
|
|
502
|
+
|
|
503
|
+
def _progress(done: int, total: int) -> None:
|
|
504
|
+
print(f"\r→ OCR 中… {done}/{total} 帧({done / total * 100:3.0f}%)", end="", flush=True)
|
|
505
|
+
|
|
506
|
+
last_text = ""
|
|
507
|
+
|
|
508
|
+
def _show(frame: FrameOcr) -> None:
|
|
509
|
+
# 实时字幕上屏(listen 同款):新字幕行出现即回显,不用等整片跑完才知道内容对不对
|
|
510
|
+
nonlocal last_text
|
|
511
|
+
if not frame.text or frame.text == last_text:
|
|
512
|
+
return
|
|
513
|
+
last_text = frame.text
|
|
514
|
+
print(f"\r\033[K ↪ {frame.text}", flush=True) # 清掉进度行再上屏,进度随后 \r 重绘
|
|
515
|
+
|
|
516
|
+
try:
|
|
517
|
+
duration_s, segments = extract_hardsub(
|
|
518
|
+
video_path,
|
|
519
|
+
tmp_dir,
|
|
520
|
+
fps=args.fps,
|
|
521
|
+
region=args.region,
|
|
522
|
+
min_score=args.min_score,
|
|
523
|
+
engine=engine,
|
|
524
|
+
on_progress=_progress,
|
|
525
|
+
on_frame=_show,
|
|
526
|
+
)
|
|
527
|
+
print()
|
|
528
|
+
if not args.title:
|
|
529
|
+
args.title = title
|
|
530
|
+
if not args.note:
|
|
531
|
+
args.note = source_url or f"本地文件 {video_path.name}"
|
|
532
|
+
note_meta = NoteMeta(
|
|
533
|
+
started_at=datetime.now(),
|
|
534
|
+
duration_s=duration_s,
|
|
535
|
+
device=uploader,
|
|
536
|
+
source="ocr",
|
|
537
|
+
note=args.note,
|
|
538
|
+
source_url=source_url,
|
|
539
|
+
)
|
|
540
|
+
return _run_pipeline(segments, note_meta, args, settings)
|
|
541
|
+
finally:
|
|
542
|
+
if url_mode:
|
|
543
|
+
video_path.unlink(missing_ok=True) # URL 模式不留全片(磁盘紧张;确认/放弃已在上方完成)
|
|
544
|
+
|
|
545
|
+
|
|
431
546
|
def cmd_deliver(args: argparse.Namespace, settings: Settings) -> int:
|
|
432
547
|
md_path = args.file
|
|
433
548
|
if not md_path.is_file():
|
|
@@ -469,6 +584,13 @@ def cmd_doctor(_args: argparse.Namespace, settings: Settings) -> int:
|
|
|
469
584
|
print(f"{'✓' if fine else '✗'} {label}" + ("" if fine else f" → {fix}"))
|
|
470
585
|
|
|
471
586
|
check("ffmpeg(系统或内置)", ffmpeg_available(), "重装 earshot 依赖(imageio-ffmpeg 应自带)")
|
|
587
|
+
try:
|
|
588
|
+
import rapidocr # noqa: F401,PLC0415 轻量探测:不实例化,doctor 不加载模型
|
|
589
|
+
|
|
590
|
+
print("✓ OCR 引擎(RapidOCR,硬字幕提取)")
|
|
591
|
+
except ImportError:
|
|
592
|
+
# 可选能力,缺失不算失败:降级为提示
|
|
593
|
+
print('○ OCR 引擎:未安装,硬字幕提取(earshot ocr)需 uv tool install "earshot-cli[ocr]"')
|
|
472
594
|
try:
|
|
473
595
|
devices = list_capture_devices()
|
|
474
596
|
loopbacks = [n for n, lb in devices if lb]
|
|
@@ -553,6 +675,42 @@ def cmd_login(args: argparse.Namespace, settings: Settings) -> int:
|
|
|
553
675
|
return EXIT_OK
|
|
554
676
|
|
|
555
677
|
|
|
678
|
+
def cmd_update(args: argparse.Namespace, settings: Settings) -> int:
|
|
679
|
+
"""替换 API Key:已拿到新 key(exomind 管理端复制)时本地换上。
|
|
680
|
+
|
|
681
|
+
只管替换,不管新 key 怎么来——获取凭据走 login 的设备流。探活不通过不写入
|
|
682
|
+
(与 cmd_login 同款纪律,避免无效 key 覆盖现有有效配置)。
|
|
683
|
+
"""
|
|
684
|
+
key = args.api_key
|
|
685
|
+
if not key:
|
|
686
|
+
key = _prompt("新 API Key(回车取消)")
|
|
687
|
+
if not key:
|
|
688
|
+
print("未提供凭据,未改动。")
|
|
689
|
+
return EXIT_OK
|
|
690
|
+
base_url = settings.exomind_base_url or DEFAULT_EXOMIND_BASE_URL
|
|
691
|
+
if not verify_key(base_url, key):
|
|
692
|
+
print(f"✗ 凭据探活失败({base_url}),未写入;确认 key 有效后重试")
|
|
693
|
+
return EXIT_FAIL
|
|
694
|
+
path = save_credentials(base_url, key)
|
|
695
|
+
masked = f"{key[:8]}…{key[-4:]}" if len(key) > 12 else key
|
|
696
|
+
print(f"✓ 凭据已替换:{masked}")
|
|
697
|
+
print(f" 已写入 {path}")
|
|
698
|
+
return EXIT_OK
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
def cmd_logout(_args: argparse.Namespace, _settings: Settings) -> int:
|
|
702
|
+
"""清除本地凭据(保留 base_url);~/.exomind/config.json 三家共用,登出影响一并说清。"""
|
|
703
|
+
path = clear_credentials()
|
|
704
|
+
if path is None:
|
|
705
|
+
print("未登录(本地无凭据),无需登出。")
|
|
706
|
+
return EXIT_OK
|
|
707
|
+
print(f"✓ 已登出,本地凭据已清除({path})")
|
|
708
|
+
print(" 服务器地址保留;重新登录: earshot login")
|
|
709
|
+
print(" 注意: ~/.exomind/config.json 由 earshot/exomind-cli/fireCut 共享,它们的调用也会失效")
|
|
710
|
+
print(" 服务端吊销该 key 请到 exomind 管理端(account 页)操作")
|
|
711
|
+
return EXIT_OK
|
|
712
|
+
|
|
713
|
+
|
|
556
714
|
def main(argv: list[str] | None = None) -> int:
|
|
557
715
|
parser = build_parser()
|
|
558
716
|
args = parser.parse_args(argv)
|
|
@@ -561,21 +719,33 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
561
719
|
"listen": cmd_listen,
|
|
562
720
|
"audio": cmd_audio,
|
|
563
721
|
"video": cmd_video,
|
|
722
|
+
"ocr": cmd_ocr,
|
|
564
723
|
"deliver": cmd_deliver,
|
|
565
724
|
"login": cmd_login,
|
|
725
|
+
"update": cmd_update,
|
|
726
|
+
"logout": cmd_logout,
|
|
566
727
|
"me": cmd_me,
|
|
567
728
|
"devices": cmd_devices,
|
|
568
729
|
"doctor": cmd_doctor,
|
|
569
730
|
"clean": cmd_clean,
|
|
570
731
|
}
|
|
732
|
+
if args.command == "help":
|
|
733
|
+
if args.topic:
|
|
734
|
+
# 复用 argparse 自己的 -h 渲染:earshot help listen ≡ earshot listen --help
|
|
735
|
+
try:
|
|
736
|
+
parser.parse_args([args.topic, "--help"])
|
|
737
|
+
except SystemExit as exc:
|
|
738
|
+
return int(exc.code or 0)
|
|
739
|
+
parser.print_help()
|
|
740
|
+
return EXIT_OK
|
|
571
741
|
if args.command is None:
|
|
572
742
|
if not _interactive():
|
|
573
743
|
parser.print_help()
|
|
574
744
|
return EXIT_FAIL
|
|
575
|
-
choice = _prompt("earshot 模式 [1]听录 [2]视频字幕 [3]本地文件(回车=1;输入 q 退出)", default="1")
|
|
745
|
+
choice = _prompt("earshot 模式 [1]听录 [2]视频字幕 [3]本地文件 [4]硬字幕OCR(回车=1;输入 q 退出)", default="1")
|
|
576
746
|
if choice == "q":
|
|
577
747
|
return EXIT_OK
|
|
578
|
-
mapping = {"1": "listen", "2": "video", "3": "audio"}
|
|
748
|
+
mapping = {"1": "listen", "2": "video", "3": "audio", "4": "ocr"}
|
|
579
749
|
sub = mapping.get(choice)
|
|
580
750
|
if sub is None:
|
|
581
751
|
print(f"✗ 无效选择: {choice}")
|
|
@@ -14,7 +14,28 @@ PARAGRAPH_MAX_CHARS = 400 # 单段上限,超出在句号处拆(口播字幕无
|
|
|
14
14
|
SENTENCE_MAX_CHARS = 60 # 句长预算:连续无句号超过该字数,强制断句
|
|
15
15
|
TITLE_MAX_CHARS = 40
|
|
16
16
|
|
|
17
|
-
SOURCE_LABELS = {"listen": "旁听录音", "audio": "音频文件", "video": "视频字幕"}
|
|
17
|
+
SOURCE_LABELS = {"listen": "旁听录音", "audio": "音频文件", "video": "视频字幕", "ocr": "硬字幕OCR"}
|
|
18
|
+
|
|
19
|
+
# 粉丝互动话术(求三连/关注/下期再见):不是知识内容,入库只会污染实体抽取。
|
|
20
|
+
# 严格模式控制误杀:须「命中模式 且 整段 ≤50 字」才丢(知识视频真讨论"点赞机制"时多为长句)。
|
|
21
|
+
CTA_MAX_CHARS = 50
|
|
22
|
+
CTA_PATTERNS = (
|
|
23
|
+
re.compile(r"三连|投币"),
|
|
24
|
+
re.compile(r"点赞.{0,8}(收藏|关注|转发|加购)"),
|
|
25
|
+
re.compile(r"(关注|订阅).{0,6}(我|频道|账号|公众号)"),
|
|
26
|
+
re.compile(r"下期(再?见|再见)|不见不散|不迷路"),
|
|
27
|
+
re.compile(r"(谢谢|感谢)观看"),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def drop_cta(segments: list[Segment]) -> list[Segment]:
|
|
32
|
+
"""滤除粉丝互动话术段(纯函数,listen/audio/video/ocr 四路统一)。"""
|
|
33
|
+
return [s for s in segments if not _is_cta(s.text)]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _is_cta(text: str) -> bool:
|
|
37
|
+
t = text.strip()
|
|
38
|
+
return len(t) <= CTA_MAX_CHARS and any(p.search(t) for p in CTA_PATTERNS)
|
|
18
39
|
|
|
19
40
|
|
|
20
41
|
@dataclass(frozen=True, slots=True)
|