Disc title order: main feature first on branching UHDs

Disc::titles previously sorted purely by duration_secs descending,
which puts a play-all virtual playlist at index 0 on UHDs that ship
one. Such playlists reference the same source clips multiple times
for seamless alternate-angle / alternate-ending playback and report
inflated duration AND inflated size_bytes that exceeds the disc's
physical capacity.

Concrete observed case (The Amateur 2025 4K UHD, 58.5 GB BD-100):
  Title 1 — 00020.mpls — 4h13m — 92.4 GB — 253 clips  ← impossible
  Title 2 — 00800.mpls — 2h02m — 57.2 GB — 1 clip      ← the movie

92.4 GB > 58.5 GB capacity is proof of clip double-counting. With
the duration-only sort, freemkv -t 1 / disc.titles.first() / autorip's
main-feature picker all selected the 4-hour composite instead of the
2-hour movie.

New canonical_title_order:
  1. Real titles (size_bytes <= capacity_bytes) before virtual
     composites — capacity gate is hard physical truth.
  2. Among real titles, fewer clips first (1-clip wins as the
     canonical main feature; multi-clip is either chapter-stitched
     or composite).
  3. Tiebreak on longer duration first.

Behaviour:
- Non-branching discs: unchanged. The longest 1-clip title is
  already the movie.
- Branching UHDs: virtual composite drops to the back, the real
  movie surfaces at index 0.

Comparator exposed as Disc::canonical_title_order for downstream
consumers that need the same logic on custom title sets.

Three regression tests (disc::tests::canonical_order_*):
- pushes_oversize_play_all_behind_real_main (The Amateur)
- preserves_natural_ranking_on_normal_disc
- fewer_clips_wins_tiebreak
This commit is contained in:
2026-05-09 19:57:07 -07:00
parent 4700878b73
commit 518c5293c8
2 changed files with 164 additions and 5 deletions
+34
View File
@@ -1,5 +1,39 @@
# Changelog
## Unreleased — 0.18.3
### Behaviour change
- **`Disc::titles[0]` is now the canonical main feature on branching
discs, not the longest playlist.** Previously titles were sorted
purely by `duration_secs` descending, which puts a "play-all"
virtual playlist (alternate angles / seamless branching) at index 0
on UHDs that ship one — its inflated duration overshoots the real
movie. Concrete example: *The Amateur (2025)* 4K UHD on a 58.5 GB
disc has Title 1 = `00020.mpls` 4h13m / 92.4 GB / 253 clips
(impossible — the size exceeds the disc capacity, proving it's a
virtual composite) and Title 2 = `00800.mpls` 2h02m / 57.2 GB /
1 clip (the actual film, matching TMDB).
New sort priority:
1. Real titles (`size_bytes <= capacity_bytes`) before virtual
composites.
2. Among real titles, fewer clips first (1-clip wins).
3. Tiebreak on longer duration first.
**Migration:** consumers calling `disc.titles.first()` /
`disc.titles[0]` automatically get the corrected title — no code
changes needed. CLI users invoking `freemkv -t 1 disc:// …` now hit
the actual main feature on branching discs (this was the user-
visible bug). On non-branching discs the order is unchanged.
The comparator is exposed as
[`Disc::canonical_title_order`](#) for callers that need to
re-sort a custom title set with the same logic.
Regression tests: `disc::tests::canonical_order_*` (three cases:
branching-UHD, normal disc, clip-count tiebreak).
## 0.18.2 (2026-05-09)
### Bug fixes