fix: add_track(str) no longer reuses the source file's mkvmerge info - #131
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #131 +/- ##
=======================================
Coverage 99.11% 99.12%
=======================================
Files 21 21
Lines 1477 1487 +10
=======================================
+ Hits 1464 1474 +10
Misses 13 13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
MKVFile.add_track passed self._info_json - the mkvmerge -J output of the
file the MKVFile was built from - as existing_info for a track created
from an unrelated path. MKVTrack then read metadata out of that JSON
instead of probing the file, and since track_id defaults to 0 the new
track reported track 0 of the original file:
mkv = MKVFile("file.mkv")
mkv.add_track("subtitle.srt")
mkv.tracks[-1].track_type # 'video' instead of 'subtitles'
Same line also suppressed verification: MKVTrack.file_path skips
verify_supported when _info_json is set, so any path was accepted.
Fixes #123
MKVTrack ran mkvmerge -J twice per construction. The file_path setter called verify_supported(), which fetches the info and returns only a bool, and the track_id setter then fetched the same JSON again because _info_json was still empty. The cause is that _info_json served two roles at once: cache of the probe, and flag for "caller supplied the info, skip verification". That same conflation produced #123. Split them with _info_path, the path the cached info describes: - the file_path setter probes once and keeps the output, so track_id has nothing left to fetch - pointing a track at a different file drops the cache, so the track always describes the file it currently points at - existing_info is trusted for the first assignment and stops being trusted once the path changes - verify_supported is replaced by info.container.supported, which is exactly what that function returns. checking_file_path already validated the path, so only the mkvmerge lookup remains, and it is cached This also fixes stale metadata on reassignment. Before, pointing a track at another file kept the previous file's type and codec, and skipped verification of the new path: t = MKVTrack("sub.srt") # subtitles t.file_path = "video.mkv" t.track_type # 'subtitles' — wrong 20 iterations of MKVFile + add_track + command: 1.56s -> 1.10s, with add_track itself halved from 1.01s to 0.53s. Tests dropped 20 patches of verify_supported in the MKVTrack namespace; they targeted a function that is no longer called and would have passed even with verification broken. test_track_file_path_setter_verification_failure now uses a real empty file, which mkvmerge reports as unsupported.
GitBib
force-pushed
the
fix/add-track-stale-info
branch
from
August 2, 2026 13:47
aeb1cb0 to
bb48b1b
Compare
Keeps MKVTrack.py at 100%: the FileNotFoundError for a bad mkvmerge_path and the track_id setter's fallback, which the file_path setter now makes unreachable in normal use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
add_track(str)passedself._info_json— themkvmerge -Joutput of the fileMKVFilewas built from — asexisting_infofor a track built from a different path. The track reported track 0 of the source file, soTrackOptionsemitted--no-subtitlesfor an SRT and the track was dropped from the mux. It also skippedverify_supported.Second commit:
MKVTrackranmkvmerge -Jtwice per construction, once inverify_supportedand again in thetrack_idsetter._info_jsonnow caches the single probe, tracked by the path it describes, so reassigningfile_pathrefreshes the track instead of keeping the previous file's type and codec.Fixes #123.