Commit graph sonda/internal/api/openapi
Author SHA1 Message Date
tgiachi
246cdc63d3 feat: Recently added on Home, with a newest-first order for albums
I can now see on Home what I added to the library lately.

- GET /albums takes sort=recent: the albums added last first, by the date of the newest file of the album that is not missing, then the newest album. The default stays by title and any other value is invalid_input.
- The albums shelf on Home is Recently added and asks for that order; See all leads to /albums?sort=recent, which the albums page understands.
- English and Italian.
2026-11-14 10:29:08 +01:00
tgiachi
d3695d00d6 feat(smart): smart playlists by the year a song came out
I can now ask for songs from a year to a year, for example the eighties.

- The year is read from the tags of each file (the original date first, then the date) and kept on the track: migration 0028 adds tracks.year (SQLite and PostgreSQL).
- Two new rules, min_year and max_year, both included and checked (1000 to 2999, the first not after the second). The index answers them. A song with no year never matches.
- Files indexed before have no year until a full rescan reads their tags again; the editor and the API description say so.
- The smart playlist editor gets From year and Up to year, and the rules are described in words.
- English and Italian.
2026-11-14 10:19:39 +01:00
tgiachi
a7a258464b feat(mastodon): say in Settings when the instance no longer accepts the token
When the instance refuses the token on a post (it was revoked or expired), the account now remembers it: GET /me/mastodon says problem: token_refused and nothing is posted until I connect again with a new token.

- migration 0027 adds mastodon_accounts.problem (SQLite and PostgreSQL).
- Only a refused token marks the account; an instance that is down does not.
- Saving the account again clears the problem.
- Settings shows the warning and the form with the instance already filled in, next to Disconnect.
- English and Italian.
2026-11-14 10:04:07 +01:00
tgiachi
0dc7782028 feat: post what I listen to on Mastodon, if I connect an account
In Settings a person connects their Mastodon account: the address of their instance and an access token that can only write posts. Nothing is connected by default, and disconnecting forgets the token.

- When a track of this server counts as a listen, it is posted as an unlisted status: title, artists, album and #NowPlaying, with no link. Music of a friend is never reported as a listen, so it is never posted. At most one post a minute for each person, in the background, with a bounded queue.
- PUT, GET and DELETE /me/mastodon. The token is never sent back.
- The address of the instance is typed by a person, so it must be a domain name on https, and the client never connects to a private, loopback or link-local address (checked on the address it really dials, so a name that points inside is no way in), never follows a redirect, ignores proxy settings and reads at most a megabyte.
- New table mastodon_accounts (SQLite and PostgreSQL) that goes with the account.
- README: the feature, and the credit for butterchurn and its presets.
2026-11-13 21:59:03 +01:00
tgiachi
7243fe7a04 feat: the seek bar shows the waveform of a friend's track
A friend's server works out the peaks of a track in a shared library and gives
them to a signed friend (GET /peer/tracks/{id}/peaks). This server asks for them
and passes them on to the listener after checking them: 1 to 1000 levels from 0
to 255, as many as the count says (GET /friends/{friend}/tracks/{id}/peaks). The
player uses it for a friend's track, so its bar is no longer flat.
2026-11-13 19:46:37 +01:00
tgiachi
bfa3e6e458 feat: the seek bar shows the waveform of the track
The seek bar of the player is the shape of the track, with the part already
heard in colour, as in the approved mockups.

- GET /tracks/{id}/peaks gives 120 levels from 0 to 255 (the loudest part is
  255 whatever the volume). The server finds them by decoding the file, MP3 with
  go-mp3 and FLAC with eaburns/flac, both in pure Go. It takes a few seconds, so
  the first request starts the work in the background and answers 202 with
  Retry-After. It is done once for each file (migration 0025), worked out again
  if the size or the date of the file change, one track at a time so that a NAS
  is not kept busy, and a file that cannot be decoded is remembered as such. A
  track deleted while its file is being decoded is not an error.
- The seek bar of the player bar and of the full-screen player draws the shape
  and asks again every few seconds until it is there. Until then, and for a
  friend's track, which has none, the bar is flat. The heard part is teal, or
  the friend colour. It is still a native range input, 44 pixels high in the
  bar.
- OpenAPI path and schema, contract test, tests with real MP3 and FLAC files,
  and a real server checked: a 4-minute MP3 is ready in about a second and a
  half, a 12 MB FLAC in three, and asking again takes a millisecond.
2026-11-13 17:35:00 +01:00
tgiachi
7f38ae038e feat(federation): play a friend's music and show its covers through this server
A listener can now play the music of a friend from the web app.

- GET /friends/{friend}/tracks/{id}/stream and /friends/{friend}/albums/{id}/cover,
  in the group that accepts the access token in the query, like the local ones.
  This server asks the friend with a signed request and passes the bytes on,
  forwarding Range and the conditional headers, so a player can seek. The
  friend sees this server and never the listener.
- Only audio (for a stream) and a JPEG (for a cover) are passed on, with a
  fixed set of headers: Content-Type, Content-Length, Content-Range,
  Accept-Ranges, Last-Modified and ETag. Anything else a friend sends, or
  what a listener's request carries (cookies, authorization), is not passed
  either way, so a friend cannot make this server serve anything else.
- The client of friends can open a streaming answer: no limit on its whole
  length, one only on its beginning, no redirect followed, and it ends when
  the listener leaves.
