{
  "openapi": "3.0.3",
  "info": {
    "title": "RUSWRLD Player Catalog API",
    "version": "1.0.0",
    "description": "Публичные методы чтения каталога. Регистрация и API-ключ не нужны. Сервер может добавлять новые поля в ответы."
  },
  "servers": [{ "url": "https://rusikmusic999.ru" }],
  "externalDocs": { "description": "Документация и примеры", "url": "https://rusikmusic999.ru/help/api/" },
  "security": [],
  "paths": {
    "/juicewrld/songs/": {
      "get": {
        "operationId": "listSongs",
        "summary": "Поиск и список треков",
        "parameters": [
          { "$ref": "#/components/parameters/Search" },
          { "$ref": "#/components/parameters/Page" },
          { "$ref": "#/components/parameters/CatalogPageSize" },
          { "$ref": "#/components/parameters/Category" },
          { "$ref": "#/components/parameters/CategoryExact" },
          { "$ref": "#/components/parameters/IsReleased" },
          { "$ref": "#/components/parameters/HasLrc" }
        ],
        "responses": {
          "200": { "description": "Страница каталога", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SongPage" } } } },
          "429": { "$ref": "#/components/responses/SearchRateLimited" }
        }
      }
    },
    "/juicewrld/songs/{id}/": {
      "parameters": [{ "$ref": "#/components/parameters/SongId" }],
      "get": {
        "operationId": "getSong",
        "summary": "Карточка трека",
        "responses": {
          "200": { "description": "Найденный трек", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SongDetails" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/juicewrld/songs/{id}/versions/": {
      "parameters": [{ "$ref": "#/components/parameters/SongId" }],
      "get": {
        "operationId": "listSongVersions",
        "summary": "Версии песни",
        "responses": {
          "200": { "description": "Треки в группе версий", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SongList" } } } },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/juicewrld/albums/": {
      "get": {
        "operationId": "listAlbums",
        "summary": "Альбомы и папки каталога",
        "responses": {
          "200": { "description": "Группы альбомов", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AlbumCatalog" } } } }
        }
      }
    },
    "/juicewrld/categories/": {
      "get": {
        "operationId": "listCategories",
        "summary": "Значения фильтров каталога",
        "responses": {
          "200": { "description": "Категории, эры и исполнители", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CatalogFilters" } } } }
        }
      }
    },
    "/juicewrld/top/": {
      "get": {
        "operationId": "getTopSongs",
        "summary": "Топ по прослушиваниям",
        "parameters": [
          { "name": "period", "in": "query", "schema": { "type": "string", "enum": ["now", "24h", "7d", "30d", "all"], "default": "now" }, "description": "Период рейтинга. now означает последний час." },
          { "name": "as_of", "in": "query", "schema": { "type": "integer", "format": "int64" }, "description": "Время среза в миллисекундах Unix. Передаётся в ссылке next. Срез действует до 24 часов." },
          { "$ref": "#/components/parameters/Search" },
          { "$ref": "#/components/parameters/Page" },
          { "name": "page_size", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 200, "default": 100 } },
          { "$ref": "#/components/parameters/Category" },
          { "$ref": "#/components/parameters/CategoryExact" },
          { "$ref": "#/components/parameters/IsReleased" },
          { "$ref": "#/components/parameters/HasLrc" }
        ],
        "responses": {
          "200": { "description": "Страница топа", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/TopPage" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "429": { "$ref": "#/components/responses/SearchRateLimited" }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "Search": { "name": "search", "in": "query", "schema": { "type": "string", "maxLength": 80 }, "example": "Lucid Dreams" },
      "Page": { "name": "page", "in": "query", "schema": { "type": "integer", "minimum": 1, "default": 1 } },
      "CatalogPageSize": { "name": "page_size", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 200, "default": 30 } },
      "Category": { "name": "category", "in": "query", "schema": { "type": "string" }, "description": "Значение value из списка categories." },
      "CategoryExact": { "name": "category_exact", "in": "query", "schema": { "type": "boolean", "default": false }, "description": "При true из результата исключаются подпапки указанной категории." },
      "IsReleased": { "name": "is_released", "in": "query", "schema": { "type": "boolean" } },
      "HasLrc": { "name": "has_lrc", "in": "query", "schema": { "type": "boolean" } },
      "SongId": { "name": "id", "in": "path", "required": true, "schema": { "type": "integer", "format": "int64", "minimum": 1 }, "example": 330208596 }
    },
    "responses": {
      "BadRequest": { "description": "Неверный ID, период топа или время среза", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "NotFound": { "description": "Трек или группа версий не найдены", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "SearchRateLimited": {
        "description": "Превышен общий лимит поиска по каталогу и топу, 120 запросов в минуту с одного IP",
        "headers": { "Retry-After": { "description": "Сколько секунд ждать перед повтором", "schema": { "type": "integer", "minimum": 0 } } },
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    },
    "schemas": {
      "Error": {
        "type": "object", "required": ["ok", "error"],
        "properties": { "ok": { "type": "boolean", "enum": [false] }, "error": { "type": "string" } }
      },
      "Song": {
        "type": "object", "required": ["id", "name", "category", "image_url", "is_released", "play_count"],
        "properties": {
          "id": { "type": "integer", "format": "int64" },
          "name": { "type": "string" },
          "category": { "type": "string", "nullable": true },
          "image_url": { "type": "string", "format": "uri" },
          "is_released": { "type": "boolean" },
          "play_count": { "type": "integer", "minimum": 0 }
        }
      },
      "SongDetails": {
        "allOf": [
          { "$ref": "#/components/schemas/Song" },
          { "type": "object", "required": ["aliases"], "properties": { "aliases": { "type": "array", "items": { "type": "string" } } } }
        ]
      },
      "SongList": {
        "type": "object", "required": ["count", "results"],
        "properties": {
          "count": { "type": "integer", "minimum": 0 },
          "results": { "type": "array", "items": { "$ref": "#/components/schemas/Song" } }
        }
      },
      "Pagination": {
        "type": "object", "required": ["next", "previous"],
        "properties": {
          "next": { "type": "string", "format": "uri", "nullable": true },
          "previous": { "type": "string", "format": "uri", "nullable": true }
        }
      },
      "SongPage": { "allOf": [{ "$ref": "#/components/schemas/SongList" }, { "$ref": "#/components/schemas/Pagination" }] },
      "TopSong": {
        "allOf": [
          { "$ref": "#/components/schemas/Song" },
          { "type": "object", "required": ["period_play_count"], "properties": { "period_play_count": { "type": "integer", "minimum": 0 } } }
        ]
      },
      "TopPage": {
        "allOf": [
          { "$ref": "#/components/schemas/Pagination" },
          {
            "type": "object",
            "required": ["count", "results", "period", "as_of", "generated_at", "range_start", "range_end", "coverage_complete", "coverage_since"],
            "properties": {
              "count": { "type": "integer", "minimum": 0 },
              "results": { "type": "array", "items": { "$ref": "#/components/schemas/TopSong" } },
              "period": { "type": "string", "enum": ["now", "24h", "7d", "30d", "all"] },
              "as_of": { "type": "integer", "format": "int64" },
              "generated_at": { "type": "string", "format": "date-time" },
              "range_start": { "type": "string", "format": "date-time", "nullable": true },
              "range_end": { "type": "string", "format": "date-time" },
              "coverage_complete": { "type": "boolean" },
              "coverage_since": { "type": "string", "format": "date-time", "nullable": true }
            }
          }
        ]
      },
      "AlbumCatalog": {
        "type": "object", "required": ["groups", "album_count", "song_count"],
        "properties": {
          "groups": { "type": "array", "items": { "$ref": "#/components/schemas/AlbumGroup" } },
          "album_count": { "type": "integer", "minimum": 0 },
          "song_count": { "type": "integer", "minimum": 0 }
        }
      },
      "AlbumGroup": {
        "type": "object", "required": ["name", "albums", "album_count", "song_count", "cover_url"],
        "properties": {
          "name": { "type": "string" },
          "cover_url": { "type": "string", "format": "uri" },
          "albums": { "type": "array", "items": { "$ref": "#/components/schemas/Album" } },
          "subfolders": { "type": "array", "items": { "$ref": "#/components/schemas/AlbumGroup" } },
          "album_count": { "type": "integer", "minimum": 0 },
          "song_count": { "type": "integer", "minimum": 0 }
        }
      },
      "Album": {
        "type": "object", "required": ["name", "category", "song_count", "cover_url"],
        "properties": {
          "name": { "type": "string" },
          "category": { "type": "string" },
          "song_count": { "type": "integer", "minimum": 0 },
          "cover_url": { "type": "string", "format": "uri" }
        }
      },
      "CatalogFilters": {
        "type": "object", "required": ["categories", "eras", "recording_eras", "artists"],
        "properties": {
          "categories": { "type": "array", "items": { "$ref": "#/components/schemas/CategoryOption" } },
          "eras": { "type": "array", "items": { "type": "string" } },
          "recording_eras": { "type": "array", "items": { "type": "string" } },
          "artists": { "type": "array", "items": { "type": "string" } }
        }
      },
      "CategoryOption": {
        "type": "object", "required": ["value", "label"],
        "properties": { "value": { "type": "string" }, "label": { "type": "string" } }
      }
    }
  }
}
