feat(hls): license every content key of a FairPlay bridge playlist that rotates its key

This commit is contained in:
imSp4rky
2026-12-01 18:32:36 -07:00
parent e0880812d5
commit 41c2b3d86a
12 changed files with 478 additions and 76 deletions
+18 -7
View File
@@ -103,6 +103,8 @@ from unshackle.core.utils.service_params import service_options
from unshackle.core.wire import apply_tracks_reply, build_chapters, build_music, build_title
if TYPE_CHECKING:
from pywidevine.pssh import PSSH
from unshackle.core.remote_channel import Channel
from unshackle.core.remote_lifetime import RemoteSessionLifetime
@@ -1731,11 +1733,15 @@ class RemoteService(TitleSource):
with malformed_answer("chapters"):
return build_chapters(raw)
def get_widevine_license(self, *, challenge: bytes, title: Title_T, track: AnyTrack) -> bytes | str | None:
return self.proxy_license(challenge, track, "widevine")
def get_widevine_license(
self, *, challenge: bytes, title: Title_T, track: AnyTrack, pssh: PSSH | None = None
) -> bytes | str | None:
return self.proxy_license(challenge, track, "widevine", pssh.dumps() if pssh else None)
def get_playready_license(self, *, challenge: bytes, title: Title_T, track: AnyTrack) -> bytes | str | None:
return self.proxy_license(challenge, track, "playready")
def get_playready_license(
self, *, challenge: bytes, title: Title_T, track: AnyTrack, pssh_b64: str | None = None
) -> bytes | str | None:
return self.proxy_license(challenge, track, "playready", pssh_b64)
def get_widevine_service_certificate(
self,
@@ -1859,12 +1865,17 @@ class RemoteService(TitleSource):
raise click.ClickException(f"The server sent no URL for track {track.id}")
return str(url)
def proxy_license(self, challenge: bytes | str, track: AnyTrack, drm_type: str) -> bytes:
"""Relay a licence challenge to the server. A failed relay raises ClickException, so dl's licence fallbacks see it."""
def proxy_license(
self, challenge: bytes | str, track: AnyTrack, drm_type: str, pssh_b64: str | None = None
) -> bytes:
"""Relay a licence challenge and the PSSH of its header, by default the track's first, to the server.
A failed relay raises ClickException, so dl's licence fallbacks see it.
"""
if isinstance(challenge, str):
challenge = challenge.encode("utf-8")
pssh_b64 = track_pssh(track, drm_type)
pssh_b64 = pssh_b64 or track_pssh(track, drm_type)
payload = LicenseRequest(challenge=base64.b64encode(challenge).decode("ascii"), drm_type=drm_type)
if pssh_b64: