#!/usr/bin/env python3

import sys
import tidalapi

if len(sys.argv) != 2:
    print("Uso: get_tidal_image.py <track_id>")
    sys.exit(1)

track_id = sys.argv[1]

print(f"[INFO] Track ID recibido: {track_id}")

try:
    session = tidalapi.Session()
    if not session.check_login():
        print("[INFO] No hay sesión activa, iniciando login...")
        logged_in = session.login_oauth_simple()
        if not logged_in:
            print("[ERROR] Falló el login interactivo")
            sys.exit(1)
        else:
            print("[INFO] Login correcto.")
    else:
        print("[INFO] Sesión cargada correctamente.")

    print(f"[INFO] Obteniendo información de la pista {track_id}...")
    track = session.track(track_id)

    cover_url = track.album.cover.replace("320x320", "1280x1280")
    print(f"[INFO] URL de portada: {cover_url}")
    print(cover_url)

except Exception as e:
    print(f"[ERROR] {e}")
    sys.exit(1)