- The player holds a friend's track next to the local ones. It streams
  through this server, shows the friend's cover, links to the music of the
  friend and not to a local page, is told apart from a local track with the
  same id, and is never reported as a listen: it does not feed taste.
- The songs of a friend have play buttons, the albums their covers.
- OpenAPI paths, contract test, and two real servers checked end to end: the
  bytes of the file arrive unchanged, with ranges, and a song plays in a
  browser from the friend's server through the other one.
2026-11-13 16:11:59 +01:00
tgiachi
29bd46c3ba feat(federation): browse and search a friend's catalogue
A listener can now browse the music that a friend's server shares.

- GET /friends lists the friends both admins agreed to, by id and name; an
  address or a key is for the admin only. It is empty while federation is off.
- GET /friends/{friend}/artists, albums and tracks (q, limit, offset,
  artist_id, album_id) and the one-item routes: this server asks the friend
  with a request signed by its own key and passes the page on. The answer is
  read into this API's own types first, so what a friend adds is dropped and
  the shape is the one in the spec. Nothing is kept, and the ids are the
  friend's own.
- Only the three kinds of thing can be asked, and only the parameters their
  routes take: a listener cannot make this server ask a friend for anything
  else. The friend's address and what the connection said never reach a
  listener.
- A friend that cannot be reached, no longer takes this server for a friend,
  is busy or is not there is told in words, never as an error page.
- The client of friends gets a generic signed GET with a size limit.
- The web app has a Friends entry in the menu, shown only when there is a
  friend to browse, a list of friends and a page for each with artists,
  albums and songs, a search and links from an artist to its albums and from
  an album to its songs, in English and Italian.
- OpenAPI paths and schemas, contract test with a friend that is a whole
  server, and two real servers checked end to end.
2026-11-13 15:59:26 +01:00
tgiachi
89826fcd07 feat(federation): shared libraries and the signed read API for friends
A friend's server can now read what an admin chose to share.

- A library has a shared flag, off by default (migration 0024), set with
  PATCH /libraries/{id}. Changing it never waits for a scan.
- Requests between friends are signed with each server's Ed25519 key: the
  method, the path and query from /api/v1/peer on, a date, a nonce and the
  hash of the empty body. A date more than two minutes off, a nonce used
  before, an unknown or removed key and a bad signature all get the same
  401. A friend still waiting for approval gets 403, and while federation is
  off the routes are missing.
- Routes under /api/v1/peer: info, artists, albums, tracks, covers and
  streaming with Range. The catalogue, the counts and the format come from
  the shared libraries only, and the file served is the one in a shared
  library. No path, library id, listen, taste, user or provider data is part
  of an answer.
- A friend never makes this server build a cover, read an audio file or ask
  a provider: only covers already built from the audio files are served.
- Per-friend limits, set by the admin: parallel streams (default 3) and KiB
  a second (default 4096, 0 for none), shared by all the streams of a friend.
- A log of the last requests friends made (route, status, bytes; never the
  query), kept for 7 days, in GET /federation/requests.
- POST /federation/friends/{id}/check lets the side that pasted an invite
  find out that the other admin approved; a signed call from a friend this
  server is waiting for makes it active too.
- Admin: a Shared with friends switch on each library, which asks first, and
  limits, recent requests and a Check button in the Federation section, in
  English and Italian.
- OpenAPI paths and schemas, contract test, two real servers checked end to
  end with tagged audio files.
2026-11-13 15:04:07 +01:00
tgiachi
695a012f6c feat(federation): keys, invites and pairing between Sonda servers
Two servers can become friends. Federation is off by default; turning it
on makes an Ed25519 key pair, kept in the database and never returned.

- Admin routes: GET and PUT /federation (on or off, name, public address),
  POST /federation/invites, POST /federation/friends (use an invite),
  POST /federation/friends/{id}/approve and DELETE /federation/friends/{id}.
- POST /api/v1/peer/pair, the one route without a login: the code of an
  invite is the proof. An invite works once and expires in 24 hours; only
  a hash of its code is stored. At most 10 attempts a minute.
- The server that uses an invite checks that the key it gets back is the
  one named in the invite. A friend is kept as incoming or outgoing until
  both admins have agreed.
- https only, except plain http on a network of one's own (private,
  loopback or link-local address, or a local name).
- A client of its own for friends, with no redirects, no proxy from the
  environment, a size limit and a time limit; the providers' client stays
  as it is.
- Migration 0023 for SQLite and PostgreSQL, OpenAPI paths and schemas,
  contract test with two real servers.
- Admin > Federation in the web app, in English and Italian, and a
  section in the README.
