fix(dl): name no cdm system in the remote status line of a whole-file cipher title

This commit is contained in:
imSp4rky
2026-11-27 10:16:40 -07:00
parent b719c44679
commit 5500440eb9
2 changed files with 61 additions and 2 deletions
+54 -1
View File
@@ -15,7 +15,7 @@ from tests.lang_selection import test_kind_only_selection as harness
from tests.lang_selection.test_kind_only_selection import FakeService from tests.lang_selection.test_kind_only_selection import FakeService
from tests.remote.key_source import MemoryKeySource, remote_keys from tests.remote.key_source import MemoryKeySource, remote_keys
from unshackle.commands import dl as dl_module from unshackle.commands import dl as dl_module
from unshackle.core.drm import PlayReady, Widevine from unshackle.core.drm import BlowfishStripe, ClearKeyCTR, PlayReady, Widevine
from unshackle.core.drm.cenc import drm_stub from unshackle.core.drm.cenc import drm_stub
from unshackle.core.import_service import ImportService from unshackle.core.import_service import ImportService
from unshackle.core.service import Service from unshackle.core.service import Service
@@ -158,6 +158,59 @@ def test_dl_licenses_with_no_cdm_of_its_own_when_the_keys_arrive_from_the_source
assert (source.closed, saved) == (1, []) assert (source.closed, saved) == (1, [])
class CipheredSource(KeyedSource):
"""A server-keyed source whose video and audio tracks carry the DRM of ``drm``."""
def __init__(self, drm: dict[str, Any], server_cdm_type: str) -> None:
super().__init__(KeyArrival.SERVER)
self.drm = drm
self.keys.server_cdm_type = server_cdm_type
def get_tracks(self, title: Any) -> Any:
tracks = super().get_tracks(title)
for track in tracks:
track.drm = self.drm.get(track.id)
return tracks
def ctr() -> ClearKeyCTR:
return ClearKeyCTR(licence=None, iv=bytes(16), magic=b"EX")
@pytest.mark.parametrize(
("drm", "server_cdm_type", "line"),
[
({"v": [ctr()], "a": [ctr()]}, "widevine", "Using keys from the server; no local CDM required"),
(
{"v": [BlowfishStripe(key=bytes(8))], "a": [ctr()]},
"playready",
"Using keys from the server; no local CDM required",
),
({"a": [ctr()]}, "widevine", "Using server CDM (Widevine); no local CDM required"),
(
{"v": [drm_stub("widevine", KIDS)], "a": [ctr()]},
"widevine",
"Using server CDM (Widevine); no local CDM required",
),
({"v": [drm_stub("playready", KIDS)]}, "playready", "Using server CDM (PlayReady); no local CDM required"),
],
ids=["whole-file", "whole-file-playready-server", "video-drm-not-loaded", "mixed", "playready"],
)
def test_dl_names_the_server_cdm_only_for_a_title_that_needs_one(
monkeypatch: pytest.MonkeyPatch,
caplog: pytest.LogCaptureFixture,
drm: dict[str, Any],
server_cdm_type: str,
line: str,
) -> None:
lines: list[str] = []
monkeypatch.setattr(logging.getLogger("test_kind_only"), "info", lambda msg, *a, **k: lines.append(msg))
monkeypatch.setattr(dl_module.login, "save_cookies", lambda *a: None)
source = CipheredSource(drm, server_cdm_type)
assert harness.run(monkeypatch, caplog, {1: {}}, service=source, to_end=True, skip_dl=True) is None
assert [msg for msg in lines if "no local CDM required" in msg] == [line]
def test_dl_saves_the_login_cookies_of_a_service( def test_dl_saves_the_login_cookies_of_a_service(
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture, tmp_path: Path monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture, tmp_path: Path
) -> None: ) -> None:
+7 -1
View File
@@ -50,6 +50,7 @@ from unshackle.core.downloaders import (
set_speed_limit, set_speed_limit,
) )
from unshackle.core.drm import ( from unshackle.core.drm import (
WHOLE_FILE_DRM,
MonaLisa, MonaLisa,
cbcs, cbcs,
own_kids, own_kids,
@@ -2113,8 +2114,13 @@ class dl:
self.cdm = cdm_type_stub(server_cdm_type) self.cdm = cdm_type_stub(server_cdm_type)
if self._remote_service.key_arrival is KeyArrival.EXPORT: if self._remote_service.key_arrival is KeyArrival.EXPORT:
self.log.info("Using keys from the export; no CDM required") self.log.info("Using keys from the export; no CDM required")
elif (keyed := [*title.tracks.videos, *title.tracks.audio]) and all(
track.drm and all(isinstance(drm, WHOLE_FILE_DRM) for drm in track.drm) for track in keyed
):
self.log.info("Using keys from the server; no local CDM required")
else: else:
self.log.info(f"Using server CDM ({server_cdm_type.title()}); no local CDM required") server_system = "PlayReady" if server_cdm_type == "playready" else "Widevine"
self.log.info(f"Using server CDM ({server_system}); no local CDM required")
video_tracks = title.tracks.videos video_tracks = title.tracks.videos
if video_tracks and not server_cdm_type: if video_tracks and not server_cdm_type: