- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
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.
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
playlist_items.track_id is ON DELETE CASCADE (added by the playlists work on main), so deleting a
duplicate would have taken the song out of every user's playlists, as it would have done with the
listens. RemoveCopy now repoints the items first, in the same transaction.
Also merges main (playlists) into the branch.
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
Candidates are the playable files whose title another file shares. A fingerprint is kept only for the file that was read (same size and date), and a scan that finds the file changed forgets it. Removing a copy moves its listens to the track that stays, because they would be deleted with the track, then removes the track with its file, credits and genres. Tested on SQLite and PostgreSQL.
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
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
The refresh at start fixed each stale row with its own UPDATE. On PostgreSQL that
is one round trip per row: 100,000 stale rows took 5.3 s on localhost, and more
over a network. The rows now go 500 at a time in one UPDATE ... FROM (VALUES ...):
1.9 s for the same rows. SQLite keeps one UPDATE per row, which is faster there
(no round trip to save). A run with nothing to fix is unchanged (about 0.1 s per
100,000 rows).
A test with 1,250 stale rows covers more than two batches on both databases.
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.
- A search text that has nothing left once its accents are taken off matches
nothing instead of everything.
- The search key folds compatibility forms (the ligature "fi", full-width
letters) and the Greek final sigma.
- The start-up refresh of the keys logs when it starts and how long it took, since
it can take a while on a big library the first time.
- More tests: a retitled track is found by its new title, a refresh fixes both
keys and keeps "Beyoncé" and "Beyonce" apart, more cases for the key.
- 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.
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.
- 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
- 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.
- 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
- 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
- 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
- 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.
- 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
- 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.
- 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
- PATCH /me/settings accepts exactly one JSON object: text after it, null, a
differently cased name or an unknown name are refused (400) and change nothing.
- A user deleted between the read and the write of the settings gives 401, not a
500, on PostgreSQL too (foreign key violation mapped to user not found).
- The spec says a 401 can also mean the account no longer exists, and that the
body is strict.
- README no longer says more than the setting does.
- Tests: strict body cases, tokens of a deleted account on GET and PATCH,
recognising a foreign key violation on both databases.
- GET and PATCH /me/settings: settings that belong to the signed-in user.
- First setting, discover_from_listening, is off by default. When on, Discover
may start from the artists I listen to most, which sends their names to
Last.fm.
- New user_settings table (migration 0011, SQLite and PostgreSQL), removed with
the account. A user with no row has the private defaults.
- A misspelt setting is rejected instead of being ignored.
- Spec, contract test and README updated.
Refs #29
- Order the liked artists by the weighted sum, not by tanh, which rounds to
exactly 1 after about 58 listens and made heavy artists tie.
- An event dated after now counts as happening now, also for the last listen.
- Genres of files that are gone no longer shape the tag profile, as in
/artists/{id}/tags.
- The tag list is capped at 50.
- A zero half-life falls back to 90 days instead of producing NaN.
- Document the 10 half-lives window and the new rules in the spec and README.
- Tests: heavy artists keep their order, tracks with two artists credit both,
genres of a missing file are left out, the tag cap, a zero half-life.
- taste package: each listening event has a value (complete +1, a play that
counts +0.5, a skip that does not count -1, a short play 0), older events
weigh less (half-life 90 days, taste.half_life_days), and the values of an
artist become a preference in (-1, 1) with tanh.
- Tag profile built from the artists I like: genres of my files plus the tags
already stored from providers, each source scaled to its own best tag.
- GET /me/taste shows the liked artists and the tags. It reads local data only
and never asks a provider.
- TasteRepo reads events, names and tags; tests on SQLite and PostgreSQL.
- OpenAPI spec, contract test, README and example config updated.
Closes#27
- fix: on PostgreSQL a purge could delete a discovered artist while a scan was
adopting it. The scan then failed on the missing artist for the whole file,
and the two could also deadlock. Purge now takes the same artist lock as the
scanner and discovery before it removes anything. Saving a list or tags does
too, and an artist that is gone by then is reported as not found instead of a
foreign key error, so a user who opened an artist that was removed meanwhile
gets a 404
- fix: a discovered artist that was only the source of a list stayed forever and
kept the artists of its own list alive, so chains built up. Cleanup now removes
such an artist and then follows the chain until nothing more goes
- fix: in a full rescan a file that came back but could not be read stayed
marked missing. It is restored first, as in a normal scan, and read as well
- fix: ?full given twice is refused, so a typo cannot start a scan of another
kind
- fix: genre cleaning lives in one place, used by the reader and the store
- docs: the files genres count the tracks the artist is credited on, and the spec
says every files tag is a genre
- test: a purge colliding with a scan on both databases (it fails without the
lock), a chain of discovered artists, saving for an artist that is gone, a
file that returns unreadable during a full scan
- feat: DELETE /api/v1/providers/{name}/data (admin) removes everything a
provider gave: its lists of similar artists, its tags and the records of
when it was asked, then the artists that only that data named and that
nobody has files for. Last.fm's terms ask for this when an agreement ends.
The user's own artists, music, listens and settings stay, the provider is not
switched off, and a second call removes nothing
- feat: a discovered artist that no list names any more is removed when the
list that named it is replaced, together with its tags, so they do not pile
up. Real artists, and any artist that another list still names, are kept
- feat: the scan reads the GENRE tag of each file, offline (several genres
separated by ";", lower case, at most five per file), and
GET /artists/{id}/tags gets a third entry, files: the genres of the artist's
own playable tracks, each weighted by how many tracks have it. It asks nobody
and is always there
- feat: POST /library/scan and POST /libraries/{id}/scan take full=true to read
every file again, not only the new or changed ones, so MusicBrainz ids and
genres reach music that was indexed before. Files keep their identity, so
listening history is kept. Anything but true or false is a 400
- test: the plan of a full scan, the scanner and the manager; the purge on both
databases, checked by removing the rule that spares real artists; the
cleanup of replaced lists; genres per file and per artist
- docs: README, OpenAPI and the todo list updated
- fix: a discovered artist adopted by id under another spelling kept its old
match key, so the next file with the new spelling and no id created a second
artist. The key now follows the name
- fix: when a real artist without an id and a discovered artist holding the id
have the same name, the id now goes to the real artist and the discovered one
lets go of it. Before, the scan created a second real artist and a second
album, and could not repair it because the id was taken
- fix: when a file without an id adopts a discovered artist that had a provider
id, the tags, the fetch records and the similar artists read under that id
are dropped, since they are not known to be about the user's artist. Links
from other artists to it stay. A file that confirms the very same id keeps
everything
- fix: the album artist id is only read when the file has an album artist tag;
with the tag missing the name is a fallback and the id would have landed on the
wrong artist (a Various Artists id on the track's own artist)
- fix: one artist credit with one id ("X feat. Y" with the id of X, how beets
writes it) is not paired: no id is safer than a wrong one. A name that is
itself a single letter or contains a slash still gets its id
- fix: on PostgreSQL the scanner took the artist lock after it had already
changed artist rows, which could deadlock with a concurrent similar-artists
save. SaveFile now takes the lock first, once
- fix: Last.fm does not know every MusicBrainz id: when it does not know the id
and there is a name, the name is tried, never autocorrected, as before ids
were read from files
- fix: waiting for one provider's tags is bounded at 20 seconds, so a rate
limited provider cannot hold a page for a minute
- docs: the tag range is 1 to 100 (a tag with no votes is dropped), the spec says
where an artist's id can come from, and the README says when Last.fm gets an id
- test: adoption by spelling, the real artist with a discovered namesake,
dropping and keeping what was read, album artist fallback, credits, an ID3
frame, and the id-then-name fallback of Last.fm
- feat: GET /api/v1/artists/{id}/tags lists, for each provider that is on, the
tags it gives to an artist with its own weights, kept as they came: Last.fm's
are relative to the artist, MusicBrainz's are counts of votes, and they are
never mixed. MusicBrainz also marks the tags it lists as genres. The same
rules as similar artists apply: asked only on demand, kept 7 days (1 for an
unknown artist), old data served when a provider fails, and one call for
simultaneous requests. A provider that is off, failing or lacking an id does
not hide the other
- feat: a thin MusicBrainz client that reads an artist's tags and genres by its
id. It never searches by name, because a search returns look-alikes and
picking one would be a guess. The id is checked before it reaches the path,
and errors never repeat the provider's text
- feat: the User-Agent can change while the server runs, so the contact an
admin sets for MusicBrainz applies to the next request; if the settings
cannot be read it falls back to the project address
- feat: Last.fm top tags, by id when known and by name otherwise, never
autocorrected
- feat: the scan reads MusicBrainz artist ids from the file tags, offline, and
keeps them on the artists. An id is only used when it can be paired with its
artist for certain: the same number of ids as artists, all valid. The same id
is the same artist whatever the spelling, an artist without an id takes the
one its file gives, and another id under the same name is another artist. A
file that confirms the id a provider gave to a discovered artist keeps it
- feat: POST /providers/musicbrainz/test checks that the service answers
- test: what leaves the server for MusicBrainz is checked from the other end:
the id of the artist and the admin's contact, nothing from the library;
removing the safeguards on ids and pairing makes tests fail
- docs: README, OpenAPI and the provider text updated
- fix: on SQLite a transaction that read and then wrote failed at once with
"database is locked" when another writer committed in between, because the
busy timeout does not apply there. Transactions now start with BEGIN
IMMEDIATE. Before this change a scan running while someone opened similar
artists made files fail, and parallel requests stored nothing
- fix: on PostgreSQL two requests naming the same new artist could fail on the
unique MusicBrainz id or leave two rows with one name. Creating artists, in
the discovery store and in the scanner, now takes turns through an advisory
lock and looks again once it has the turn
- fix: music arriving for an artist that a provider only named used to keep the
provider's spelling and its unchecked MusicBrainz id, which later lookups
would then send instead of the name. Such artists are now marked
(artists.discovered); the first scan that finds them renames them to the
spelling of the file tags, drops the id and clears the mark
- fix: a panic in the shared provider call is turned into a failure; the
singleflight group would have re-raised it where nothing can recover
- fix: a client that leaves while Last.fm is being asked no longer gets a 500
and an error in the log
- fix: no page can ask for more than is stored (limit tops out at 50), and the
docs no longer say the best score is always 1
- test: concurrent saves plus a scan on both databases, checked by removing each
fix; adoption keeps neither the name nor the id; the panic; the client that
leaves
- feat: GET /api/v1/artists/{id}/similar lists the artists Last.fm finds similar
to one in the library, best first, each with the provider's own score and
rank and a flag saying whether it is in the library. It answers 200 when the
provider is off or failing, with provider_status, stale and retrieved_at
- feat: a thin Last.fm client on top of the outbound client. It always sends
autocorrect=0 so a misspelled local name cannot turn into another artist,
prefers the MusicBrainz id when known, always sets a limit, and reads the
error field even when the status is 200. Errors never carry the URL or the
provider's own message, because the key travels in the query string
- feat: results are stored in artist_similar with a freshness ledger in
provider_fetches: 7 days for an answer, 1 day for "unknown artist". Old data
is served when the provider fails, and concurrent requests for the same
artist share one call that does not depend on the first caller staying
- feat: artists named by a provider but without files become artists without
tracks. GET /artists/{id} can show them (track_count 0), the lists of the
library never include them, and a later scan adopts them by name. A provider
id is never written onto an existing artist; names match only when at least
one side has no id, and different ids always mean different artists
- feat: POST /providers/{name}/test (admin) checks a stored key with one cheap
request, whether the provider is on or off, and reports ok, no_api_key,
key_refused, rate_limited, unreachable or error
- test: the whole request is checked from the receiving end, with a user, a
listen, a title and a library path in the database: only the artist and the
key leave, with a User-Agent that names the project
- docs: README and OpenAPI updated; the contract test calls the new operations
- feat(storage): provider_settings table (provider, enabled, api_key, contact);
migration 0007 for both drivers. A provider with no row, or turned off, is
never contacted
- feat(providers): a service that validates and applies settings: a Last.fm key
is 32 hexadecimal characters, enabling a provider that needs a key without
one is refused, clearing the key turns the provider off, a contact cannot
contain parentheses or control characters. Each provider states what it sends
and under which terms, and what it never sends
- feat(api): admin-only GET /providers and PUT /providers/{name}. The API key is
write-only: responses carry only has_api_key, errors never repeat it and the
request log never contains it (tested)
- feat(providers/outbound): the only way Sonda talks to the outside: plain GET
with an identifiable User-Agent, no cookies, no Referer, no Authorization, no
redirects, bounded answers, a timeout per attempt, a minimum interval between
requests, retries with exponential backoff that honour Retry-After without
waiting past the caller's deadline or for an absurd time, and a circuit
breaker that makes a failing provider fail fast
- feat(providers): UserAgent builds "Sonda/version ( contact )" as MusicBrainz
asks, defaulting to the project address so no personal address is sent
- breaking(config): providers.lastfm and SONDA_LASTFM_API_KEY are gone; an old
config, or the variable, fails with a hint instead of being ignored
- docs: OpenAPI operations and schemas, README section on the providers and on
what leaves the server
- test: fake servers and a fake clock only; no network in the suite
- fix: a listen from a deleted account is answered 401 before the track or the
duration is looked at, so a client that signs out on 401 does it whatever
else is wrong with the request (UserExists on the store)
- docs: one event per play, sent when the play ends or is abandoned, with one
idempotency key per play. An event cannot be upgraded afterwards: a key that
was already used is ignored even if the type or duration differ, and a new
key would count the same play twice. The README no longer says to report at
20 seconds, which led straight into that trap, and no longer hard-codes the
minimum
- test: the SQL filter at exactly the threshold and just under it, the order of
events within the same second, the order of checks for a deleted account
- feat: an event counts as a listen when it is `complete`, or when it was
played for at least listening.min_listen_seconds (default 20, 1 to 3600).
The rule is applied when the history is read, not when an event is stored,
so changing the setting re-reads the past; streaming never counts
- feat(api): POST /listens answers with `counted`, also for a duplicate
- feat(api): GET /listens returns the signed-in user's own history, newest
first, with `counted` per event, paging and ?counted=true; nobody sees
anybody else's events
- feat: a reported play time more than twice the track length plus ten seconds
is rejected as implausible; looping and seeking back stay allowed, and a
track of unknown length is not checked
- feat(storage): TrackDurationMs and ListEvents on SQLite and PostgreSQL
- docs: OpenAPI operations and schemas, README rule, setting, API table and a
demo that reports a 25 s and a 3 s play and reads the history; the demo tones
now last 30 s so a 25 s play is plausible
- test: the rule at its boundaries, the plausibility bound, history order,
paging and isolation on both databases, and the contract test for the new
operation
Closes#17
- fix(spec): album.artist and track.album are real nullable objects (OpenAPI
3.0 only honours nullable next to a type); the stream documents 304 on HEAD,
412, If-Unmodified-Since and multipart/byteranges answers
- fix(spec): passwords and idempotency keys are measured in bytes, an overlap
between libraries is a 400, a library PATCH needs a name or a path, limit 0
means the default, login has no format rules of its own, and the wording about
signing out says that issued access tokens live until they expire
- fix(auth): the Bearer scheme is matched ignoring case (RFC 7235)
- fix(listening): a listen with the access token of a deleted account is a 401
instead of a database error
- fix(docs): the docs pages answer HEAD and carry X-Frame-Options, a CSP
frame-ancestors, nosniff and no-referrer, since people paste their token there
- test: error codes are asserted in every error case; every accepted request is
validated against the spec too; HEAD and 3xx answers are checked by hand
because the validator skips them; the stream Content-Type must be one the
spec lists; a scan held mid-way proves the scan_running conflicts; null album
and null album artist, a vanished file, multi-range, 412 and HEAD 304 are
exercised. Verified by breaking the code and the spec on purpose
- fix(storage): tracks of two albums with the same title (Greatest Hits, Live)
no longer interleave in a listing: the album id is part of the order
- fix(storage): an artist's album_count and GET /albums?artist_id= now mean
the same thing: albums the artist owns plus albums where it is credited on a
playable track; a property test checks it for every artist and library
- fix(catalog): a NUL byte or invalid UTF-8 in q is a 400 instead of a broken
SQL statement and a 500
- fix(api): clamp paging values with math.MaxInt32 so the package also builds
on 32-bit targets
- docs: search ignores case, including accented letters, but not accents
("bjork" does not find "Bjork"); the earlier comments said otherwise
- test: same-title albums across a page boundary, NUL and invalid UTF-8
- feat(api): GET /api/v1/artists, /albums and /tracks with q (case and accent
insensitive substring), limit and offset (default 50, at most 200) and a
total; filters library_id, artist_id and album_id; GET /artists/{id},
/albums/{id} and /tracks/{id}; any signed-in user can read
- feat(catalog): only tracks with a file that is not flagged missing are
visible, so everything shown can be played; a track with several files is
listed once; album artists without credited tracks (compilations) are listed
- feat(storage): results are ordered the same way on SQLite and PostgreSQL
(plain byte order), LIKE wildcards in the search text are escaped, and a
page costs a fixed number of queries: related items and counts are loaded in
batches
- feat(storage): tracks get a title_key computed in Go (migration 0006, with
a startup refresh), like artists and albums
- test: ordering, paging, search with accents and wildcards, library filter,
duplicate encodings, missing files, details, and a query-count guard on
both databases
- fix(migration): roots that differ only in case (/Music and /music are two
directories on Linux) used to make migration 0005 fail on the unique name;
the later ones now get a numeric suffix
- feat(library): at startup, log a warning for every library whose directory
cannot be read or that overlaps another, because migrated rows skip
validation and may still hold roots that were removed from the old config
- fix(library): creating or updating a library is now serialised, so two
concurrent requests cannot both pass the overlap check
- fix(library): changing a library's directory or deleting it is refused with
409 scan_running while a scan runs; the scan works from the list it started
with and would write under a stale path
- fix(library): library names clash ignoring case and accents the same way on
SQLite and PostgreSQL, checked in Go
- fix(library): changing only the path no longer revalidates an untouched
name, which can be longer than the limit after a migration
- test: roots differing in case on both databases; concurrent creates with a
slow store, verified to fail without the lock; the busy guard; Problems
- feat(storage): libraries table (name, path); audio_files points at a library
by id instead of repeating the root path; migration 0005 for both drivers
turns every existing root into a library and keeps file ids, tracks and the
missing flag
- feat(library): Libraries service validates names and paths: absolute, an
existing directory, never the filesystem root, never inside or around
another library (checked on real paths, so symlinks cannot hide an overlap)
- feat(api): admin-only GET/POST /libraries, PATCH/DELETE /libraries/{id} and
POST /libraries/{id}/scan; deleting a library drops its index entries and
keeps tracks and listening history
- feat(library): the scanner and the scan manager work on libraries; scanning
with no libraries answers 409 no_libraries
- feat(streaming): the library directory comes from the database instead of
a configured list of roots
- breaking(config): library.roots is removed; an old config fails with a hint
to use POST /api/v1/libraries
- test: CRUD and duplicates on both databases, path change keeps files,
upgrade of a database written before libraries existed
- feat(streaming): open a track's file only after checking it against the
configured library roots: relative paths only, no "..", symlinks resolved on
both sides so none can leave the root, regular files only
- feat(api): GET and HEAD /api/v1/tracks/{id}/stream via http.ServeContent
(206, 416, Content-Length, conditional requests), MIME type from the
extension, nosniff, no-referrer and private caching headers
- feat(api): the stream route also accepts the access token as access_token in
the query string, because an audio element cannot send headers; no other
route does, and the query string is never logged
- feat(storage): PlayableFile picks the oldest file of a track that is not
flagged missing
- fix(api): internal errors set by handlers are now written to the request log
- test: range variants, HEAD, conditional requests, auth variants, traversal,
symlink escape, symlinked root, missing file, directory instead of file
- fix(storage): lock the user row when rotating a refresh token or changing a
password, so on PostgreSQL a token minted during a password change can no
longer survive the revoke-everything that runs at the same time
- fix(auth): a replay of a just-rotated refresh token (two tabs, a retrying
client) now fails without revoking the winner's new token; only a replay
after RefreshReuseGrace is treated as theft and revokes every session
- fix(auth): changing or resetting a password and revoking the user's refresh
tokens now happen in one transaction
- docs(auth): note that the last-admin rule relies on a single instance
- test: password change racing with a refresh (25 rounds, both databases),
grace window, winner's token still valid after concurrent rotation
- feat(auth): short-lived access tokens plus rotating refresh tokens stored as
SHA-256 hashes; replaying a spent token revokes every session of that user
- feat(auth): is_admin flag; the first registered user is the admin and the
last admin can be neither demoted nor deleted
- feat(api): POST /auth/refresh, /auth/logout, /auth/password and GET /auth/me
- feat(api): admin-only GET/POST /users, PATCH /users/{id}, PUT
/users/{id}/password and DELETE /users/{id}; the admin check reads the role
from the database on every call
- feat(api): starting a library scan is now admin-only
- feat(storage): users and refresh token repositories for SQLite and
PostgreSQL (migration 0004; the oldest existing account becomes admin)
- feat(config): auth.access_ttl_minutes and auth.refresh_ttl_hours replace
auth.token_ttl_hours
- test: rotation, reuse detection, concurrent rotation with a single winner,
admin rules, role changes taking effect immediately
- fix(storage): RefreshMatchKeys recomputes name_key and title_key for rows
created before migration 0003, whose SQL lower() key is ASCII-only on SQLite;
idempotent, runs at every start
- fix(library): re-check that the stat result is a regular file, closing the
window where a path is swapped for a FIFO or symlink after the directory read
- docs(library): note that OnFinish callbacks of consecutive scans can overlap
- test: old rows with approximate keys are matched after the refresh