2026-11-13 14:43:48 +01:00
tgiachi
82b92eaf08 feat(smart): covers on the Smart playlists page
- GET /smart-playlists/{id}/covers and GET /smart-playlists/suggested/{key}/covers say which albums stand for a smart playlist: up to 4 albums that have a cover, in the order of the songs the rules give now (for the variant asked), each once. They are worked out apart from the songs, and the answer may be kept for a few minutes.
- The cards of the Smart playlists page are a grid with the collage. The list shows at once and each card asks for its own covers after that, showing the rings until they arrive or when they cannot be read.
- The pages of a smart playlist and of a suggested one use the same covers for the variant on screen, so only albums that have a cover are shown.
2026-11-13 11:41:23 +01:00
tgiachi
a1e192066c feat: playlists with a cover, a collage of the covers of their albums
- A playlist says which albums stand for it (album_ids): up to 4 albums that have a cover, in the order they first appear in it, each once, read for a whole page of playlists in one query. An empty one has an empty list.
- The Playlists page is a grid of cards with the collage, and the page of a playlist shows it in its header. The pages of a smart playlist and of a suggested one show a collage of the albums of their first songs.
- Nothing is fetched for it: the covers are the ones the library already has.
2026-11-13 11:32:01 +01:00
tgiachi
1b79a7370d feat(naming): an admin section that shows what Claude costs
- Every question asked of Claude is recorded: when, the kind of list, the model, the tokens read and written (also for an answer that was no name but was billed) and how it ended: a name made, a name taken from the kept ones, or a failure and why. Nothing of the facts that were sent is recorded. Records older than a year are removed (migration 0022).
- GET /providers/anthropic/usage (admin) gives the totals of the last days (1 to 365, 30 by default), a row for each day with calls and an estimate of the cost in dollars, worked out from the tokens and the price of the model. It says it is an estimate and flags calls to a model whose price is not known.
- A Costs section in the admin area shows the last 7, 30 or 90 days.
2026-11-13 11:14:45 +01:00
tgiachi
0d8fadadf6 feat(naming): playlists named by Claude by themselves when it is on
- Keeping a mix, a smart playlist or a suggested smart playlist as a playlist with auto_name gives it the name and the line of description that Claude makes from its songs. The name sent stays the fallback when the provider is off, or Claude fails or declines, so a failure never stops a playlist from being made.
- A smart playlist can be made with no name when Claude is on: it names it from the songs the rules give. Without Claude a name is still needed.
- GET /naming says whether names are automatic, so the editor does not ask for a name that Claude will make.
- The web app always asks for an automatic name and sends the language of the page.
2026-11-13 11:00:23 +01:00
tgiachi
bf5c108785 feat(smart): the songs I play most, in rotation lately and over the year
- A smart playlist rule, plays_within_days, that counts only the plays of the last N days where plays are counted: the minimum of plays and the most and least played orders. The other listening rules are not changed.
- Two more suggested smart playlists on it: on-rotation (the most played of the last 30 days, at least twice) and top-year (the same over 365 days). most-played stays as the plays of all time.
- The editor has the new rule and the page says it in words. Texts in English and Italian.
2026-11-13 10:44:55 +01:00
tgiachi
23ae396430 feat(naming): names for playlists, with the Claude API as an option
- A pipeline over the facts about a list of songs (up to 5 genres, up to 8 artist names, how many songs, a few words about the rules of a smart playlist, the language). A local namer builds a name from the genres and the artists on this server and is always there; Claude is asked first only when an admin turned the new anthropic provider on with an API key. A failure or a refusal gives the local name. What Claude answers is kept under a hash of the facts, so the same question is not asked or paid twice.
- The anthropic provider: a write-only key (kept as typed, it is case-sensitive), a test that reads one model and sends no text, and a plain statement of what is sent. It uses the official Go SDK with nothing taken from the environment of the server (no key, profile, base URL or extra headers), no redirects, no system headers, and an answer that is cleaned and bounded.
- POST /playlists/{id}/suggest-name, POST /mixes/{id}/suggest-name and POST /smart-playlists/{id}/suggest-name answer with a name, a description and where it came from.
2026-11-13 10:33:48 +01:00
tgiachi
17f70d582d feat(smart): smart playlists made for everybody, without making them
- A fixed set that is there with no setup: recently added, never played, most played, not heard for a while, high quality files and long tracks. The rules are the same for everyone and are worked out on each one's own library and history, like the mixes; nothing is stored, so they follow the library.
- GET /smart-playlists/suggested, GET /smart-playlists/suggested/{key}/tracks and POST /smart-playlists/suggested/{key}/playlist.
- The Smart playlists page begins with them, with names and descriptions in the language of the page. A suggested one can be played, shuffled again, kept as a playlist, or made one's own: a copy of its rules opens in the editor.
2026-11-13 10:06:58 +01:00
tgiachi
1ad0d718c8 feat(mixes): a picture for each mix, a collage of album covers
- The server says which albums stand for a mix (album_ids): up to 4 albums that have a cover, by different artists, with most of the songs the mix draws from. The list gives them for every mix and a mix gives its own.
- The Mixes page shows the collage on each card (a 2 by 2 collage with four covers, the first one alone with fewer, the rings with none), and the page of a mix shows it in its header.
- Nothing is fetched for it: a mix has a picture once the covers of its albums were looked up.
2026-11-13 09:58:04 +01:00
tgiachi
a607070149 feat(smart): GET /genres, the genres of the library to choose from
Each genre with the number of playable songs, the biggest first and by name among equals. The spellings the files have are one genre, written the way the rules compare them, and tags such as other or unknown are left out.
2026-11-13 09:46:03 +01:00
tgiachi
104e41d10a feat(smart): smart playlists, playlists made of rules
A smart playlist is a set of rules, an order and a limit, kept under a name and worked out again every time it is opened.

