Skip to content

fix: add_track(str) no longer reuses the source file's mkvmerge info - #131

Merged
GitBib merged 3 commits into
masterfrom
fix/add-track-stale-info
Aug 2, 2026
Merged

fix: add_track(str) no longer reuses the source file's mkvmerge info#131
GitBib merged 3 commits into
masterfrom
fix/add-track-stale-info

Conversation

@GitBib

@GitBib GitBib commented Aug 2, 2026

Copy link
Copy Markdown
Owner

add_track(str) passed self._info_json — the mkvmerge -J output of the file MKVFile was built from — as existing_info for a track built from a different path. The track reported track 0 of the source file, so TrackOptions emitted --no-subtitles for an SRT and the track was dropped from the mux. It also skipped verify_supported.

Second commit: MKVTrack ran mkvmerge -J twice per construction, once in verify_supported and again in the track_id setter. _info_json now caches the single probe, tracked by the path it describes, so reassigning file_path refreshes the track instead of keeping the previous file's type and codec.

Fixes #123.

@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.12%. Comparing base (8bde76b) to head (0a58e51).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

GitBib added 2 commits August 2, 2026 16:47
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
GitBib force-pushed the fix/add-track-stale-info branch from aeb1cb0 to bb48b1b Compare August 2, 2026 13:47
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.
@GitBib
GitBib merged commit acf00ae into master Aug 2, 2026
25 checks passed
@GitBib
GitBib deleted the fix/add-track-stale-info branch August 2, 2026 13:52
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.

MKVFile.add_track(str) uses stale existing_info from the source file, producing wrong track metadata

1 participant