From 221cd145c4e76b34d56339fff5d1ab430596dc70 Mon Sep 17 00:00:00 2001 From: rlaphoenix <17136956+rlaphoenix@users.noreply.github.com> Date: Fri, 17 May 2024 01:52:45 +0100 Subject: [PATCH] refactor(dl): Make Widevine CDM config optional With this change you no longer have to define/configure a CDM to load. This is something that isn't necessary for a lot of services. Note: It's also now less hand-holdy in terms of correct config formatting/values. I.e. if you define a cdm by profile for a service slightly incorrectly, say a typo on the service or profile name, it will no longer warn you. --- devine/commands/dl.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/devine/commands/dl.py b/devine/commands/dl.py index 0f007fa..d4857ce 100644 --- a/devine/commands/dl.py +++ b/devine/commands/dl.py @@ -178,9 +178,10 @@ def __init__( except ValueError as e: self.log.error(f"Failed to load Widevine CDM, {e}") sys.exit(1) - self.log.info( - f"Loaded {self.cdm.__class__.__name__} Widevine CDM: {self.cdm.system_id} (L{self.cdm.security_level})" - ) + if self.cdm: + self.log.info( + f"Loaded {self.cdm.__class__.__name__} Widevine CDM: {self.cdm.system_id} (L{self.cdm.security_level})" + ) with console.status("Loading Key Vaults...", spinner="dots"): self.vaults = Vaults(self.service) @@ -936,21 +937,21 @@ def get_credentials(service: str, profile: Optional[str]) -> Optional[Credential return Credential.loads(credentials) # type: ignore @staticmethod - def get_cdm(service: str, profile: Optional[str] = None) -> WidevineCdm: + def get_cdm(service: str, profile: Optional[str] = None) -> Optional[WidevineCdm]: """ Get CDM for a specified service (either Local or Remote CDM). Raises a ValueError if there's a problem getting a CDM. """ cdm_name = config.cdm.get(service) or config.cdm.get("default") if not cdm_name: - raise ValueError("A CDM to use wasn't listed in the config") + return None if isinstance(cdm_name, dict): if not profile: - raise ValueError("CDM config is mapped for profiles, but no profile was chosen") + return None cdm_name = cdm_name.get(profile) or config.cdm.get("default") if not cdm_name: - raise ValueError(f"A CDM to use was not mapped for the profile {profile}") + return None cdm_api = next(iter(x for x in config.remote_cdm if x["name"] == cdm_name), None) if cdm_api: