forked from kenzuya/unshackle
feat(hls): use the DRM of the track when no key tag can be licensed
This commit is contained in:
@@ -706,6 +706,11 @@ class HLS:
|
||||
if ctx.on_segments:
|
||||
ctx.on_segments(track, wanted_segments)
|
||||
|
||||
if track.drm and HLS.drop_unsupported_keys(master):
|
||||
log.debug(
|
||||
f"{track.id}: its key tags name key systems unshackle cannot license, using the DRM of the service"
|
||||
)
|
||||
|
||||
# Get session DRM as fallback but prefer media playlist keys for accurate KID matching
|
||||
if track.drm:
|
||||
session_drm = track.get_drm_for_cdm(cdm)
|
||||
@@ -1465,6 +1470,21 @@ class HLS:
|
||||
else:
|
||||
raise NotImplementedError(f"None of the key systems are supported: {', '.join(unsupported_systems)}")
|
||||
|
||||
@staticmethod
|
||||
def drop_unsupported_keys(manifest: M3U8) -> bool:
|
||||
"""Remove every EXT-X-KEY of `manifest` when each one names a DRM system unshackle cannot license; True when it did.
|
||||
|
||||
A service can license such a playlist another way, with the DRM it puts on the track. The download then
|
||||
reads the playlist as one without an EXT-X-KEY, and the track keeps that DRM.
|
||||
"""
|
||||
keys = [key for key in (manifest.keys or []) if key is not None]
|
||||
if not keys or any(key.method in ("NONE", "AES-128") or cenc_key(key) for key in keys):
|
||||
return False
|
||||
manifest.keys = []
|
||||
for segment in manifest.segments:
|
||||
segment.keys = []
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def get_drm(
|
||||
key: m3u8.model.SessionKey | m3u8.model.Key,
|
||||
|
||||
Reference in New Issue
Block a user