import requests
import json

MISTY_IP = "192.168.68.57" 

def try_start(label, payload):
    base_url = f"http://{MISTY_IP}/api/avstreaming/start"
    print(f"Versuche {label}...")
    try:
        res = requests.post(base_url, json=payload, timeout=5)
        if res.status_code == 200:
            print(f"✅ {label} ERFOLGREICH!")
            return True
        else:
            print(f"❌ {label} fehlgeschlagen: {res.status_code} - {res.text}")
    except Exception as e:
        print(f"Fehler: {e}")
    return False

def run_all():
    # Reset
    requests.post(f"http://{MISTY_IP}/api/avstreaming/stop")
    
    # Variante A: 'URL' großgeschrieben mit null
    payload_a = {"URL": None, "Width": 640, "Height": 480, "FrameRate": 15, "VideoBitRate": 1000000, "AudioBitRate": 128000, "AudioSampleRateHz": 16000}
    
    # Variante B: 'Url' kleingeschrieben mit null
    payload_b = {"Url": None, "Width": 640, "Height": 480, "FrameRate": 15, "VideoBitRate": 1000000, "AudioBitRate": 128000, "AudioSampleRateHz": 16000}
    
    # Variante C: 'URL' mit lokalem Pfad (Manche Versionen brauchen das)
    payload_c = {"URL": "rtsp://127.0.0.1:554/live", "Width": 640, "Height": 480, "FrameRate": 15, "VideoBitRate": 1000000, "AudioBitRate": 128000, "AudioSampleRateHz": 16000}

    if not try_start("Variante A (URL: null)", payload_a):
        if not try_start("Variante B (Url: null)", payload_b):
            try_start("Variante C (Localhost IP)", payload_c)

if __name__ == "__main__":
    run_all()
