fix(hls): bridge a FairPlay playlist whose clear part has a METHOD=NONE tag and its own init segment

This commit is contained in:
imSp4rky
2026-12-01 18:32:31 -07:00
parent f680df7eff
commit e0880812d5
4 changed files with 121 additions and 10 deletions
+22 -5
View File
@@ -1528,10 +1528,10 @@ class HLS:
The pssh boxes count only in a one-key playlist, and with several init segments only as `get_stitched_kid` reads
them: an all-zero tenc takes any content key.
"""
keyed = [span for span in key_spans(manifest, segments) if span.init_section and span.keys]
keyed = [span for span in key_spans(manifest, segments) if span.init_section and HLS.encrypts(span.keys)]
if not keyed or not HLS.only_unsupported_keys(manifest):
return None
one_key = len({key.uri for key in manifest.keys if key}) == 1
one_key = len({key.uri for key in manifest.keys if key and key.method != "NONE"}) == 1
if any(b.init_section != a.init_section and not b.discontinuity for a, b in pairwise(segments)):
return None
init_sections: list[m3u8.model.InitializationSection] = []
@@ -1582,10 +1582,27 @@ class HLS:
def only_unsupported_keys(manifest: M3U8) -> bool:
"""Whether each EXT-X-KEY of `manifest`, at least one, is sample encryption of a DRM system unshackle cannot license.
Any other METHOD, such as AES-128 or AES-256, makes it false.
A METHOD=NONE tag also counts, unless a segment under it shares its init segment with an encrypted segment: a
decrypter that reads the encrypted init segment treats the clear samples as encrypted. Any other METHOD, such as
AES-128 or AES-256-GCM, makes it false. An identity KEYFORMAT, or none, names no DRM system, so each encrypted
segment also needs a tag with another KEYFORMAT.
"""
keys = [key for key in (manifest.keys or []) if key is not None]
return bool(keys) and all(key.method in ("SAMPLE-AES", "SAMPLE-AES-CTR") and not cenc_key(key) for key in keys)
keys = [key for key in (manifest.keys or []) if key is not None and key.method != "NONE"]
if not keys or not all(key.method in ("SAMPLE-AES", "SAMPLE-AES-CTR") and not cenc_key(key) for key in keys):
return False
spans = key_spans(manifest, manifest.segments)
clear_inits = [span.init_section for span in spans if any(key.method == "NONE" for key in span.keys if key)]
return all(
span.init_section not in clear_inits
and any((key.keyformat or "identity").lower() != "identity" for key in span.keys if key)
for span in spans
if HLS.encrypts(span.keys)
)
@staticmethod
def encrypts(keys: list[m3u8.model.Key]) -> bool:
"""Whether `keys` hold an EXT-X-KEY with a METHOD other than NONE."""
return any(key.method != "NONE" for key in keys if key)
@staticmethod
def drop_unsupported_keys(manifest: M3U8) -> bool: