refactor(tracks): name and match resolutions by one standard-height rule

standard_resolution() replaces the aspect-ratio logic in naming and is shared by -q matching, export names and progress/hybrid labels, so 1920x1088, 1916x1076, portrait and DCI sizes get standard names.
This commit is contained in:
imSp4rky
2026-10-31 22:05:26 -06:00
parent d5a8ed2a39
commit 86f26c31d5
13 changed files with 190 additions and 84 deletions
-1
View File
@@ -76,7 +76,6 @@ def test_codec_names_renames_video_and_each_hdr_part(monkeypatch: pytest.MonkeyP
height=2160,
format="HEVC",
scan_type="Progressive",
other_display_aspect_ratio=["16:9"],
hdr_format_commercial="HDR10+",
hdr_format="Dolby Vision, Version 1.0, Profile 8.1",
transfer_characteristics=None,
-1
View File
@@ -32,7 +32,6 @@ def hdr_tag(
height=1080,
format="AV1",
scan_type="Progressive",
other_display_aspect_ratio=["16:9"],
hdr_format_commercial=commercial,
hdr_format=hdr_format,
hdr_format_profile=profile,
+4 -4
View File
@@ -418,7 +418,7 @@ def test_a_conversion_run_removes_its_rpus_so_the_next_base_makes_its_own(
monkeypatch.setattr(Hybrid, "level_6", level_6)
monkeypatch.setattr(hybrid_mod.console, "print", lambda *a, **k: None)
Hybrid([SimpleNamespace(id="b", path=base, height=2160, range=Video.Range.HDR10P)], "TEST")
Hybrid([SimpleNamespace(id="b", path=base, width=None, height=2160, range=Video.Range.HDR10P)], "TEST")
assert seen == {"stale_l6": False, "active_fraction": 0.9}
assert not (tmp_path / "RPU.bin").exists() and not (tmp_path / "RPU_L6.bin").exists()
@@ -446,8 +446,8 @@ def test_a_failed_resolution_removes_its_crop_edits_and_keeps_the_dv_files(
monkeypatch.setattr(Hybrid, "injecting", failed_inject)
monkeypatch.setattr(hybrid_mod.console, "print", lambda *a, **k: None)
videos = [
SimpleNamespace(id="b", path=tmp_path / "base.mkv", height=2160, range=Video.Range.HDR10),
SimpleNamespace(id="d", path=tmp_path / "dv.mkv", height=1080, range=Video.Range.DV),
SimpleNamespace(id="b", path=tmp_path / "base.mkv", width=None, height=2160, range=Video.Range.HDR10),
SimpleNamespace(id="d", path=tmp_path / "dv.mkv", width=None, height=1080, range=Video.Range.DV),
]
with pytest.raises(ValueError):
@@ -559,7 +559,7 @@ def test_hybrid_asks_for_hdr10plus_only_for_a_conversion_without_dv(
def test_the_hybrid_step_gets_the_base_alone_when_there_is_no_dv(tmp_path: Path) -> None:
base = SimpleNamespace(id="base", path=tmp_path / "base.mp4", height=2160, range=Video.Range.HDR10P)
base = SimpleNamespace(id="base", path=tmp_path / "base.mp4", width=None, height=2160, range=Video.Range.HDR10P)
tracks = hybrid_source_tracks(base, None) # type: ignore[arg-type]
+119
View File
@@ -0,0 +1,119 @@
"""Tests for the standard resolution in the filename context, the export name and -q matching."""
from __future__ import annotations
import types
from typing import Optional
import pytest
from unshackle.core.config import config
from unshackle.core.export_name import resolution
from unshackle.core.titles.movie import Movie
from unshackle.core.tracks import Video
from unshackle.core.tracks.tracks import at_resolution
from unshackle.core.utilities import standard_resolution
class DummyService:
pass
@pytest.fixture(autouse=True)
def clean_config(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(config, "tag_rules", [])
monkeypatch.setattr(config, "language_tags", {})
monkeypatch.setattr(config, "codec_names", {})
def quality(width: Optional[int], height: Optional[int], scan_type: str = "Progressive") -> str:
movie = Movie(id_="movie-0001", service=DummyService, name="The Film", year=2024, language="en")
video = types.SimpleNamespace(
width=width,
height=height,
format="AVC",
scan_type=scan_type,
hdr_format_commercial=None,
hdr_format=None,
transfer_characteristics="BT.709",
transfer_characteristics_original=None,
frame_rate="25.000",
)
media_info = types.SimpleNamespace(video_tracks=[video], audio_tracks=[])
return str(movie.build_base_template_context(media_info)["quality"])
@pytest.mark.parametrize(
("width", "height", "expected"),
[
(3840, 2160, 2160),
(1920, 1080, 1080),
(1280, 720, 720),
(2560, 1440, 1440),
(1920, 1088, 1080), # padded to a multiple of 16
(960, 544, 540),
(640, 368, 360),
(1916, 1076, 1080), # a few lines short
(3836, 2156, 2160),
(1920, 800, 1080), # scope crop
(1920, 1036, 1080), # flat crop
(3840, 1600, 2160),
(1280, 544, 720),
(4096, 2160, 2160), # DCI
(4096, 1716, 2160),
(2048, 858, 1080),
(1440, 1080, 1080), # 4:3 pillarbox
(960, 720, 720),
(720, 576, 576), # anamorphic SD
(704, 576, 576),
(720, 480, 480),
(854, 480, 480),
(1080, 1920, 1080), # portrait
(1080, 1350, 1080),
(720, 1280, 720),
(2560, 1080, 1080), # ultrawide
(3440, 1440, 1440),
(1600, 900, 900), # no standard height near it
],
)
def test_standard_resolution(width: int, height: int, expected: int) -> None:
assert standard_resolution(width, height) == expected
def test_a_picture_with_one_side_uses_it() -> None:
assert standard_resolution(None, 1088) == 1080
def test_a_picture_with_no_size_has_no_resolution() -> None:
assert standard_resolution(None, None) is None
def test_the_filename_quality_uses_the_standard_resolution() -> None:
assert quality(1920, 1088) == "1080p"
assert quality(1920, 800) == "1080p"
def test_an_interlaced_picture_keeps_the_i_suffix() -> None:
assert quality(1920, 1088, scan_type="Interlaced") == "1080i"
def test_a_video_track_with_no_size_gives_an_empty_quality() -> None:
assert quality(None, None) == ""
def video(width: int, height: int) -> Video:
return Video(url="https://example.test/v.mpd", language="en", codec=Video.Codec.AVC, width=width, height=height)
def test_the_export_name_uses_the_standard_resolution() -> None:
assert resolution(video(1080, 1920)) == 1080
assert resolution(video(4096, 2160)) == 2160
@pytest.mark.parametrize(("width", "height"), [(1920, 1080), (1920, 800), (1916, 1076), (1920, 1088)])
def test_q_1080_matches_odd_1080p_encodes(width: int, height: int) -> None:
assert at_resolution(video(width, height), 1080)
def test_q_1080_does_not_match_720p() -> None:
assert not at_resolution(video(1280, 720), 1080)
-1
View File
@@ -104,7 +104,6 @@ def test_a_quality_rule_matches_the_built_context(monkeypatch: pytest.MonkeyPatc
height=2160,
format="HEVC",
scan_type="Progressive",
other_display_aspect_ratio=["16:9"],
hdr_format_commercial=None,
hdr_format=None,
transfer_characteristics=None,