import requests
import time
from config import MISTY_IP

def start_misty_studio_clone():
    print(f"--- Erzwungener Studio-Klon Start ({MISTY_IP}) ---")
    
    # 1. Cleanup: Erst alles stoppen
    requests.post(f"http://{MISTY_IP}/api/avstreaming/stop")
    time.sleep(2)
    
    # 2. Die exakte Struktur aus deinem Studio-Fund
    # WICHTIG: Port muss im Body sein, url muss null sein
    payload = {
        "url": None,
        "width": 0,
        "height": 0,
        "frameRate": 0,
        "videoBitRate": 0,
        "audioBitRate": 0,
        "audioSampleRateHz": 0,
        "userName": None,
        "password": None,
        "port": 1936 
    }

    # Wir schicken es an den Endpoint, den das Studio nutzt
    url = f"http://{MISTY_IP}/api/avstreaming/start"
    
    print("Sende Paket...")
    try:
        response = requests.post(url, json=payload, timeout=10)
        print(f"Status: {response.status_code}")
        print(f"Antwort: {response.text}")
        
        if response.status_code == 200 and "Success" in response.text:
            print("\n✅ API sagt JA! Teste JETZT VLC.")
        else:
            print("\n❌ Misty hat das Paket abgelehnt.")
            
    except Exception as e:
        print(f"Fehler: {e}")

if __name__ == "__main__":
    start_misty_studio_clone()
