dsh-zju-lecture-note 2.2.3 → 2.2.5
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.
- package/CHANGELOG.md +102 -1
- package/README.md +98 -150
- package/SECURITY.md +136 -44
- package/docs/technical.md +175 -45
- package/lib/client.js +14 -13
- package/lib/index.js +53 -19
- package/lib/tools.js +28 -3
- package/lib/tools.schema.json +28 -3
- package/mcp_server.py +285 -34
- package/package.json +6 -2
- package/skills/scholia-notes/SKILL.md +8 -1
- package/skills/scholia-notes/references/format-spec.md +57 -6
- package/skills/scholia-notes/references/prelude.typ +55 -0
- package/skills/scholia-notes/references/typography-spec.md +4 -4
- package/skills/scholia-notes.manifest.json +9 -9
- package/skills/zju-lecture-summarizer/SKILL.md +56 -11
- package/skills/zju-lecture-summarizer-help/SKILL.md +95 -0
- package/skills/zju-lecture-summarizer-help.manifest.json +14 -0
- package/skills/zju-lecture-summarizer-login/SKILL.md +40 -0
- package/skills/zju-lecture-summarizer-login.manifest.json +14 -0
- package/skills/zju-lecture-summarizer.manifest.json +4 -4
- package/zju_lecture/__init__.py +16 -0
- package/zju_lecture/browser_login.py +923 -0
- package/zju_lecture/cli.py +98 -3
- package/zju_lecture/client.py +808 -741
- package/zju_lecture/handout.py +390 -60
- package/zju_lecture/handout_prelude.typ +47 -2
- package/zju_lecture/note_lint.py +12 -0
- package/zju_lecture/prelude.typ +55 -0
- package/zju_lecture/study_notes.py +415 -4
- package/zju_lecture/typst-packages/VENDORED.md +1 -1
- package/zju_lecture/typst-packages/preview/noteworthy/0.4.0/LICENSE +20 -20
- package/zju_lecture/typst-packages/preview/noteworthy/0.4.0/lib.typ +128 -128
- package/zju_lecture/typst-packages/preview/noteworthy/0.4.0/typst.toml +15 -15
- package/zju_lecture/typst-packages/preview/scholia/0.1.0/src/lib.typ +2 -2
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/LICENSE +21 -21
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/lib/func.typ +142 -142
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/lib/id.typ +11 -11
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/lib/pre-rendering.typ +50 -50
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/lib/sections.typ +141 -141
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/lib/shadows.typ +118 -118
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/showy.typ +267 -267
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/typst.toml +11 -11
package/zju_lecture/cli.py
CHANGED
|
@@ -8,8 +8,17 @@ import json
|
|
|
8
8
|
import os
|
|
9
9
|
import sys
|
|
10
10
|
|
|
11
|
+
from .browser_login import (
|
|
12
|
+
LoginError,
|
|
13
|
+
clear_session,
|
|
14
|
+
load_session_cookie,
|
|
15
|
+
login_available,
|
|
16
|
+
open_login_window,
|
|
17
|
+
session_summary,
|
|
18
|
+
)
|
|
11
19
|
from .client import (
|
|
12
20
|
BASE_URL,
|
|
21
|
+
TranscriptAuthError,
|
|
13
22
|
ZJUAPIError,
|
|
14
23
|
fetch_slides,
|
|
15
24
|
fetch_transcript,
|
|
@@ -37,7 +46,7 @@ def _read_cookie_file(path: str) -> str:
|
|
|
37
46
|
|
|
38
47
|
|
|
39
48
|
def _load_cookie(explicit: str = "", cookie_file: str = "") -> str:
|
|
40
|
-
"""Resolve a cookie: explicit
|
|
49
|
+
"""Resolve a cookie: explicit > file > ZJU_COOKIE > zju_login session > Edge."""
|
|
41
50
|
if explicit:
|
|
42
51
|
print(
|
|
43
52
|
"[zju-lecture] 警告: --cookie 会出现在进程列表中;建议改用 --cookie-file 或 ZJU_COOKIE。",
|
|
@@ -49,6 +58,9 @@ def _load_cookie(explicit: str = "", cookie_file: str = "") -> str:
|
|
|
49
58
|
env_cookie = os.environ.get("ZJU_COOKIE", "").strip()
|
|
50
59
|
if env_cookie:
|
|
51
60
|
return sanitize_cookie_header(env_cookie)
|
|
61
|
+
saved = load_session_cookie()
|
|
62
|
+
if saved:
|
|
63
|
+
return saved
|
|
52
64
|
return get_edge_cookie() or ""
|
|
53
65
|
|
|
54
66
|
|
|
@@ -84,8 +96,17 @@ def main():
|
|
|
84
96
|
p_parse.add_argument("url", help="回放 URL 或 sub_id")
|
|
85
97
|
|
|
86
98
|
# Command: fetch
|
|
87
|
-
p_fetch = subparsers.add_parser("fetch", help="
|
|
99
|
+
p_fetch = subparsers.add_parser("fetch", help="抓取课程语音识别字幕(可能需要登录态)")
|
|
88
100
|
p_fetch.add_argument("url", help="回放 URL 或 sub_id")
|
|
101
|
+
p_fetch.add_argument(
|
|
102
|
+
"--no-login",
|
|
103
|
+
action="store_true",
|
|
104
|
+
help="匿名请求被拒绝时不使用本机登录态(默认会自动读取本地登录态重试一次)",
|
|
105
|
+
)
|
|
106
|
+
p_fetch.add_argument(
|
|
107
|
+
"--cookie-file",
|
|
108
|
+
help="匿名请求被拒绝时,从指定本地文件读取登录态(不要传 Cookie 明文)",
|
|
109
|
+
)
|
|
89
110
|
p_fetch.add_argument(
|
|
90
111
|
"--format",
|
|
91
112
|
choices=["min", "seg", "chunk", "json"],
|
|
@@ -136,6 +157,29 @@ def main():
|
|
|
136
157
|
p_cw.add_argument("file", help="课件文件路径")
|
|
137
158
|
p_cw.add_argument("--max-chars", type=int, default=10000, help="最多提取字符数")
|
|
138
159
|
|
|
160
|
+
# Command: login
|
|
161
|
+
p_login = subparsers.add_parser(
|
|
162
|
+
"login",
|
|
163
|
+
help="打开独立登录窗口完成浙大登录,并安全保存本机登录态",
|
|
164
|
+
)
|
|
165
|
+
p_login.add_argument(
|
|
166
|
+
"url",
|
|
167
|
+
nargs="?",
|
|
168
|
+
default="",
|
|
169
|
+
help="登录后要打开的课堂链接(可选,仅接受 https 的 *.zju.edu.cn)",
|
|
170
|
+
)
|
|
171
|
+
p_login.add_argument(
|
|
172
|
+
"--timeout",
|
|
173
|
+
type=int,
|
|
174
|
+
default=300,
|
|
175
|
+
help="等待完成登录的秒数(默认 300,范围 30–540)",
|
|
176
|
+
)
|
|
177
|
+
p_login.add_argument(
|
|
178
|
+
"--clear",
|
|
179
|
+
action="store_true",
|
|
180
|
+
help="清除本机保存的登录态与独立登录窗口配置(不打开窗口)",
|
|
181
|
+
)
|
|
182
|
+
|
|
139
183
|
# Command: cookie
|
|
140
184
|
p_cookie = subparsers.add_parser("cookie", help="从本机 Edge 读取智云课堂 Cookie")
|
|
141
185
|
p_cookie.add_argument(
|
|
@@ -161,7 +205,24 @@ def main():
|
|
|
161
205
|
parsed = parse_lecture_url(args.url)
|
|
162
206
|
sub_id = parsed["sub_id"]
|
|
163
207
|
tenant = parsed.get("tenant_code", "112")
|
|
164
|
-
|
|
208
|
+
try:
|
|
209
|
+
segs = fetch_transcript(sub_id, tenant)
|
|
210
|
+
except TranscriptAuthError as exc:
|
|
211
|
+
if args.no_login:
|
|
212
|
+
raise ZJUAPIError(f"{exc}已按 --no-login 禁用本机登录态。") from exc
|
|
213
|
+
cookie = _load_cookie(cookie_file=args.cookie_file or os.environ.get("ZJU_COOKIE_FILE", ""))
|
|
214
|
+
if not cookie:
|
|
215
|
+
raise ZJUAPIError(
|
|
216
|
+
f"{exc}未读取到本机登录态;运行 `zju-lecture login` 打开独立登录窗口,"
|
|
217
|
+
"或使用 --cookie-file 指定本地 Cookie 文件(高级兜底)。"
|
|
218
|
+
) from exc
|
|
219
|
+
try:
|
|
220
|
+
segs = fetch_transcript(sub_id, tenant, cookie=cookie)
|
|
221
|
+
except TranscriptAuthError as auth_exc:
|
|
222
|
+
raise ZJUAPIError(
|
|
223
|
+
f"携带本地登录态后仍返回 HTTP {auth_exc.status},已停止重试;"
|
|
224
|
+
"请确认官网字幕权限并更新本机登录态。"
|
|
225
|
+
) from auth_exc
|
|
165
226
|
|
|
166
227
|
start_sec = args.start * 60 if args.start is not None else None
|
|
167
228
|
end_sec = (args.end * 60 + 59) if args.end is not None else None
|
|
@@ -262,10 +323,44 @@ def main():
|
|
|
262
323
|
sys.exit(1)
|
|
263
324
|
print(text)
|
|
264
325
|
|
|
326
|
+
elif args.command == "login":
|
|
327
|
+
if args.clear:
|
|
328
|
+
result = clear_session(delete_profile=True)
|
|
329
|
+
print(
|
|
330
|
+
"已清除本机登录态。"
|
|
331
|
+
if result.get("session_removed")
|
|
332
|
+
else "本机没有保存的登录态。"
|
|
333
|
+
)
|
|
334
|
+
if result.get("profile_removed"):
|
|
335
|
+
print("独立登录窗口的浏览器配置也已删除。")
|
|
336
|
+
if result.get("profile_error"):
|
|
337
|
+
print(
|
|
338
|
+
"独立登录窗口配置未能删除:"
|
|
339
|
+
f"{result['profile_error']}。请先关闭该窗口后重试。",
|
|
340
|
+
file=sys.stderr,
|
|
341
|
+
)
|
|
342
|
+
return
|
|
343
|
+
try:
|
|
344
|
+
result = open_login_window(args.url, args.timeout)
|
|
345
|
+
except LoginError as exc:
|
|
346
|
+
print(f"登录未完成({exc.reason}):{exc.message}", file=sys.stderr)
|
|
347
|
+
if exc.hint:
|
|
348
|
+
print(f"下一步:{exc.hint}", file=sys.stderr)
|
|
349
|
+
sys.exit(1)
|
|
350
|
+
print("登录成功,已读取本机登录态。")
|
|
351
|
+
print(f"- 浏览器: {result['browser']}")
|
|
352
|
+
print(f"- Cookie: {len(result['names'])} 条(含 _token,值不回显)")
|
|
353
|
+
if result.get("saved"):
|
|
354
|
+
print(f"- 保存: {result['saved_path']}(仅当前系统用户可解密)")
|
|
355
|
+
else:
|
|
356
|
+
print(f"- 保存失败: {result.get('save_error') or '未知原因'}(本次会话可用)")
|
|
357
|
+
print("现在可以运行 `zju-lecture fetch <url>`。")
|
|
358
|
+
|
|
265
359
|
elif args.command == "cookie":
|
|
266
360
|
c = get_edge_cookie()
|
|
267
361
|
if not c:
|
|
268
362
|
print("未能在本机 Edge 找到 classroom.zju.edu.cn 的 Cookie。")
|
|
363
|
+
print("推荐改用 `zju-lecture login`:它会打开独立登录窗口,不依赖 Edge 的 Cookie 解密。")
|
|
269
364
|
return
|
|
270
365
|
if args.reveal:
|
|
271
366
|
print("读取成功(明文回显;注意终端历史):")
|