- Rules (all that are set must hold): genres, artists and albums (is, or is not), file formats and a minimum bitrate of the same file, added in the last N days, never played, played or not played in the last N days, played at least N times, skipped or not skipped lately, only liked artists or without the avoided ones, and the length of the song.
- Orders: random (the same all day, a variant gives another), most played, least played, recently added, by title. A limit of 50 by default, 500 at most.
- GET/POST /smart-playlists, GET/PATCH/DELETE /smart-playlists/{id}, GET /smart-playlists/{id}/tracks, POST /smart-playlists/preview to try rules without keeping them, and POST /smart-playlists/{id}/playlist to keep what is shown as a normal playlist.
- Only the rules are stored (migration 0020); the songs come from the files and from the owner's own history and taste. Nothing is sent to a provider, and a smart playlist is its owner's alone. A user can have 200.
- Mixes and smart playlists share the way a list of songs becomes a playlist.
2026-11-13 09:36:52 +01:00
tgiachi
94dbf57544 feat(mixes): playlists made for a listener, by listening and by genre
GET /mixes lists the mixes a listener has, GET /mixes/{id}?variant= gives one with its
songs, and POST /mixes/{id}/playlist keeps one as a playlist of their own.

- Genre mixes: one for each genre with at least 30 songs by 4 artists, the genres the
  listener plays most first. Spellings that differ by case or punctuation are one
  genre (jazz+funk, jazz-funk); other and unknown are not genres.
- Made for the listener: Your favourites, Rediscover (liked artists not played for a
  month; both need history) and New to you (songs never played).
- A mix has up to 50 songs, at most 3 by one artist, never two of an artist in a row,
  picked by weighted chance (artist preference, never-played, less if played lately;
  skipped lately and avoided artists are out). The seed is user, mix, day and variant,
  so a mix is steady for a day and another is one variant away.
- Worked out when asked, from the listener's own history and the genre tags; nothing is
  stored and nothing leaves the server.

internal/mixes holds the selection and the service, internal/storage/mixes.go the
queries (SQLite and PostgreSQL). Spec, contract test, README and web types follow;
the web app comes separately.

Closes #95
2026-11-12 17:25:49 +01:00
tgiachi
3d986f051d Merge remote-tracking branch 'origin/main' into feat/duplicates-api 2026-11-12 17:00:00 +01:00
tgiachi
f900a22904 feat(playlists): a user keeps playlists of tracks
Each user can make playlists: a name (1 to 200 characters), an optional
description and an ordered list of tracks, where a track may appear more than once
(each place has its own item id). The API makes, lists, renames and deletes
playlists, and adds tracks (at the end or at a position), lists them, moves one and
removes one; positions count from 0 without gaps.

A playlist is its owner's alone: somebody else's answers playlist_not_found (404),
as one that does not exist. A track whose files were deleted or moved stays in the
playlist and is listed with available false. Deleting a user deletes their
playlists. Limits: 1,000 playlists per user, 10,000 tracks per playlist, 500 tracks
per request.

Changes of one playlist are serialised by locking its row, so two requests at once
keep the positions unique on PostgreSQL too. Migration 0019, OpenAPI spec, contract
test, README and the web API types follow. The web app comes separately.

Closes #89
2026-11-12 16:55:25 +01:00
tgiachi
fff24dfe25 Merge main into feat/duplicates-api 2026-11-12 16:53:50 +01:00
tgiachi
30f45bb383 feat(api): list the duplicate songs, check their files and delete the extra copies
Admin only. GET /library/duplicates lists the groups with what is needed to choose and never a path; POST|GET|DELETE /library/duplicates/check is the job that fingerprints the files; POST /library/duplicates/clean deletes the chosen copies of one song, each refusal with its own status and code (deletion_disabled, scan_running, invalid_input, track_not_found, duplicate_changed, library_read_only). In the spec with the contract test, and wired in main, where an info line says when library.allow_delete is on.
2026-11-12 16:46:50 +01:00
tgiachi
2669f6c6dc feat(images): ask again without the disc or edition note of a title
Many titles end with a note taken from the tags: (disc 2), (bonus disc),
(Deluxe Edition), sometimes cut off by a tag that is too short. A release group is
named after the album, not after a disc, so those albums found nothing.

The lookup now asks for the title as it is first and, only when MusicBrainz has no
sure result, once more without the notes at its end (baseTitle). A group in brackets
with none of the words of a note stays part of the title, and a title that would be
left empty is kept. The rule for accepting a result does not change.

On 25 albums of a real library with such notes, 19 found a cover (none before).

Closes #87
2026-11-12 16:35:23 +01:00
tgiachi
12f487f223 feat(images): find the cover of an album that has no MusicBrainz id
The covers asked the Cover Art Archive only for albums whose files carried a
release group id. In a library tagged without MusicBrainz, 3,321 of 3,433 albums
have none, so almost no cover could come from the archive.

An album with no id is now looked up in MusicBrainz by the name of its artist and
its title (musicbrainz.Client.FindReleaseGroup), when the musicbrainz provider is
on too. A result is taken only if MusicBrainz scores it 95 or more and its title
and one name of its artist credit equal the ones asked for after folding case,
accents and punctuation; the first such result wins and anything doubtful is no
cover. The id is used for that request and is not stored on the album.

Artists are still never looked up by name. The MusicBrainz and Cover Art Archive
provider texts, the README and the API spec say what is sent.

On 47 albums sampled from a real library, 23 got a cover (all checked as the right
ones by eye or by exact title and artist); a title like 'Live (disc 2)' finds nothing.

Closes #83
2026-11-12 16:22:02 +01:00
tgiachi
96ad8b1f62 feat(auth): accounts are identified by an email address
Registration, login and the admin's create-user call take `email` instead of
`username`, and the user object returns `email`. The address is checked for its
shape (a plain address, no display name, at most 254 bytes), trimmed, lowercased
and unique. Sonda sends no mail and does not verify it.

