feat(dl): let a service force --license-first with the LICENSE_FIRST class variable

This commit is contained in:
imSp4rky
2026-12-05 20:23:47 -07:00
parent ce7cb41eac
commit bd178bc3af
18 changed files with 59 additions and 5 deletions
+16
View File
@@ -128,6 +128,22 @@ def test_without_the_flag_a_track_downloads_before_a_later_licence_fails(
assert run.fetched == ["Video_video.mp4"], result.output
def test_a_service_with_license_first_licenses_every_track_with_no_flag(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
from unshackle.core import services
monkeypatch.setattr(services.ensure_loaded("EXAMPLE"), "LICENSE_FIRST", True)
run = Run(monkeypatch, tmp_path, refuse="audio")
result = run()
assert "Licence refused for track audio" in result.output
assert result.exit_code == 1
assert run.licences == ["video", "audio"]
assert run.fetched == []
def test_the_download_pass_sends_no_second_licence(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
run = Run(monkeypatch, tmp_path)
+16
View File
@@ -46,6 +46,7 @@ class StubService:
A test puts extra service work in ``hooks``: "titles" runs inside get_titles, on the service thread.
"""
LICENSE_FIRST = False
logins = 0
hooks: dict[str, Callable[[StubService], None]] = {}
@@ -290,3 +291,18 @@ def test_server_request_records_never_reach_the_remote_client(
assert all("body" not in e["response"] for e in entries)
own = [e for e in entries if e["request"]["host"] == server_host and e["request"]["path"].endswith("/titles")]
assert own and all((tmp_path / "server" / e["response"]["body_file"]).is_file() for e in own)
@pytest.mark.parametrize("forced", [True, False])
def test_the_client_reports_the_license_first_of_the_served_service(
server: SimpleNamespace, monkeypatch: pytest.MonkeyPatch, forced: bool
) -> None:
monkeypatch.setattr(StubService, "LICENSE_FIRST", forced)
remote = make_client(server.url)
try:
remote.authenticate()
remote.get_tracks(remote.get_titles()[0])
finally:
remote.close()
assert remote.LICENSE_FIRST is forced
@@ -263,6 +263,8 @@ def test_the_tracks_response_names_the_system_of_the_loaded_device(monkeypatch,
monkeypatch.setattr(store_mod.bus, "publish", lambda topic, data: None)
class StubService:
LICENSE_FIRST = False
session = SimpleNamespace(headers={}, cookies=[])
ctx = SimpleNamespace(obj=SimpleNamespace(cdm=SimpleNamespace(is_playready=system == "playready")))
@@ -308,6 +310,7 @@ def _reply_then_licence(monkeypatch, track, drm_type, loaded=None):
"get_chapters": lambda self, title: [],
"decrypts_samples": lambda self, track: False,
"fairplay_bridge": lambda self: None,
"LICENSE_FIRST": False,
"get_widevine_service_certificate": lambda self, **k: None,
"get_widevine_license": lambda self, **k: b"",
"get_playready_license": lambda self, **k: b"",
@@ -116,6 +116,8 @@ def tracks_reply(client_plugins: Any) -> tuple[Any, Any]:
"""The answer of the tracks route for a title with an EXAMPLE plugin track (its body or its APIError), and the session."""
class StubService:
LICENSE_FIRST = False
session = SimpleNamespace(headers={}, cookies=[])
def fairplay_bridge(self) -> None:
@@ -110,6 +110,8 @@ def test_tracks_handler_marks_the_title_live_before_it_fetches(monkeypatch: pyte
monkeypatch.setattr(store_mod.bus, "publish", lambda topic, data: published.append((topic, data)))
class StubService:
LICENSE_FIRST = False
session = SimpleNamespace(headers={}, cookies=[])
def fairplay_bridge(self) -> None:
+2
View File
@@ -97,6 +97,8 @@ def call_session_handler(handler, body, service, **entry_fields):
class StubService:
LICENSE_FIRST = False
def __init__(self, tracks=(), cookies=()):
self.session = SimpleNamespace(headers={}, cookies=list(cookies))
self.tracks = list(tracks)