Danielle McLean
27d8c37139
Everything now uses bog-standard Python dataclasses, with Pydantic providing validation and type conversion through separate classes using its type adapter feature. It's also possible to define your classes using Pydantic's own model type directly, making the type adapter unnecessary, but I didn't want to do things that way because no actual validation is needed when constructing a Song instance for example. Having Pydantic do its thing only on-demand was preferable. I tried a number of validation libraries before settling on Pydantic for this. It's not the fastest option out there (msgspec is I think), but it makes adding support for third-party types like yarl.URL really easy, it generates a nice clean JSON Schema which is easy enough to adjust to my requirements through its GenerateJsonSchema hooks, and raw speed isn't all that important anyway since this is a single-user desktop program that reads its configuration file once on startup. Also, MessagePack is now mandatory if you're caching to an external service. It just didn't make a whole lot sense to explicitly install mpd-now-playable's Redis or Memcached support and then use pickling with them. With all this fussing around done, I'm probably finally ready to actually use that configuration file to configure new features! Yay!
48 lines
1.4 KiB
JSON
48 lines
1.4 KiB
JSON
{
|
|
"$defs": {
|
|
"MpdConfig": {
|
|
"properties": {
|
|
"host": {
|
|
"default": "127.0.0.1",
|
|
"description": "The hostname or IP address of your MPD server. If you're running MPD on your local machine, you don't need to configure this.",
|
|
"format": "hostname",
|
|
"title": "Host",
|
|
"type": "string"
|
|
},
|
|
"password": {
|
|
"description": "The password required to connect to your MPD instance, if you need one.",
|
|
"format": "password",
|
|
"title": "Password",
|
|
"type": "string",
|
|
"writeOnly": true
|
|
},
|
|
"port": {
|
|
"default": 6600,
|
|
"description": "The port on which to connect to MPD. Unless you're managing multiple MPD servers on one machine for some reason, you probably haven't changed this from the default port, 6600.",
|
|
"maximum": 65535,
|
|
"minimum": 1,
|
|
"title": "Port",
|
|
"type": "integer"
|
|
}
|
|
},
|
|
"title": "MpdConfig",
|
|
"type": "object"
|
|
}
|
|
},
|
|
"$id": "https://cdn.00dani.me/m/schemata/mpd-now-playable/config-v1.json",
|
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
"properties": {
|
|
"cache": {
|
|
"description": "A URL describing a cache service for mpd-now-playable to use. Supported protocols are memory://, redis://, and memcached://.",
|
|
"format": "uri",
|
|
"title": "Cache",
|
|
"type": "string"
|
|
},
|
|
"mpd": {
|
|
"$ref": "#/$defs/MpdConfig"
|
|
}
|
|
},
|
|
"title": "Config",
|
|
"type": "object"
|
|
}
|