- Migration 0018 renames the users column (and the PostgreSQL index); values are
  kept, so an account made before keeps its plain name and still logs in with it
  (login does not check the shape).
- Error code username_taken becomes email_taken; the JWT claim is now `email`,
  so access tokens issued before the upgrade are refused once and clients refresh.
- OpenAPI spec, README, the web login form (type email), strings (en, it) and
  the generated API types follow.

Closes #65
2026-11-12 14:40:33 +01:00
tgiachi
69da67065d fix(discover): refusals do not wait for a turn, and waiting for one has an end
- The gate now comes after what only the database decides (a seed that is not an
  artist, no seed and no permission), so those answers are not held up by three
  slow Discovers and do not make the listener "busy".
- A request that waits more than 30 seconds for a turn answers 429 instead of
  hanging for as long as the providers are slow.
- The spec and the README say that a waiting request counts as running.
2026-11-12 12:00:18 +01:00
tgiachi
63fee32271 feat(discover): one Discover at a time for each listener, three at once on the server
A cold Discover can make dozens of provider requests, and nothing stopped one
listener, or a client that keeps opening and cancelling requests, from lining up
work for the providers and slowing everyone else's.

- A listener who already has a Discover running gets 429 `discover_busy` with
  Retry-After, at once.
- At most three Discovers run at the same time, whoever asks; the others wait for
  their turn, and one that stops waiting does no work and keeps no place.
- The place and the turn are given back when a Discover fails or ends.
- Spec and README describe it; the fakes of the tests are safe for parallel runs.
2026-11-12 11:52:20 +01:00
tgiachi
8160c33960 feat(lidarr): send an artist to Lidarr and see whether it has it
- POST /artists/{id}/lidarr (admin) adds the artist to the admin's own Lidarr by its
  MusicBrainz id, never by name, with the profiles, the folder and the monitor
  option the admin chose. It works for any artist that has an id, also one that
  Sonda only learned of from a list of similar artists. It can be repeated: an artist
  that Lidarr already has changes nothing. Two sends at once go one after the other.
- GET /artists/{id}/lidarr (signed in) says whether Lidarr has the artist and
  monitors it; what stops the answer is a status (disabled, no_id, not_configured,
  error), as for the descriptions.
- It needs the provider switched on and the profiles and folder chosen; a timeout
  says the artist may have been added anyway.
- Spec, contract test and README, which also say that Sonda downloads nothing.
2026-11-12 11:28:15 +01:00
tgiachi
4dbe1074ba fix(lidarr): saved defaults, conflicts, no proxy, readable addresses
- Setting the address alone now stores the default options (monitor all, search
  for missing albums), so what is shown is what will be sent.
- A 409 from Lidarr, when two adds of the same artist cross, means the artist is
  already there; only "an artist with this ID was not found" is an unknown artist.
- The client never goes through a proxy named by the environment, since Lidarr is
  on the admin's own network and the key travels in a header.
- An address that cannot be read back (an IPv6 zone) is refused instead of being
  stored and reported as "not configured".
- A deadline asking Lidarr is a bad gateway, not an internal error; a redirect is
  reported with a hint to use the final address; the request schema of the Lidarr
  options is closed.
2026-11-12 11:11:35 +01:00
tgiachi
fb9e923197 feat(lidarr): set up Lidarr as a provider and read what it offers
Lidarr is a server of the user's own that looks for and downloads music. Sonda
never downloads; this is the first piece of letting an admin send it an artist.

- The `lidarr` provider, off by default: an address, an API key (32 hexadecimal
  characters, never returned) and, chosen once, a quality profile, a metadata
  profile, a root folder, the monitor option and whether to search for missing
  albums. It cannot be enabled without an address and a key.
- The address is checked: http or https, no user and password, no query, no
  fragment, no closing slash.
