Add subtitle tracks to open Matroska documents

MKV docs can now import .srt/.ssa/.ass subtitle files, written as
S_TEXT/UTF8 by MP42MkvRemuxer (submodule bump). Video/audio adds and
other subtitle formats stay refused by both sides.

- DocumentWindowController: split selectFile: validation so MKV docs
  get an Import panel restricted to matroskaSubtitleExtensions (kept
  in sync with the remuxer's gate); showImportSheet routes MKV docs
  to importSubtitleTracksForMatroska, which imports each file with a
  plain MP42FileImporter (no track-selection sheet), attaches the
  conversion-settings defaults addTrack: asserts on, and assigns the
  next display trackId. Drag-drop already funnels through
  showImportSheet. didSelect skips
  organizeAlternateGroups/inferMediaCharacteristics on MKV docs —
  same TrackEntry-pairing protection as delete.
- Document: the tagsChanged check already caught additions; the
  post-remux snapshot now appends the added tracks behind the kept
  ones, matching the TrackEntry order in the written file, so a
  later tags-only save pairs correctly instead of double-appending.
- ScriptCommand: the AppleScript "save as" command called
  mp4.write(to:) directly, which muxed a QuickTime MP4 over a
  Matroska document. Route isMatroska documents through
  Document.save(saveAsOperation) so writeMatroska picks the
  tag-writer/remux path and enforces the mkv destination.

Verified with the /tmp/subler-mkv-test harness (matrix PASS=276: add
srt/ass, add+drop mix, no-cues source, bad-file and drop-all
refusals, idempotent re-save, post-add tag edit) and against the
live app (scripted import + save on a fixture copy; output checked
with mkvmerge/mkvextract/ffmpeg and reopened cleanly).

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
Scott GarrettandClaude Code committed 2026-11-26 11:53:50 -05:00
1 parent eb386a52c3
commit 330236735d
5 files changed
+125 -18

No files matched your search

+22 -3
View File
@@ -342,15 +342,34 @@ class SBSaveAsScriptCommand: NSScriptCommand, ScriptCommandDocumentTargeting {
logger.write(toLog: "No document available for save as operation")
return nil
}
// Use the helper method to extract the destination path
guard let path = extractFilePath() else {
return nil
}
let destinationURL = URL(fileURLWithPath: path)
let fileName = destinationURL.lastPathComponent
// mp4.write(to:) below muxes QuickTime atoms and would happily write
// an MP4 over a Matroska document, so route those through NSDocument
// instead: that picks the tag-writer/remux path in writeMatroska,
// enforces the mkv/mka/mks destination, does the fileURL/change-count
// bookkeeping, and reports progress itself via Document.save.
if sublerDoc.isMatroska {
// "Matroska video" is the CFBundleTypeName covering mkv/mka/mks
// (NSDocument.documentType is unavailable from Swift; writeSafely
// only re-checks the destination extension itself).
sublerDoc.save(to: destinationURL, ofType: "Matroska video", for: .saveAsOperation) { error in
if let error = error {
logger.write(toLog: "Failed to save document: \(error.localizedDescription)")
} else {
logger.write(toLog: "Script save of \(fileName) completed")
}
}
return path
}
// Build options dictionary with 64-bit settings from UI preferences
var options: [String: Any] = [:]
options[MP4264BitData] = Prefs.mp464bitOffset