mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-16 05:55:09 +00:00
fix(tracks): rank video picks by quality across regional tags and in hybrid
One video language request that matches several regional tags now gives one video, the best of them; hybrid bases and the DV source use the same pick, and hybrid --worst no longer needs -q. Thanks to reel.deal for the report and the first patch.
This commit is contained in:
@@ -11,7 +11,7 @@ from typing import Any
|
||||
import pytest
|
||||
from langcodes import Language
|
||||
|
||||
from unshackle.commands.dl import dl, hybrid_plan, pick_video
|
||||
from unshackle.commands.dl import dl, hybrid_plan
|
||||
from unshackle.core import binaries
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.drm.verify import decrypter_for
|
||||
@@ -19,6 +19,7 @@ from unshackle.core.manifests import DASH, HLS
|
||||
from unshackle.core.titles.movie import Movie
|
||||
from unshackle.core.tracks import Audio, Chapter, Chapters, Track, Tracks, Video
|
||||
from unshackle.core.tracks import tracks as tracks_module
|
||||
from unshackle.core.tracks.tracks import pick_video
|
||||
|
||||
VIDEO_IDS = itertools.count()
|
||||
|
||||
|
||||
@@ -2,33 +2,32 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.lang_selection import test_kind_only_selection as harness
|
||||
from unshackle.core import binaries
|
||||
from unshackle.core.titles import Episode
|
||||
from unshackle.core.tracks import Tracks, Video
|
||||
|
||||
LADDER = [
|
||||
("1080-hi", 1920, 1080, 6_000_000),
|
||||
("1080-lo", 1920, 1080, 3_000_000),
|
||||
("1080-unknown", 1920, 1080, None),
|
||||
("540", 960, 540, 900_000),
|
||||
("270-lo", 480, 270, 79_000),
|
||||
("240-hi", 320, 240, 153_000),
|
||||
("240-lo", 320, 240, 140_000),
|
||||
("240-unknown", 320, 240, None),
|
||||
("1080-hi", Video.Range.SDR, 1920, 1080, 6_000_000),
|
||||
("1080-lo", Video.Range.SDR, 1920, 1080, 3_000_000),
|
||||
("1080-unknown", Video.Range.SDR, 1920, 1080, None),
|
||||
("540", Video.Range.SDR, 960, 540, 900_000),
|
||||
("270-lo", Video.Range.SDR, 480, 270, 79_000),
|
||||
("240-hi", Video.Range.SDR, 320, 240, 153_000),
|
||||
("240-lo", Video.Range.SDR, 320, 240, 140_000),
|
||||
("240-unknown", Video.Range.SDR, 320, 240, None),
|
||||
]
|
||||
|
||||
|
||||
class LadderService(harness.FakeService):
|
||||
"""The harness episode with the video ladder above; a track with no bitrate is never the worst."""
|
||||
"""The harness episode with a video ladder of one codec; a track with no bitrate is never the worst."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, ladder: list[tuple[Any, ...]] = LADDER, codec: Video.Codec = Video.Codec.AVC) -> None:
|
||||
super().__init__({1: {}})
|
||||
self.ladder, self.codec = ladder, codec
|
||||
|
||||
def get_tracks(self, title: Episode) -> Tracks:
|
||||
tracks = super().get_tracks(title)
|
||||
@@ -37,13 +36,13 @@ class LadderService(harness.FakeService):
|
||||
id_=id_,
|
||||
url=f"https://x/{id_}",
|
||||
language="en",
|
||||
codec=Video.Codec.AVC,
|
||||
range_=Video.Range.SDR,
|
||||
codec=self.codec,
|
||||
range_=range_,
|
||||
width=width,
|
||||
height=height,
|
||||
bitrate=bitrate,
|
||||
)
|
||||
for id_, width, height, bitrate in LADDER
|
||||
for id_, range_, width, height, bitrate in self.ladder
|
||||
]
|
||||
return tracks
|
||||
|
||||
@@ -64,10 +63,25 @@ def test_worst_picks_the_lowest_bitrate_of_the_quality_or_of_the_lowest_resoluti
|
||||
assert ids["video"] == expected
|
||||
|
||||
|
||||
def test_worst_in_hybrid_mode_needs_a_quality(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
HDR_LADDER = [
|
||||
("hdr-2160", Video.Range.HDR10, 3840, 2160, 15_000_000),
|
||||
("hdr-1080-hi", Video.Range.HDR10, 1920, 1080, 6_000_000),
|
||||
("hdr-1080-lo", Video.Range.HDR10, 1920, 1080, 4_000_000),
|
||||
("hdr-1080-unknown", Video.Range.HDR10, 1920, 1080, None),
|
||||
("dv-1080", Video.Range.DV, 1920, 1080, 5_000_000),
|
||||
("dv-540", Video.Range.DV, 960, 540, 1_000_000),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"flags",
|
||||
[{}, {"quality": [1080]}, {"quality": [4320], "best_available": True}],
|
||||
ids=["no-quality", "quality", "best-available"],
|
||||
)
|
||||
def test_worst_in_hybrid_mode_takes_the_lowest_bitrate_base_of_the_lowest_base_height(
|
||||
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture, flags: dict[str, Any]
|
||||
) -> None:
|
||||
monkeypatch.setattr(binaries, "DoviTool", Path("dovi_tool"))
|
||||
code = harness.run(monkeypatch, caplog, {1: {}}, service=LadderService(), worst=True, range_=[Video.Range.HYBRID])
|
||||
assert code == 1
|
||||
assert "--worst requires -q/--quality to be specified in hybrid mode" in caplog.text
|
||||
harness.stub_hybrid(monkeypatch)
|
||||
service = LadderService(HDR_LADDER, Video.Codec.HEVC)
|
||||
ids = harness.run(monkeypatch, caplog, {1: {}}, service=service, worst=True, range_=[Video.Range.HYBRID], **flags)
|
||||
assert ids["video"] == ["hdr-1080-lo", "dv-540"]
|
||||
|
||||
Reference in New Issue
Block a user