- A small client of its own, apart from the outbound one (which only makes plain
  GETs): the key travels in a header, no redirect is ever followed, answers and
  time are bounded, and the address and key are read for every request.
  Status, options, artist by MusicBrainz id and add (lookup, then the add that
  Lidarr's own screen sends).
- `GET /providers/lidarr/options` lists the profiles and root folders; the test of
  the provider checks the address and the key (`no_address` when it has none).
- Migration 0017 adds the address and the options to the provider settings.
- OpenAPI, contract test and README say what is sent and where.
2026-11-12 11:04:53 +01:00
tgiachi
271c88743c feat(search): search ignores accents
- A search key apart from the key that identifies artists, albums and tracks:
  lower case, accents taken off (Latin, Greek and Cyrillic marks only, so kana
  and Hangul stay intact), and letters like ß, æ, ø, ł written plain.
- GET /artists, /albums and /tracks look in it, so "bjork" finds "Björk" and
  "strasse" finds "Straße".
- "Beyoncé" and "Beyonce" stay two artists: the identity key keeps accents.
- Migration 0016 adds the column on SQLite and PostgreSQL; RefreshMatchKeys
  fills it for existing rows at start.
- golang.org/x/text is now a direct dependency.
2026-11-12 10:17:21 +01:00
tgiachi
9323702b1e fix(jobs): a stop or a panic never wedges a job, a bad download never replaces a good picture
- A panic while counting no longer leaves the job marked as running; a panic in the
  work of one item is a failure of that item, and a panic in the list ends the job
  with a reason.
- A stop while the items are counted is recorded as a stop instead of a 500, and a
  count that fails leaves the status as the previous job left it.
- An artist that lost its MusicBrainz id since it was listed is skipped by the
  pictures job, as the spec says, instead of counting as a failure.
- A picture that cannot be used now (refused download, bytes that are not an image)
  is a failure when a good picture is stored, so a refresh never throws it away.
- The outcomes the artist jobs report share their constants in the jobs package.
- The spec no longer calls each job "the one request" that goes through the library.
- The test that waited with a sleep for the count now waits for a signal.
2026-11-12 10:09:46 +01:00
tgiachi
e3843ad7d6 feat(jobs): background jobs for artist photos and descriptions
Add one engine, internal/jobs, that runs the jobs which go through the whole
library: start, stop, progress, one at a time, give up after five failures in
a row, end at once when a provider is off.

- The covers job now runs on the engine; its API is unchanged.
- POST/GET/DELETE /library/artist-images looks for the picture of every
  artist of the library that has a MusicBrainz id.
- POST/GET/DELETE /library/descriptions does the same for the Wikipedia
  description.
- ?refresh=true searches everything again and never replaces a stored result
  by a failure; artists without an id are never touched, nothing is looked up
  by name.
- images.Service.EnsureArtistImage and about.Service.Ensure do the work for one
  artist; the lists come from ImageRepo and DiscoveryRepo.
- jobs.Runner binds a job to the application context, replacing the two
  hand-written controls.
- OpenAPI, contract test and README describe the new endpoints and say that
  they are bulk requests.
2026-11-12 09:58:45 +01:00
tgiachi
345ad8eecb fix(images): a refresh never wipes covers, the job sees outages and starts cleanly
- A refresh (or any rebuild) while the Cover Art Archive is switched off, but its data
  not taken back, no longer turns the covers it gave into "no cover" and deletes their
  files: the stored cover is kept and its date renewed, so the files are not searched
  again at every request.
- When none of an album's files and folders can be looked at (an unmounted disk, a
  permission), that is ErrFilesUnreadable (503 files_unreadable), not "no picture": nothing
  is remembered, nothing built is touched, the archive is not asked, and the job counts it
  as a failure and gives up after five. A link that leaves the library is still just refused.
- The job calls the build for every album that is not good yet and does not serve an older
  cover on an outage, so a dead provider shows as failures and trips the limit instead of
  being reported as covers from the archive.
- Start marks the job as running before counting the albums and does not hold the lock
  meanwhile; a stop that comes back as a plain driver error is not a failure; a job that
  finished by itself is never marked stopped.
- Spec and README say so; the tests cover each case, including a list that fails midway.
2026-11-12 09:43:51 +01:00
tgiachi
548ee03d83 feat(images): a background job that builds all the covers
- POST /library/covers (admin) starts, in the background and one at a time like a scan,
  a job that builds the cover of every album that has something to play and no cover that
  is still good; GET /library/covers shows the progress and how the last job ended;
  DELETE /library/covers stops it. ?refresh=true searches every album again.
- For each album it does what opening its cover does: the user's own files first, then the
  Cover Art Archive if the provider is on. It gives up, and says why, when the provider
  fails for five albums in a row; an album that vanished is skipped, not a failure.
- This is the one request that goes through the whole library, and the README and the
  provider text say so: with the archive on it sends the release group id of each album with
  no picture in its files, one after the other, spaced out.
- NewRouter now refuses to build when a service was not wired, naming it, instead of
  panicking at the first request (the wiring of this job in main had been missed, which no
  test could see).
- The outbound spacing test measures where the request leaves the client, so a busy
  machine cannot make it fail.
- Spec, contract and HTTP tests, README updated.

Closes #45
2026-11-12 09:34:27 +01:00
tgiachi
5fecd394e4 fix(images): purge removes every archive cover, the id of an emptied album moves on
- The covers that come from the Cover Art Archive now live in a folder of their own
  (images/album-remote). Taking the provider's data back deletes that folder, so nothing
  from the archive is left whatever became of its records: a rescan makes a record stale
  and a later search that finds nothing replaces it, and neither of those used to remove
  the files. A cover that moves between the user's files and the archive, or goes away,
  no longer leaves the old files behind.
- A redirect to a place that is not allowed is an outage (502, not remembered, an older
  cover served), not "no cover" for a day for every album. A picture over the limit is
  still "no cover".
- A track that moves to another album (a fixed title) leaves the first with no track: it
  gives up its release group id, so the album the track went to can take it. An album
  that has an id keeps it; an id another album owns is not given twice.
- Waiting for a local slot is no longer reported as the provider being unreachable, and a
  build whose reads were purged three times is not served with files that were never written.
- README and spec no longer say covers never contact anybody.
- Tests: the new folder and the purge after a rescan, files left by a replaced cover, the
  local wait, repeated purges, a refused redirect, the update path with a taken id and the
  emptied album.
2026-11-12 09:21:11 +01:00
tgiachi
d5ed0f2e9c feat(images): album covers from the Cover Art Archive
- The scan reads the MusicBrainz release group id of an album from the tags of its
  files (MUSICBRAINZ_RELEASEGROUPID, a vorbis comment or an ID3 frame) and stores it in
  albums.mbid: it is taken only when the file has an album and exactly one valid id, an
  album keeps the one it has, and an id that another album owns is not given twice. A full
  rescan reads it for music that was already indexed.
- New provider "coverartarchive" (off by default, no key, contact in the User-Agent). When
  an album has no picture in the user's own files, which always come first, its cover is
  asked from the archive by that id and never by a title: only the id leaves the server.
  The same GET /albums/{id}/cover; the record keeps the source. An outage is a 502
  provider_unavailable and is not remembered, and an older cover is served in its place.
