fix(drm): end a licence with no usable key in one line for every DRM system

This commit is contained in:
imSp4rky
2026-11-24 17:13:08 -07:00
parent d954f61100
commit 4692e6bb96
6 changed files with 69 additions and 19 deletions
+3 -2
View File
@@ -6,6 +6,7 @@ from pathlib import Path
from typing import Any, Callable, Iterable, Optional, Union
from uuid import UUID
import click
from requests import Session
from unshackle.core.config import config
@@ -192,10 +193,10 @@ class ClearKeyCENC:
class KIDNotFound(Exception):
"""KID (Encryption Key ID) was not found."""
class CEKNotFound(Exception):
class CEKNotFound(click.ClickException):
"""CEK (Content Encryption Key) for KID was not found in License."""
class EmptyLicense(Exception):
class EmptyLicense(click.ClickException):
"""License returned no Content Encryption Keys."""
+12 -3
View File
@@ -7,6 +7,7 @@ from threading import Lock
from typing import Any, Callable, Optional, Union
from uuid import UUID
import click
import m3u8
from construct import Container
from pymp4.parser import Box
@@ -491,7 +492,15 @@ class PlayReady:
except ValueError:
pass
cdm.parse_license(session_id, license_str)
try:
cdm.parse_license(session_id, license_str)
except Exception as e:
if self.detect_revocation(license_str) or self.detect_revocation(str(e)):
raise
kids = ", ".join(kid.hex for kid in required_kids)
raise PlayReady.Exceptions.EmptyLicense(
f"No usable PlayReady licence for KID {kids}: {e}"
) from e
log_event(
"drm_license_response",
level="DEBUG",
@@ -561,10 +570,10 @@ class PlayReady:
class KIDNotFound(Exception):
pass
class CEKNotFound(Exception):
class CEKNotFound(click.ClickException):
pass
class EmptyLicense(Exception):
class EmptyLicense(click.ClickException):
pass
class DeviceRevoked(Exception):
+6 -7
View File
@@ -10,7 +10,6 @@ import m3u8
from construct import Container
from pymp4.parser import Box
from pywidevine.cdm import Cdm as WidevineCdm
from pywidevine.exceptions import InvalidLicenseMessage
from pywidevine.pssh import PSSH
from unshackle.core.config import config
@@ -251,10 +250,10 @@ class Widevine:
license_res = call_licence(licence, challenge, pssh=self.pssh, session_id=session_id)
try:
cdm.parse_license(session_id, license_res)
except InvalidLicenseMessage:
raise click.ClickException(
f"The licence server sent no usable Widevine licence for KID {kid.hex}"
) from None
except Exception as e:
raise Widevine.Exceptions.EmptyLicense(
f"No usable Widevine licence for KID {kid.hex}: {e}"
) from e
log_event(
"drm_license_response",
level="DEBUG",
@@ -318,10 +317,10 @@ class Widevine:
class KIDNotFound(Exception):
"""KID (Encryption Key ID) was not found."""
class CEKNotFound(Exception):
class CEKNotFound(click.ClickException):
"""CEK (Content Encryption Key) for KID was not found in License."""
class EmptyLicense(Exception):
class EmptyLicense(click.ClickException):
"""License returned no Content Encryption Keys."""