{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Lelap add-on protocol v1",
  "$defs": {
    "Manifest": {
      "$id": "#/$defs/Manifest",
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 3
        },
        "version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+"
        },
        "protocol": {
          "type": "number",
          "const": 1
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        },
        "logo": {
          "type": "string",
          "format": "uri"
        },
        "types": {
          "minItems": 1,
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "audiobook",
              "podcast",
              "episode"
            ]
          }
        },
        "resources": {
          "minItems": 1,
          "type": "array",
          "items": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "catalog",
                  "meta",
                  "stream",
                  "scrobble"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "enum": [
                      "catalog",
                      "meta",
                      "stream",
                      "scrobble"
                    ]
                  },
                  "types": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "audiobook",
                        "podcast",
                        "episode"
                      ]
                    }
                  },
                  "idPrefixes": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    }
                  }
                },
                "required": [
                  "name"
                ],
                "additionalProperties": false
              }
            ]
          }
        },
        "idPrefixes": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "catalogs": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "audiobook",
                  "podcast",
                  "episode"
                ]
              },
              "id": {
                "type": "string",
                "minLength": 1
              },
              "name": {
                "type": "string",
                "minLength": 1
              },
              "extra": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string",
                      "minLength": 1
                    },
                    "isRequired": {
                      "type": "boolean"
                    },
                    "options": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "name"
                  ],
                  "additionalProperties": false
                }
              },
              "shelf": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "type",
              "id",
              "name"
            ],
            "additionalProperties": false
          }
        },
        "configurable": {
          "type": "boolean"
        }
      },
      "required": [
        "id",
        "version",
        "protocol",
        "name",
        "description",
        "types",
        "resources",
        "catalogs"
      ],
      "additionalProperties": false
    },
    "CatalogResponse": {
      "$id": "#/$defs/CatalogResponse",
      "type": "object",
      "properties": {
        "metas": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 3,
                "maxLength": 512,
                "pattern": "^[a-z][a-z0-9_-]*:.+$"
              },
              "type": {
                "type": "string",
                "enum": [
                  "audiobook",
                  "podcast",
                  "episode"
                ]
              },
              "name": {
                "type": "string",
                "minLength": 1
              },
              "author": {
                "type": "string"
              },
              "cover": {
                "type": "string",
                "format": "uri"
              },
              "description": {
                "type": "string"
              },
              "year": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              },
              "durationMs": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              }
            },
            "required": [
              "id",
              "type",
              "name"
            ],
            "additionalProperties": false
          }
        },
        "cacheMaxAge": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "metas"
      ],
      "additionalProperties": false
    },
    "MetaResponse": {
      "$id": "#/$defs/MetaResponse",
      "type": "object",
      "properties": {
        "meta": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "minLength": 3,
              "maxLength": 512,
              "pattern": "^[a-z][a-z0-9_-]*:.+$"
            },
            "type": {
              "type": "string",
              "enum": [
                "audiobook",
                "podcast",
                "episode"
              ]
            },
            "name": {
              "type": "string",
              "minLength": 1
            },
            "author": {
              "type": "string"
            },
            "cover": {
              "type": "string",
              "format": "uri"
            },
            "description": {
              "type": "string"
            },
            "year": {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            "durationMs": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "narrators": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "series": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "position": {
                    "type": "string"
                  }
                },
                "required": [
                  "name"
                ],
                "additionalProperties": false
              }
            },
            "language": {
              "type": "string"
            },
            "genres": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "chapters": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "startMs": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  }
                },
                "required": [
                  "title",
                  "startMs"
                ],
                "additionalProperties": false
              }
            },
            "externalIds": {
              "type": "object",
              "propertyNames": {
                "type": "string"
              },
              "additionalProperties": {
                "type": "string"
              }
            },
            "episodes": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 512,
                    "pattern": "^[a-z][a-z0-9_-]*:.+$"
                  },
                  "title": {
                    "type": "string"
                  },
                  "released": {
                    "type": "string"
                  },
                  "durationMs": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  },
                  "description": {
                    "type": "string"
                  }
                },
                "required": [
                  "id",
                  "title"
                ],
                "additionalProperties": false
              }
            },
            "link": {
              "type": "string",
              "format": "uri"
            },
            "feed": {
              "type": "string",
              "format": "uri"
            }
          },
          "required": [
            "id",
            "type",
            "name"
          ],
          "additionalProperties": false
        },
        "cacheMaxAge": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "meta"
      ],
      "additionalProperties": false
    },
    "StreamResponse": {
      "$id": "#/$defs/StreamResponse",
      "type": "object",
      "properties": {
        "streams": {
          "type": "array",
          "items": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "sourceKey": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 256
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "title": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bitrate": {
                    "type": "integer",
                    "exclusiveMinimum": 0,
                    "maximum": 9007199254740991
                  },
                  "size": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  },
                  "downloadable": {
                    "type": "boolean"
                  },
                  "parts": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "url": {
                          "type": "string",
                          "format": "uri"
                        },
                        "title": {
                          "type": "string"
                        },
                        "durationMs": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        "size": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        }
                      },
                      "required": [
                        "url",
                        "durationMs"
                      ],
                      "additionalProperties": false
                    }
                  }
                },
                "required": [
                  "sourceKey",
                  "name",
                  "parts"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "sourceKey": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 256
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "title": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bitrate": {
                    "type": "integer",
                    "exclusiveMinimum": 0,
                    "maximum": 9007199254740991
                  },
                  "size": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  },
                  "downloadable": {
                    "type": "boolean"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "durationMs": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  },
                  "chapters": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "title": {
                          "type": "string"
                        },
                        "startMs": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        }
                      },
                      "required": [
                        "title",
                        "startMs"
                      ],
                      "additionalProperties": false
                    }
                  }
                },
                "required": [
                  "sourceKey",
                  "name",
                  "url"
                ],
                "additionalProperties": false
              }
            ]
          }
        },
        "cacheMaxAge": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "streams"
      ],
      "additionalProperties": false
    },
    "ScrobbleRequest": {
      "$id": "#/$defs/ScrobbleRequest",
      "type": "object",
      "properties": {
        "events": {
          "minItems": 1,
          "maxItems": 100,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "eventId": {
                "type": "string",
                "minLength": 8,
                "maxLength": 128
              },
              "event": {
                "type": "string",
                "enum": [
                  "start",
                  "progress",
                  "pause",
                  "finish",
                  "abandon",
                  "rate"
                ]
              },
              "at": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              },
              "item": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "audiobook",
                      "podcast",
                      "episode"
                    ]
                  },
                  "id": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 512,
                    "pattern": "^[a-z][a-z0-9_-]*:.+$"
                  },
                  "externalIds": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "type": "string"
                    }
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "author": {
                    "type": "string"
                  },
                  "durationMs": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  },
                  "podcast": {
                    "type": "object",
                    "properties": {
                      "feed": {
                        "type": "string",
                        "format": "uri"
                      },
                      "guid": {
                        "type": "string"
                      },
                      "title": {
                        "type": "string"
                      }
                    },
                    "additionalProperties": false
                  },
                  "episodeGuid": {
                    "type": "string"
                  }
                },
                "required": [
                  "type",
                  "name"
                ],
                "additionalProperties": false
              },
              "positionMs": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              },
              "sessionStartMs": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              },
              "rating": {
                "type": "number",
                "minimum": 0.5,
                "maximum": 5,
                "multipleOf": 0.5
              }
            },
            "required": [
              "eventId",
              "event",
              "at",
              "item"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "events"
      ],
      "additionalProperties": false
    }
  }
}
