{
  "openapi": "3.0.3",
  "info": {
    "title": "RadioAPI v2 – Vereinfachte API",
    "description": "Vereinfachtes, REST-artiges Gegenstück zur v1-API (siehe `openapi.json`). Nur JSON, kein XML. Nutzt sprechende Stationsnamen (`rgde_stations.name`) statt numerischer IDs und liefert pro Endpunkt nur die jeweils relevanten Felder statt des vollen `stationData`-Objekts. Öffentlich, unauthentifiziert, offene CORS-Header (`Access-Control-Allow-Origin: *`, inkl. `OPTIONS`-Preflight-Unterstützung).",
    "version": "2.0.0"
  },
  "servers": [
    { "url": "https://radioapi.de" }
  ],
  "paths": {
    "/api/station_list": {
      "get": {
        "summary": "Alle Stationen, gruppiert nach Netzwerk",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Stationen gruppiert nach `network_id`.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/StationListResponse" } } }
          }
        }
      }
    },
    "/api/{station}/listener": {
      "get": {
        "summary": "Aktuelle Hörerzahl einer Station",
        "parameters": [{ "$ref": "#/components/parameters/StationName" }],
        "responses": {
          "200": {
            "description": "Hörerzahl.",
            "content": { "application/json": { "schema": {
              "type": "object",
              "properties": {
                "station": { "type": "string" },
                "listeners": { "type": "integer" }
              }
            } } }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/{station}/now_playing": {
      "get": {
        "summary": "Aktuell laufender Titel einer Station",
        "parameters": [{ "$ref": "#/components/parameters/StationName" }],
        "responses": {
          "200": {
            "description": "Aktueller Titel.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NowPlaying" } } }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/{station}/info": {
      "get": {
        "summary": "Stammdaten einer Station",
        "parameters": [{ "$ref": "#/components/parameters/StationName" }],
        "responses": {
          "200": {
            "description": "Stationsinfos.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/StationInfo" } } }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/{station}/last_songs": {
      "get": {
        "summary": "Zuletzt gesendete Titel einer Station",
        "parameters": [
          { "$ref": "#/components/parameters/StationName" },
          { "name": "limit", "in": "query", "description": "Anzahl der zurückgegebenen Songs. Wird auf den Bereich 1–20 begrenzt.", "schema": { "type": "integer", "default": 10, "minimum": 1, "maximum": 20 } }
        ],
        "responses": {
          "200": {
            "description": "Liste der letzten gesendeten Titel, neueste zuerst.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LastSongsResponse" } } }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "StationName": {
        "name": "station",
        "in": "path",
        "required": true,
        "description": "Technischer Stationsname (`rgde_stations.name`, kleingeschrieben, z. B. `lionfm`).",
        "schema": { "type": "string" }
      }
    },
    "responses": {
      "NotFound": {
        "description": "Station mit diesem Namen existiert nicht (oder ist versteckt), bzw. unbekannter Endpunkt.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
      }
    },
    "schemas": {
      "StreamUrls": {
        "type": "object",
        "properties": {
          "mp3": { "type": "string", "format": "uri" },
          "m3u": { "type": "string", "format": "uri" },
          "pls": { "type": "string", "format": "uri" }
        }
      },
      "StationListEntry": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "ext_id": { "type": "integer" },
          "name": { "type": "string" },
          "display_name": { "type": "string" },
          "description": { "type": "string", "nullable": true },
          "main_genre": { "type": "string", "nullable": true },
          "listeners": { "type": "integer" },
          "color": { "type": "string", "nullable": true },
          "font_color": { "type": "string", "nullable": true },
          "top_station": { "type": "boolean" },
          "image": { "type": "string", "format": "uri" },
          "stream": { "$ref": "#/components/schemas/StreamUrls" },
          "lautfm_url": { "type": "string", "format": "uri" }
        }
      },
      "StationGroup": {
        "type": "object",
        "properties": {
          "network_id": { "type": "integer" },
          "stations": { "type": "array", "items": { "$ref": "#/components/schemas/StationListEntry" } }
        }
      },
      "StationListResponse": {
        "type": "object",
        "properties": {
          "count": { "type": "integer" },
          "groups": { "type": "array", "items": { "$ref": "#/components/schemas/StationGroup" } }
        }
      },
      "NowPlaying": {
        "type": "object",
        "properties": {
          "station": { "type": "string" },
          "artist": { "type": "string" },
          "title": { "type": "string" },
          "genre": { "type": "string", "nullable": true },
          "start": { "type": "string", "format": "date-time" },
          "end": { "type": "string", "format": "date-time" },
          "is_live": { "type": "boolean" },
          "cover": { "type": "string", "format": "uri", "description": "Nur enthalten, wenn die Station zu Netzwerk 1 (LionFM) gehört." }
        }
      },
      "StationInfo": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "ext_id": { "type": "integer" },
          "network_id": { "type": "integer" },
          "name": { "type": "string" },
          "display_name": { "type": "string" },
          "description": { "type": "string", "nullable": true },
          "main_genre": { "type": "string", "nullable": true },
          "color": { "type": "string", "nullable": true },
          "font_color": { "type": "string", "nullable": true },
          "image": { "type": "string", "format": "uri" },
          "stream": { "$ref": "#/components/schemas/StreamUrls" },
          "lautfm_url": { "type": "string", "format": "uri" },
          "listeners": { "type": "integer" },
          "is_live": { "type": "boolean" },
          "live_streamer": { "type": "string", "nullable": true, "description": "Trägt ein `[LIVE] `-Präfix, wenn aktuell eine als live markierte Sendung läuft." }
        }
      },
      "LastSong": {
        "type": "object",
        "properties": {
          "time": { "type": "string", "example": "14:32" },
          "artist": { "type": "string" },
          "title": { "type": "string" },
          "genre": { "type": "string", "nullable": true },
          "cover": { "type": "string", "format": "uri", "description": "Nur enthalten, wenn die Station zu Netzwerk 1 (LionFM) gehört." }
        }
      },
      "LastSongsResponse": {
        "type": "object",
        "properties": {
          "station": { "type": "string" },
          "count": { "type": "integer" },
          "songs": { "type": "array", "items": { "$ref": "#/components/schemas/LastSong" } }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": { "type": "string" }
        }
      }
    }
  }
}
