earshot-cli 0.9.0__tar.gz → 0.10.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.9.0 → earshot_cli-0.10.0}/PKG-INFO +1 -1
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/pyproject.toml +1 -1
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/cli.py +25 -6
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/config.py +31 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_wizard.py +32 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/uv.lock +1 -1
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/.github/workflows/ci.yml +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/.github/workflows/publish.yml +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/.gitignore +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/LICENSE +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/README.md +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/scripts/download_models.sh +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/__init__.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/auth.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/capture.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/compose.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/deliver.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/extract.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/hardsub.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/live.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/models.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/subtitle.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/transcribe.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/src/earshot/transcribe_cloud.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/conftest.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_auth.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_compose.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_config.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_credential_lifecycle.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_deliver.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_deliver_api.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_do_deliver.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_extract.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_hardsub.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_live.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_me.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.0}/tests/test_subtitle.py +0 -0
- {earshot_cli-0.9.0 → earshot_cli-0.10.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.10.0
|
|
4
4
|
Summary: 媒体剪藏:视频字幕/系统声听录/本地音频/硬字幕OCR 四路摄入,端侧转写 → Markdown → 投递知识库(默认 ExoMind,可插拔)
|
|
5
5
|
Project-URL: Homepage, https://github.com/helloworldtang/earshot
|
|
6
6
|
Project-URL: Repository, https://github.com/helloworldtang/earshot
|
|
@@ -24,7 +24,7 @@ from earshot.compose import (
|
|
|
24
24
|
outbox_path,
|
|
25
25
|
render_markdown,
|
|
26
26
|
)
|
|
27
|
-
from earshot.config import DEFAULT_EXOMIND_BASE_URL, Settings, load_settings
|
|
27
|
+
from earshot.config import DEFAULT_EXOMIND_BASE_URL, Settings, load_settings, load_state, save_state
|
|
28
28
|
from earshot.deliver import DeliveryResult, deliver_exomind, deliver_exomind_api, deliver_webhook
|
|
29
29
|
from earshot.extract import ExtractError, ffmpeg_available, to_wav16k, wav_duration
|
|
30
30
|
from earshot.hardsub import FrameOcr, HardsubError, download_video, extract_hardsub, is_url, make_rapidocr_engine
|
|
@@ -78,7 +78,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
78
78
|
p_video.add_argument("url", nargs="?", help="视频链接(B站等 yt-dlp 支持的平台;缺省时交互询问)")
|
|
79
79
|
p_video.add_argument(
|
|
80
80
|
"--cookies-from-browser",
|
|
81
|
-
help="浏览器名(chrome/safari/firefox/edge)
|
|
81
|
+
help="浏览器名(chrome/safari/firefox/edge;none=匿名)。拉 AI 字幕(ai-zh)通常需要登录态;选择会被记住",
|
|
82
82
|
)
|
|
83
83
|
|
|
84
84
|
p_ocr = sub.add_parser("ocr", help="硬字幕视频 OCR 提取(字幕烧在画面里、无音轨的场景)")
|
|
@@ -422,6 +422,28 @@ def _short_url(url: str, max_len: int = 60) -> str:
|
|
|
422
422
|
return base
|
|
423
423
|
|
|
424
424
|
|
|
425
|
+
def _resolve_cookies(raw: str | None, settings: Settings) -> str | None:
|
|
426
|
+
"""解析字幕登录态浏览器:显式旗标 > 上次的选择(落盘记忆)> 交互问一次。
|
|
427
|
+
|
|
428
|
+
高频路径上「回车=chrome」是每回都付的税,问过一次就记住;显式旗标永远是
|
|
429
|
+
最新信号,顺带更新记忆(none/n 表示匿名)。
|
|
430
|
+
"""
|
|
431
|
+
if raw is not None:
|
|
432
|
+
cookies = None if raw.lower() in ("n", "none") else raw
|
|
433
|
+
save_state(settings.home, cookies_browser=cookies or "")
|
|
434
|
+
return cookies
|
|
435
|
+
remembered = load_state(settings.home).get("cookies_browser")
|
|
436
|
+
if remembered is not None:
|
|
437
|
+
print(f"→ 字幕登录态:{remembered or '匿名'}(上次的选择;--cookies-from-browser <名|none> 可改)")
|
|
438
|
+
return remembered or None
|
|
439
|
+
if _interactive():
|
|
440
|
+
ans = _prompt("字幕登录态浏览器(拉 AI 字幕用;回车=chrome,输 n 匿名;记住,之后不再问)", default="chrome")
|
|
441
|
+
cookies = None if ans.lower() in ("n", "none") else ans
|
|
442
|
+
save_state(settings.home, cookies_browser=cookies or "")
|
|
443
|
+
return cookies
|
|
444
|
+
return None
|
|
445
|
+
|
|
446
|
+
|
|
425
447
|
def cmd_video(args: argparse.Namespace, settings: Settings) -> int:
|
|
426
448
|
url = args.url
|
|
427
449
|
if not url:
|
|
@@ -437,10 +459,7 @@ def cmd_video(args: argparse.Namespace, settings: Settings) -> int:
|
|
|
437
459
|
if not url:
|
|
438
460
|
print("✗ 未提供链接")
|
|
439
461
|
return EXIT_FAIL
|
|
440
|
-
cookies = args.cookies_from_browser
|
|
441
|
-
if cookies is None and _interactive():
|
|
442
|
-
ans = _prompt("字幕登录态浏览器(拉 AI 字幕用;回车=chrome,输 n 匿名)", default="chrome")
|
|
443
|
-
cookies = None if ans.lower() == "n" else ans
|
|
462
|
+
cookies = _resolve_cookies(args.cookies_from_browser, settings)
|
|
444
463
|
try:
|
|
445
464
|
meta, segments = fetch_video_note(url, cookies)
|
|
446
465
|
except SubtitleError as e:
|
|
@@ -18,6 +18,7 @@ EXOMIND_BASE_URL_ENV = "EXOMIND_BASE_URL"
|
|
|
18
18
|
|
|
19
19
|
DEFAULT_EXOMIND_BASE_URL = "https://exomind-api.ai-as.cn"
|
|
20
20
|
EXOMIND_CONFIG_FILENAME = ".exomind/config.json"
|
|
21
|
+
STATE_FILENAME = "state.json"
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
@dataclass(frozen=True, slots=True)
|
|
@@ -69,6 +70,36 @@ def load_settings(
|
|
|
69
70
|
)
|
|
70
71
|
|
|
71
72
|
|
|
73
|
+
def load_state(home: Path) -> dict[str, str]:
|
|
74
|
+
"""读取本地状态文件(``~/.earshot/state.json``),不存在或损坏时返回空 dict。
|
|
75
|
+
|
|
76
|
+
与 config 的区别:state 是 CLI 运行中产生的记忆(如上次的选择),可随时重建。
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
home: earshot 数据目录。
|
|
80
|
+
"""
|
|
81
|
+
try:
|
|
82
|
+
raw = json.loads((home / STATE_FILENAME).read_text(encoding="utf-8"))
|
|
83
|
+
except (OSError, ValueError):
|
|
84
|
+
return {}
|
|
85
|
+
if not isinstance(raw, dict):
|
|
86
|
+
return {}
|
|
87
|
+
return {k: v for k, v in raw.items() if isinstance(v, str)}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def save_state(home: Path, **kv: str) -> None:
|
|
91
|
+
"""合并写入本地状态文件(保留未涉及的键)。
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
home: earshot 数据目录。
|
|
95
|
+
**kv: 要写入的键值对(均为字符串)。
|
|
96
|
+
"""
|
|
97
|
+
state = load_state(home)
|
|
98
|
+
state.update(kv)
|
|
99
|
+
home.mkdir(parents=True, exist_ok=True)
|
|
100
|
+
(home / STATE_FILENAME).write_text(json.dumps(state, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
101
|
+
|
|
102
|
+
|
|
72
103
|
def load_exomind_config(path: Path | None = None) -> dict[str, str]:
|
|
73
104
|
"""读取 exomind CLI 的配置文件,不存在或损坏时返回空 dict。
|
|
74
105
|
|
|
@@ -105,3 +105,35 @@ def test_run_pipeline_default_tag_follows_source(monkeypatch: pytest.MonkeyPatch
|
|
|
105
105
|
rc = cli._run_pipeline([Segment(0.0, 1.0, "内容")], meta, args, _settings())
|
|
106
106
|
assert rc == 0
|
|
107
107
|
assert captured["tags"] == ["视频字幕"]
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _settings_home(home: Path) -> Settings:
|
|
111
|
+
return Settings(
|
|
112
|
+
home=home,
|
|
113
|
+
model_root=home / "models",
|
|
114
|
+
exomind_base_url="https://api.example.com",
|
|
115
|
+
exomind_api_key="",
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_resolve_cookies_asks_once_then_remembers(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
|
120
|
+
"""交互问一次后落盘记忆:第二次起不再问,静默沿用上次选择。"""
|
|
121
|
+
settings = _settings_home(tmp_path)
|
|
122
|
+
monkeypatch.setattr(cli, "_interactive", lambda: True)
|
|
123
|
+
monkeypatch.setattr(cli, "_prompt", lambda *a, **k: "safari")
|
|
124
|
+
assert cli._resolve_cookies(None, settings) == "safari"
|
|
125
|
+
prompts: list[object] = []
|
|
126
|
+
monkeypatch.setattr(cli, "_prompt", lambda *a, **k: prompts.append(a) or "chrome")
|
|
127
|
+
assert cli._resolve_cookies(None, settings) == "safari" # 记忆生效
|
|
128
|
+
assert not prompts
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_resolve_cookies_explicit_none_overrides_and_persists(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
|
132
|
+
"""显式 --cookies-from-browser none 走匿名并覆盖记忆;之后无旗标也沿用匿名。"""
|
|
133
|
+
from earshot.config import load_state
|
|
134
|
+
|
|
135
|
+
settings = _settings_home(tmp_path)
|
|
136
|
+
monkeypatch.setattr(cli, "_interactive", lambda: True)
|
|
137
|
+
assert cli._resolve_cookies("none", settings) is None
|
|
138
|
+
assert load_state(settings.home)["cookies_browser"] == ""
|
|
139
|
+
assert cli._resolve_cookies(None, settings) is None # 匿名也被记住,且不再追问
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|