From 6a9598021d5073a92a93cd5bcde1bd9ddbd1bc55 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Thu, 25 May 2023 04:45:49 +0100 Subject: [PATCH] Re-raise errors when loading WVD files so it's more understandable It also looks for the "expected 2 but parsed 1" error which is likely an error while parsing the WVD version field. If this happens, it will inform the user to use `pywidevine migrate`. --- devine/commands/dl.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/devine/commands/dl.py b/devine/commands/dl.py index 0a764bb..b7694e2 100644 --- a/devine/commands/dl.py +++ b/devine/commands/dl.py @@ -24,6 +24,7 @@ import click import jsonpickle import pycaption import yaml +from construct import ConstError from pymediainfo import MediaInfo from pywidevine.cdm import Cdm as WidevineCdm from pywidevine.device import Device @@ -1023,5 +1024,14 @@ class dl: cdm_path = config.directories.wvds / f"{cdm_name}.wvd" if not cdm_path.is_file(): raise ValueError(f"{cdm_name} does not exist or is not a file") - device = Device.load(cdm_path) + + try: + device = Device.load(cdm_path) + except ConstError as e: + if "expected 2 but parsed 1" in str(e): + raise ValueError( + f"{cdm_name}.wvd seems to be a v1 WVD file, use `pywidevine migrate --help` to migrate it to v2." + ) + raise ValueError(f"{cdm_name}.wvd is an invalid or corrupt Widevine Device file, {e}") + return WidevineCdm.from_device(device)