Skip to content

feat(captions): import SRT/WebVTT and export SRT/WebVTT in the browser build - #72

Closed
YueyuHoshizora wants to merge 2 commits into
Hao0321:mainfrom
YueyuHoshizora:feat/issue-60-caption-srt-vtt
Closed

YueyuHoshizora wants to merge 2 commits into
Hao0321:mainfrom
YueyuHoshizora:feat/issue-60-caption-srt-vtt

Conversation

@YueyuHoshizora

Copy link
Copy Markdown
Contributor

Refs #60

What changed(變更內容)

  • 新增 src/application/captionFiles.ts(不含 node 依賴):
    • serializeCaptions:輸出 SRT/WebVTT,依開始時間排序,cue 內空行移除,取整後不產生零長度 cue;WebVTT 跳脫 & < >。
    • parseCaptionFile:解析 SRT/WebVTT(BOM、CRLF、無序號、./, 毫秒、MM:SS.mmm、NOTE/STYLE/REGION、cue settings、<v>/<i> 標籤、ASS {\an8}、VTT entity;單獨的 < 保留為文字)。整份先驗證,任何一段不合法就整份不匯入,錯誤訊息指出第幾段。上限 5 MB、20,000 句。
    • buildImportCaptionsCommand:以單一 batch add_caption 加入,時間對齊 fps,一次 Undo 全部移除。
  • 專案選單新增「字幕檔」區:匯入(桌面與網頁)、匯出 SRT/WebVTT(僅網頁)。
  • exportGraph.ts 抽出 downloadTextFile,downloadEditGraph 改用,無重複程式。
  • docs/BUILDING.md 新增「Caption files」。無新增依賴。

User journey and platform(使用者流程與平台)

使用者可把外部 SRT/VTT 匯入時間軸繼續編修,也可在網頁版把字幕匯出給其他軟體或網頁播放器。桌面版目前只有匯入:桌面沒有通用的存檔通道,blob 下載無法在該環境驗證,所以未放入;補上需要新增讓使用者選路徑的 IPC(會與 #42 的路徑綁定設計相關)。因此本 PR 使用 Refs,issue 保持開啟。

Validation(驗證)

  • 完整 npm test:2009 passed、4 skipped;tsc --noEmit 乾淨;npm run source:scan GREEN。
  • captionFiles.test.ts(14 項):小時級時間戳、排序、零長度 cue、VTT 跳脫往返、SRT 往返、真實世界 SRT/VTT 寫法、6 種錯誤輸入(無時間軸、結束早於開始、分鐘超範圍、時間亂碼、無可匯入內容、空檔)、匯入後對齊 fps 且 id 唯一。
  • 真實 Chromium(build 後的 dist):匯入無效檔顯示「第 1 段找不到…時間軸」且未加入字幕;匯入 2 句 SRT 成功;匯出的 SRT/VTT 內容正確(含 3 &lt; 5 &amp; ok)。
  • 未驗證:桌面版、Safari、Firefox。

Security and provenance(安全與來源)

  • 字幕文字僅作為 React 文字節點顯示;標籤剝除採單次掃描,只移除完整且格式正確的標籤。
  • 檔案限制 5 MB、20,000 句,本機處理、不上傳。
  • 無新增依賴、二進位檔或憑證。
  • 已知限制:翻譯字幕不匯出;SRT 匯出不跳脫,內含標籤形式的文字重新匯入時會被當成標籤移除。
  • 本 PR 從 main 分出,未含 feat(web): open, save, re-link media and autosave projects in the browser build #71,App.tsx、Toolbar.tsx、EditorShell.tsx 會與其有相鄰改動,後合併者可能需要 rebase。

DCO

Commit 已使用 git commit -s 簽署。

YueyuHoshizora and others added 2 commits September 30, 2026 17:50
…r build

Add node-free caption file parsing and serialization, an import action
that adds all cues in one undoable batch, and browser-only export.
Desktop export needs a native save channel and is not included.

Refs Hao0321#60

Signed-off-by: Yueyu Hoshizora <yueyuhoshizora@gmail.com>

@Hao0321 Hao0321 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caption parser does not meet the bounded-input processing requirement. Maintainer validation of the actual compiled parser shows that admissible literal cue text below the stated size limit can exceed a one-second execution deadline; normal cue and timeout controls were verified. Replace the repeated suffix searches with genuinely bounded processing and retain literal-text correctness. Also preserve the already reviewed owner-only Pages workflow. Keep the new feature unmerged until these regressions and the native import path have meaningful coverage.

Hao0321 commented Oct 6, 2026

Copy link
Copy Markdown
Owner

感謝你的貢獻!Editkin 已確定以本機桌面版為主,不再發展網頁版,GitHub Pages 部署也會移除(見 #87),所以這個 PR 先關閉。

SRT/WebVTT 的匯入匯出對桌面版也有價值。如果你願意,歡迎以桌面版為目標重新提交,並請:

  • 不要包含 .github/workflows/pages.yml 的變更;
  • 先處理之前 review 提到的字幕解析上限(標記剝除改成線性時間、時間戳必須是有限且有上限的值),並加上對應的測試。

Generated by Claude Code

@Hao0321 Hao0321 closed this Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants