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:
1 parent
eb386a52c3
commit
330236735d
5 files changed
+125
-18
No files matched your search
+15
-7
@@ -308,13 +308,15 @@ final class Document: NSDocument {
|
||||
}
|
||||
|
||||
let currentTracks = mp4.tracks.filter { $0.isMember(of: MP42ChapterTrack.self) == false }
|
||||
// Structural change == some importer-created track is gone. Tracks are
|
||||
// paired by object identity, so a reordered (impossible: reorder is
|
||||
// gated on MKV docs) or merely renamed track still compares equal.
|
||||
let tracksRemoved = currentTracks.count != mkvSourceTracks.count ||
|
||||
// Structural change == some importer-created track is gone, or the
|
||||
// model carries a track the importer never produced (an imported
|
||||
// subtitle). Tracks are paired by object identity, so a reordered
|
||||
// (impossible: reorder is gated on MKV docs) or merely renamed track
|
||||
// still compares equal.
|
||||
let tracksChanged = currentTracks.count != mkvSourceTracks.count ||
|
||||
currentTracks.contains { track in mkvSourceTracks.contains(where: { $0 === track }) == false }
|
||||
|
||||
if tracksRemoved || saveOperation != .saveOperation {
|
||||
if tracksChanged || saveOperation != .saveOperation {
|
||||
try remuxMatroska(to: url, currentTracks: currentTracks)
|
||||
return
|
||||
}
|
||||
@@ -355,10 +357,16 @@ final class Document: NSDocument {
|
||||
sourceTracks: mkvSourceTracks, currentTracks: currentTracks)
|
||||
mkvRemuxer = nil
|
||||
// The output keeps the surviving TrackEntry elements in source file
|
||||
// order, so re-snapshot the pairing baseline in that same order.
|
||||
// order and appends one TrackEntry per added subtitle track last
|
||||
// (MP42MkvRemuxer), so re-snapshot the pairing baseline in that same
|
||||
// order — otherwise the appended track would look "added" again on
|
||||
// the next save and the TrackEntry count would mispair.
|
||||
let addedTracks = currentTracks.filter { track in
|
||||
mkvSourceTracks.contains(where: { $0 === track }) == false
|
||||
}
|
||||
mkvSourceTracks = mkvSourceTracks.filter { track in
|
||||
currentTracks.contains(where: { $0 === track })
|
||||
}
|
||||
} + addedTracks
|
||||
snapshotMatroskaFile(at: url)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user