- The archive answers with three redirects (coverartarchive.org, archive.org, a data node
  whose name changes). The outbound client can now follow redirects, but only the ones the
  caller allows, up to a limit; here that is https on archive.org and its subdomains.
- A purge counter now guards the covers too: a read that started before the provider's data
  was taken back is not kept. Removing the provider's data forgets the covers that came from
  it and deletes their files, and leaves the ones from the user's files.
- Spec, contract and HTTP tests, README updated; the facts of the real archive are written down.

Closes #43
2026-11-12 09:09:31 +01:00
tgiachi
9e85d4d1ea fix(images): outages are 502, purges are not undone, bad pictures are not outages
- A timeout inside the provider (the outbound client's own deadline, which wraps
  context.DeadlineExceeded) was mistaken for the caller leaving and came out as a 500, so
  an older stored picture was not served. The decision now uses the caller's own context,
  and a build that runs out of its two minutes is an outage (502) too.
- A purge of the Commons data could be undone by a read that was already running: the row
  was deleted, so the generation guard started from zero, and the files were written after
  the files were removed. Pictures are now kept only under a purge counter; BeginArtistPurge
  is called before the purge and a read that started earlier starts again, or is refused if
  the provider is off by then.
- A redirect or an oversized picture from the picture host is a fault of that picture (no
  picture), not an outage, and the pictures are downloaded through a client of their own so
  that one bad file cannot open the breaker of the API calls.
- The author drops the invisible characters that reorder or hide text. Artist pictures are
  decoded only up to 4 million pixels.
- Tests: an outage that ends in a deadline, a build that times out, a purge during a read,
  a redirect and a huge picture from the host, a separate download client.
2026-11-11 22:12:49 +01:00
tgiachi
e752d15536 feat(images): free photos of artists from Wikimedia Commons
- GET and HEAD /artists/{id}/image serve a free picture of an artist as a JPEG
  (size=small 300 px or large 1000 px, token in the query allowed for an <img>), and
  GET /artists/{id}/image/credit gives the author, the licence and the page of the file,
  to be shown next to it.
- New provider "commons" (off by default, no key, contact in the User-Agent), which also
  needs MusicBrainz on. The way to the picture uses ids only, never a name: the artist's
  MusicBrainz id, the Wikidata item MusicBrainz links to it, the file Wikidata names for
  it (P18), Commons for its licence, and a 960 px copy from a Wikimedia picture host.
- Only free licences: public domain, CC0, CC BY and CC BY-SA. Non-commercial,
  no-derivatives, GFDL alone, fair use and unknown licences are refused, since a copy is
  kept. The author is plain text, the licence address is kept only on creativecommons.org,
  and the download only from https thumb.wikimedia.org or upload.wikimedia.org.
- Built on the first request, kept in the data folder: 30 days, or a week when there is no
  free picture; an older copy is served when Commons cannot be reached; a failure is not
  remembered. Credit changes change the ETag.
- Removing the provider's data forgets the records and deletes the files; a read that started
  before it is not saved over it.
- images table gets the credit (migration 0015); the purge reports images.
- Spec, contract test, README updated; the facts of the real APIs are written down.

Closes #41
2026-11-11 22:03:32 +01:00
tgiachi
762d424816 fix(about): unusable pages fall through, MusicBrainz switch, merged items
- A page that cannot be used (no text, an address off Wikipedia, a redirect that is
  never followed) is now an answer: the chain goes on to the next language and the
  outcome is stored. Before, it was a failure asked about again at every view, and
  redirects counted against the provider's breaker.
- The chain also needs the MusicBrainz provider to be on, since the id goes to it
  with its own contact: nothing is sent to MusicBrainz that the admin did not allow.
  The disclosure in the provider settings, the spec and the README say so.
- A Wikidata item that was merged into another is understood through the target: the
  entity's own id is returned, compared with the page's item and stored. Verified on
  the real API.
- The title shown is the one Wikidata names (with spaces), control characters are
  dropped from the text (PostgreSQL refuses NUL), the text is cut to at most 4000
  characters with the mark included, and a stored description is reported disabled
  when the provider is off.
- A read that started before the provider was switched off does not save its result.
- Tests: the real clients with a redirect and a page without text, merged items,
  MusicBrainz off, switching off during a read.
2026-11-11 21:45:20 +01:00
tgiachi
48cb903115 feat(about): artist descriptions from Wikipedia
- GET /artists/{id}/description shows what Wikipedia says about an artist: a short
  text with its page, a link and the licence (CC BY-SA 4.0).
- New provider "wikipedia" (off by default, no key, contact in the User-Agent, which
  Wikimedia requires). The way to the text is a chain of ids, never a name: the
  artist's MusicBrainz id, the Wikidata item MusicBrainz links to it, the Wikipedia
  page Wikidata names in the first configured language that has one. A page is used
  only if it is an article about that same item.
- [wikipedia] languages in the config (one to five codes of two or three lower case
  letters, checked before they are sent: an unknown site makes Wikidata answer with
  every language).
- Stored 30 days (a day when there was nothing to find), served stale if Wikipedia
  fails, removed with the provider's data (the purge now reports descriptions).
- MusicBrainz client: WikidataID. Wikipedia client for Wikidata and the summary,
  which also reads Wikidata's errors that come with HTTP 200.
- artist_descriptions table (migration 0014, SQLite and PostgreSQL).
- Spec, contract test, README and example config updated.

