forked from kenzuya/unshackle
feat(hls): license a FairPlay-only SAMPLE-AES playlist through a PlayReady or Widevine CDM
This commit is contained in:
@@ -22,13 +22,14 @@ from requests import Session
|
||||
from requests.adapters import HTTPAdapter, Retry
|
||||
|
||||
from unshackle.core import binaries
|
||||
from unshackle.core.cdm.choice import SYSTEMS
|
||||
from unshackle.core.cdm.detect import is_playready_cdm, is_widevine_cdm
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.constants import DOWNLOAD_CANCELLED, DOWNLOAD_LICENCE_ONLY, DownloadCancelled
|
||||
from unshackle.core.downloaders.requests import requests
|
||||
from unshackle.core.drm import DRM_T, PlayReady, Widevine
|
||||
from unshackle.core.drm.cbcs import SampleDecrypter
|
||||
from unshackle.core.drm.cenc import cenc_key, init_kid
|
||||
from unshackle.core.drm.cenc import cenc_key, drm_stub, init_kid
|
||||
from unshackle.core.drm.verify import (
|
||||
children,
|
||||
find_child_box,
|
||||
@@ -993,10 +994,11 @@ class Track:
|
||||
|
||||
return self.load_drm_from_playlist()
|
||||
|
||||
def load_drm_from_playlist(self, session: Any = None) -> bool:
|
||||
def load_drm_from_playlist(self, session: Any = None, bridge: bool = False) -> bool:
|
||||
"""Load the Widevine and PlayReady DRM of the EXT-X-KEY and EXT-X-SESSION-KEY tags of this track's playlist.
|
||||
|
||||
It skips a tag that gives no DRM, and raises ValueError when the fetch fails or when every such tag fails.
|
||||
With ``bridge`` it builds both stubs for the key ID that ``HLS.get_bridge_kid`` finds when no tag gives a DRM.
|
||||
"""
|
||||
if self.drm:
|
||||
self.needs_drm_loading = False
|
||||
@@ -1024,12 +1026,18 @@ class Track:
|
||||
except Exception as e:
|
||||
logging.getLogger("track").debug(f"Skipping HLS key {key} of track {self.id}: {e!r}")
|
||||
error = e
|
||||
if error and not drm_list:
|
||||
raise ValueError(f"Failed to load DRM from playlist for track {self.id}: {error}")
|
||||
if bridge and not drm_list:
|
||||
segments = [
|
||||
s for s in playlist.segments if not (callable(self.OnSegmentFilter) and self.OnSegmentFilter(s))
|
||||
]
|
||||
if kid := HLS.get_bridge_kid(playlist, segments, self, session):
|
||||
drm_list = [drm_stub(system, [kid.hex]) for system in SYSTEMS]
|
||||
if drm_list:
|
||||
self.drm = drm_list
|
||||
self.needs_drm_loading = False
|
||||
return True
|
||||
if error:
|
||||
raise ValueError(f"Failed to load DRM from playlist for track {self.id}: {error}")
|
||||
return False
|
||||
|
||||
def get_init_segment(
|
||||
|
||||
Reference in New Issue
Block a user