"""
Cerca i file del Widevine CDM installato da Chrome sul sistema Windows
e tenta di creare un WVD di tipo CHROME.
"""
import os
import glob
import subprocess

# Percorsi comuni dove Chrome installa il Widevine CDM su Windows
chrome_paths = [
    os.path.expandvars(r"%LOCALAPPDATA%\Google\Chrome\User Data\WidevineCdm"),
    os.path.expandvars(r"%LOCALAPPDATA%\Google\Chrome\Application"),
    os.path.expandvars(r"%PROGRAMFILES%\Google\Chrome\Application"),
    os.path.expandvars(r"%PROGRAMFILES(X86)%\Google\Chrome\Application"),
    os.path.expandvars(r"%LOCALAPPDATA%\Microsoft\Edge\User Data\WidevineCdm"),
]

print("=== Ricerca Widevine CDM sul sistema ===\n")
for base in chrome_paths:
    if os.path.exists(base):
        print(f"[TROVATO] {base}")
        for root, dirs, files in os.walk(base):
            for f in files:
                full = os.path.join(root, f)
                size = os.path.getsize(full)
                if any(k in f.lower() for k in ["widevine", "cdm", "widevinecdm", ".dll", ".so", ".dylib", "manifest", "LICENSE"]):
                    print(f"    {full}  ({size} bytes)")
    else:
        print(f"[---] {base}")

print("\n=== Ricerca pywidevine CLI ===")
try:
    result = subprocess.run(["pywidevine", "--help"], capture_output=True, text=True, timeout=10)
    print(result.stdout[:500] if result.stdout else result.stderr[:500])
except FileNotFoundError:
    print("pywidevine CLI non trovato nel PATH")
except Exception as e:
    print(f"Errore: {e}")

print("\n=== Ricerca Device.new / Device.__init__ ===")
from pywidevine import Device
from pywidevine.device import DeviceTypes
import inspect
sig = inspect.signature(Device.__init__)
print(f"Device.__init__ params: {sig}")
print(f"\nDeviceTypes disponibili:")
for dt in DeviceTypes:
    print(f"  {dt.name} = {dt.value}")