Closes #39
2026-11-11 21:36:27 +01:00
tgiachi
7bdbc9e160 fix(images): limit parallel builds, no stale saves, safer files
- At most two covers are built at the same time: a page of albums asked for at once
  could decode dozens of large pictures together.
- A change to an album's files marks its record stale and moves a generation instead
  of deleting the row. A build that started before the change is not saved over it
  and starts again, so a "no cover" found too early cannot win for a day.
- A cover that was found is checked again after a week, so a picture replaced in a
  folder is noticed.
- For CD1/Disc 2 folders the picture in the folder above is used. Folder pictures
  are read one at a time, and the pixel count is computed in 64 bits.
- Stored files are synced before they get their name, an empty one counts as
  missing, and old temporary files from a crash are removed.
- Files without track or disc numbers sort the same on both databases.
- storage.data_dir defaults next to the SQLite database, so a service started from
  another folder does not need a writable working directory.
- Tests: a listener who leaves, a change during a build, the build limit, a named
  pipe, an embedded picture of a file outside the library that exists, builds that
  really overlap.
2026-11-11 21:03:26 +01:00
tgiachi
0e121ead8e feat(images): album covers from my own files
- GET and HEAD /albums/{id}/cover serve a JPEG made from the picture embedded in
  the album's files, or else a cover, folder, front, album or albumart image
  (jpg, jpeg, png) in the album's folder. ?size=small (300 px) or large (1000 px).
  The token can be in the query, so an <img> element can use it.
- Built the first time it is asked for, scaled, and kept in storage.data_dir
  (SONDA_DATA_DIR, default "data"); an album with no cover is remembered for a day.
  A new or changed file of the album, or a full rescan, clears the record.
- Nothing is sent anywhere. Pictures are untrusted: files are opened inside the
  library only (links are not followed), over 20 MB or 16 million pixels are
  ignored, and what is served is always a JPEG made here. Stored files are 0600.
- images table (migration 0013, SQLite and PostgreSQL).
- Spec, contract test, README and example config updated.

Closes #37
2026-11-11 20:52:36 +01:00
tgiachi
65e93ee84b fix(feedback): purge only what the provider named, no leak between users
- Purging a provider removes only the artists that provider's lists named. A
  purge of MusicBrainz, which names none, no longer deletes an artist only a
  wish kept alive, nor the wish.
- A mark no longer makes an artist visible to everybody: GET /artists/{id} and
  the similar lookups did, which showed what other users marked. Marking or
  unmarking needs an artist the user can see or has marked themselves, with the
  same answer for both.
- Deleting an account cleans up the discovered artists only its marks kept, in
  the same transaction and under the artist lock.
- Tests: a purge of another provider, deleting an account, the scanner adopting
  a marked artist, and what another user can see of a marked artist.
2026-11-11 20:18:04 +01:00
tgiachi
a6dbf60ac8 feat(feedback): a wishlist and "not interested"
- PUT/DELETE /wishlist/{artist} and GET /wishlist: the artists I want.
- POST/DELETE /discover/{artist}/dismiss and GET /discover/dismissed: the
  artists I am not interested in. An artist is wished or dismissed, never both,
  and both lists are mine alone.
- Discover never suggests a dismissed artist, does not use one as a seed taken
  from my listening, and marks the wished ones it shows (wishlisted).
- New artist_feedback table (migration 0012, SQLite and PostgreSQL), removed
  with the account.
- An artist I marked is not cleaned up when the list that named it is replaced,
  and goes when its last mark is taken off and nobody names it. Taking a
  provider's data back still removes what only it named, marks included.
- Spec, contract test and README updated.

Closes #35
2026-11-11 20:11:18 +01:00
tgiachi
f548423f73 fix(discover): ask permission first, stable order, honest docs
- Check the discover_from_listening setting before reading the listening
  history, so a refused request does no work and a database failure cannot turn
  it into a 500.
- Cosine adds up in tag order: the sum in map order changed in the last digit
  between runs, and equal artists could swap places between requests.
- A seed that could not be read is no longer listed as a seed.
- README and spec: Discover exists now; "disabled" means something had to be
  asked and Last.fm is off; the stored lookups are shared, so another local user
  can see from retrieved_at that an artist was looked up, but not who.
- Tests: the history is not read for a refused request, a stable cosine, tags
  fetched only for the pool and four at a time, a cancelled request stops,
  MusicBrainz is never asked, the setting is per user.
2026-11-11 19:48:51 +01:00
tgiachi
28c249c268 feat(discover): artists I may like, with a score I can explain
- GET /discover suggests artists, in my library or not, with a score from 0 to 1
  and its parts: affinity (similar to the artists I like), genre (tags close to
  mine), preference (what my listening says) and discovery (a bonus for what I
  have not played). Default weights 0.40, 0.25, 0.25, 0.10, set in [scoring].
- A part with no data (no tags) is left out and the others rescaled; the answer
  says which parts were there, and which seeds led to each suggestion.
- Seeds are the artists I name with ?seed=, or, only when I turned on
  discover_from_listening, the artists I play most. Without either the request is
  refused and nothing is sent to anyone.
- The tags of the best candidates are read from Last.fm only, only for those with
  none stored, a few at a time.
- taste.Service.Learn gives the whole picture (every preference, the liked
  artists, the tag profile); TagService.ProviderTags asks one provider.
- Spec, contract test, README and example config updated.

Closes #33
2026-11-11 19:42:09 +01:00