Skip to content

Commit

Permalink
refactor(dl): Make Widevine CDM config optional
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rlaphoenix committed May 17, 2024
1 parent 0310646 commit 221cd14
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions devine/commands/dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 221cd14

Please sign in to comment.