Only raise error if the Track's KID was not found when licensing

For ex., if a service has the same PSSH or license call for 720p and 1080p video tracks, but it doesn't return a KID for the 1080p track, then the previous code would return an error, even though it has enough content key data to continue.

With this change it now only raises the error if the track's exact KID was not licensed. This adds support to prepare_drm for specifying the track's KID.
This commit is contained in:
rlaphoenix 2023-03-08 22:41:13 +00:00
parent 73bd17ec94
commit 923cb71f81
1 changed files with 12 additions and 10 deletions

View File

@ -18,6 +18,7 @@ from http.cookiejar import MozillaCookieJar
from pathlib import Path from pathlib import Path
from threading import Event, Lock from threading import Event, Lock
from typing import Any, Callable, Optional from typing import Any, Callable, Optional
from uuid import UUID
import click import click
import jsonpickle import jsonpickle
@ -603,6 +604,7 @@ class dl:
title: Title_T, title: Title_T,
certificate: Callable, certificate: Callable,
licence: Callable, licence: Callable,
track_kid: Optional[UUID] = None,
table: Table = None, table: Table = None,
cdm_only: bool = False, cdm_only: bool = False,
vaults_only: bool = False, vaults_only: bool = False,
@ -634,11 +636,13 @@ class dl:
if kid in drm.content_keys: if kid in drm.content_keys:
continue continue
is_track_kid = ["", "*"][kid == track_kid]
if not cdm_only: if not cdm_only:
content_key, vault_used = self.vaults.get_key(kid) content_key, vault_used = self.vaults.get_key(kid)
if content_key: if content_key:
drm.content_keys[kid] = content_key drm.content_keys[kid] = content_key
label = f"[text2]{kid.hex}:{content_key} from {vault_used}" label = f"[text2]{kid.hex}:{content_key}{is_track_kid} from {vault_used}"
if not any(x.label == label for x in cek_tree.children): if not any(x.label == label for x in cek_tree.children):
cek_tree.add(label) cek_tree.add(label)
self.vaults.add_key(kid, content_key, excluding=vault_used) self.vaults.add_key(kid, content_key, excluding=vault_used)
@ -671,9 +675,7 @@ class dl:
for kid_, key in drm.content_keys.items(): for kid_, key in drm.content_keys.items():
if key == "0" * 32: if key == "0" * 32:
key = f"[red]{key}[/]" key = f"[red]{key}[/]"
if kid_ == kid: label = f"[text2]{kid_.hex}:{key}{is_track_kid}"
key += "*"
label = f"[text2]{kid_.hex}:{key}"
if not any(x.label == label for x in cek_tree.children): if not any(x.label == label for x in cek_tree.children):
cek_tree.add(label) cek_tree.add(label)
@ -690,12 +692,12 @@ class dl:
cached_keys = self.vaults.add_keys(drm.content_keys) cached_keys = self.vaults.add_keys(drm.content_keys)
self.log.info(f" + Newly added to {cached_keys}/{len(drm.content_keys)} Vaults") self.log.info(f" + Newly added to {cached_keys}/{len(drm.content_keys)} Vaults")
if kid not in drm.content_keys: if track_kid and track_kid not in drm.content_keys:
msg = f"No Content Key for KID {kid.hex} within the License" msg = f"No Content Key for KID {track_kid.hex} was returned in the License"
cek_tree.add(f"[logging.level.error]{msg}") cek_tree.add(f"[logging.level.error]{msg}")
if not pre_existing_tree: if not pre_existing_tree:
table.add_row(cek_tree) table.add_row(cek_tree)
raise Widevine.Exceptions.CEKNotFound(msg) raise Widevine.Exceptions.CEKNotFound(msg)
if cek_tree.children and not pre_existing_tree: if cek_tree.children and not pre_existing_tree:
table.add_row() table.add_row()