Hi, guys, I'm trying to get the MPD token from a Claro account using a script, but it's getting complicated. Could you help me? Thanks.



HTML Code:
import httpx
import time
import base64
import json

# CREDENCIALES Y CONFIGURACIÓN
email = "cd@gmail.com"
password = "reel19"  
authpn = "webclient"
authpt = "tfg1h3j4k6fdg"
region = "argentina"
device_id = "web"
device_model = "web"
device_type = "web"
device_so = "Chrome"
device_manufacturer = "generic"
api_version = "v5.94"
user_agent = "Mozilla/5.0"

# INFO DE CONTENIDO
content_id = "766774"
group_id = "766212"

# Función para decodificar JWT
def decodificar_jwt(token):
    payload = token.split(".")[1]
    padded = payload + "=" * (-len(payload) % 4)
    decoded = base64.urlsafe_b64decode(padded)
    return json.loads(decoded)

# Función para login
def iniciar_sesion():
    url = "https://mfwkweb-api.clarovideo.net/services/user/login"
    payload = {
        "user": email,
        "password": password,
    }
    params = {
        "device_id": device_id,
        "device_category": device_type,
        "device_model": device_model,
        "device_type": device_type,
        "device_so": device_so,
        "device_manufacturer": device_manufacturer,
        "authpn": authpn,
        "authpt": authpt,
        "api_version": api_version,
        "region": region,
        "format": "json",
        "includpaywayprofile": "true"
    }

    with httpx.Client() as client:
        r = client.post(url, params=params, data=payload)
        r.raise_for_status()
        data = r.json()
        return {
            "user_token": data["response"]["user_token"],
            "user_hash": data["response"]["session_userhash"],
            "user_id": data["response"]["user_id"],
            "HKS": data["response"]["session_stringvalue"]
        }

# Verifica si el token está vencido
def token_valido(jwt):
    try:
        payload = decodificar_jwt(jwt)
        return int(time.time()) < int(payload["exp"])
    except:
        return False

# Función para obtener el MPD
def obtener_mpd(info):
    url = "https://mfwkweb-api.clarovideo.net/services/player/getmedia"
    params = {
        "crDomain": "https://www.clarovideo.com",
        "api_version": api_version,
        "user_hash": info["user_hash"],
        "group_id": group_id,
        "user_id": info["user_id"],
        "device_id": device_id,
        "stream_type": "dashwv",
        "preview": "0",
        "css": "0",
        "content_id": content_id,
        "authpn": authpn,
        "authpt": authpt,
        "device_category": device_type,
        "device_manufacturer": device_manufacturer,
        "device_model": device_model,
        "device_type": device_type,
        "format": "json",
        "region": region,
        "HKS": info["HKS"]
    }

    headers = {
        "User-Agent": user_agent,
        "Authorization": f"Bearer {info['user_token']}"
    }

    with httpx.Client() as client:
        r = client.get(url, params=params, headers=headers)
        r.raise_for_status()
        data = r.json()

        if "response" in data:
            mpd_url = data["response"]["delivery"][0]["videos"]["video"]["url"]
            print("✅ MPD URL:")
            print(mpd_url)
        else:
            print("❌ Error al obtener el MPD.")
            print(data)

# PROGRAMA PRINCIPAL
def main():
    print("🔐 Verificando token...")
    try:
        with open("credenciales.json", "r") as f:
            info = json.load(f)
    except FileNotFoundError:
        info = iniciar_sesion()
        with open("credenciales.json", "w") as f:
            json.dump(info, f)

    if not token_valido(info["user_token"]):
        print("🔁 Token vencido, iniciando sesión nuevamente...")
        info = iniciar_sesion()
        with open("credenciales.json", "w") as f:
            json.dump(info, f)

    obtener_mpd(info)

if __name__ == "__main__":
    main()