mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-05 07:25:08 +00:00
refactor(drm): hand the server key batch to one installer as a KeyBatch value
This commit is contained in:
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from functools import partial
|
||||
from http.cookiejar import CookieJar
|
||||
@@ -55,6 +56,33 @@ class CacheIdentity(NamedTuple):
|
||||
account_hash: str | None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class HeldKeys:
|
||||
"""The content keys a server key source holds for one track, where each came from, and the DRM they go on.
|
||||
|
||||
A content key whose KID is in ``vault_kids`` came from a server vault and stays unproven until a decode passes;
|
||||
any other came from a licence. The content keys go on a stub of ``system`` that names ``kids``, a FairPlay
|
||||
bridge stub when ``bridged``, or on the track's own DRM when ``own_drm`` and the track has one. ``file_key``
|
||||
is the content key of a whole-file cipher.
|
||||
"""
|
||||
|
||||
keys: dict[UUID, str] = field(default_factory=dict)
|
||||
vault_kids: frozenset[UUID] = frozenset()
|
||||
system: str = "widevine"
|
||||
kids: tuple[UUID, ...] = ()
|
||||
bridged: bool = False
|
||||
own_drm: bool = False
|
||||
file_key: str | None = None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class KeyBatch:
|
||||
"""The content keys of the tracks of one title by track id, and the ids of the tracks asked for keys that got none."""
|
||||
|
||||
tracks: dict[str, HeldKeys] = field(default_factory=dict)
|
||||
unanswered: frozenset[str] = frozenset()
|
||||
|
||||
|
||||
class ServerKeySource(Protocol):
|
||||
"""A title source whose content keys dl gets before ``prepare_drm``: a remote session or an import."""
|
||||
|
||||
@@ -70,13 +98,13 @@ class ServerKeySource(Protocol):
|
||||
def local_cdm(self) -> Any:
|
||||
"""The CDM of this machine for a track ``licenses_locally`` names, or None."""
|
||||
|
||||
def resolve_server_keys(self, title: Title_T) -> None:
|
||||
"""Put the content keys the server or the export holds on the tracks of ``title``."""
|
||||
def batch_keys(self, title: Title_T) -> KeyBatch:
|
||||
"""The content keys the server or the export holds for the tracks of ``title``."""
|
||||
|
||||
def licenses_locally(self, track: AnyTrack) -> bool:
|
||||
"""True when this machine's own CDM licenses ``track`` instead of the server."""
|
||||
|
||||
def license_track(self, track: AnyTrack, drm: Any, kid: UUID | None = None) -> dict[UUID, str] | None:
|
||||
def license_track(self, track: AnyTrack, drm: Any, kid: UUID | None = None) -> HeldKeys | None:
|
||||
"""The content keys the server licenses for ``drm`` of ``track``, or None when it hands ``track`` to this machine's CDM.
|
||||
|
||||
Call it only for a track ``licenses_locally`` does not name; after None, it names the track. ``kid`` is
|
||||
@@ -87,9 +115,6 @@ class ServerKeySource(Protocol):
|
||||
def license_file(self, track: AnyTrack) -> str:
|
||||
"""The content key the server licenses for the whole-file cipher of ``track``; a refusal raises."""
|
||||
|
||||
def vault_source(self, kid: UUID, key: str) -> ServerVault | None:
|
||||
"""The server vault when it served ``key`` for ``kid``, else None. That content key must pass a decrypt check."""
|
||||
|
||||
@property
|
||||
def server_vault(self) -> ServerVault | None:
|
||||
"""The server's vaults, which take the content keys a decrypt proved, or None."""
|
||||
|
||||
Reference in New Issue
Block a user