Commit graph

209 commits

Author SHA1 Message Date
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
squidd
0d69ae48de Merge pull request 'feat: playlists with a cover, a collage of the covers of their albums' (#121) from feat/playlist-covers into main 2026-11-13 11:32:57 +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
squidd
75577e1fdb Merge pull request 'feat(naming): an admin section that shows what Claude costs' (#119) from feat/claude-costs into main 2026-11-13 11:15:43 +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
squidd
84b6937bbf Merge pull request 'feat(naming): playlists named by Claude by themselves when it is on' (#117) from feat/auto-names into main 2026-11-13 11:01:52 +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
squidd
0dddfb741e Merge pull request 'feat(smart): the songs I play most, in rotation lately and over the year' (#115) from feat/on-rotation into main 2026-11-13 10:45:42 +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
squidd
322b6e5530 Merge pull request 'feat(naming): names for playlists, with the Claude API as an option' (#113) from feat/naming into main 2026-11-13 10:34:49 +01:00
tgiachi
9e666d2b29 feat(web): a Suggest a name button
- Where a playlist is renamed, and where a smart playlist is edited, a button asks the server for a name in the language of the page. It fills the name, fills the description when it is empty, and says if the name came from Claude or from this server. A failed request says why and changes nothing.
- The Claude card in the providers page has a key, a test and the switch, but no contact and no data to take back.
2026-11-13 10:33:48 +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
squidd
2b7635c936 Merge pull request 'feat(web): a sidebar that collapses' (#111) from feat/web-collapsible-sidebar into main 2026-11-13 10:11:21 +01:00
tgiachi
4810564aac feat(web): a sidebar that collapses
- A button in the sidebar folds it to a narrow bar with the icon of each page, and opens it again. The choice is remembered in the browser, which may refuse to keep it.
- Every link keeps its name for screen readers and gets a tooltip when only its icon shows.
- On a phone, where the sidebar is a row of links, nothing changes.
2026-11-13 10:10:25 +01:00
squidd
ca63fc4701 Merge pull request 'feat(smart): smart playlists made for everybody, without making them' (#109) from feat/suggested-smart into main 2026-11-13 10:07:45 +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
squidd
b598842c6d Merge pull request 'feat(mixes): a picture for each mix, a collage of album covers' (#107) from feat/mix-covers into main 2026-11-13 09:58:56 +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
squidd
0e489bda1f Merge pull request 'feat(web): smart playlists, and the genres to choose from' (#105) from feat/web-smart-playlists into main 2026-11-13 09:46:48 +01:00
tgiachi
a2938f0f96 feat(web): smart playlists
- A Smart playlists page with the ones I made and a way to make a new one.
- A page for a smart playlist: its rules in words, its songs, Play, Shuffle again (for the random order), Save as playlist (keeps what is on screen), Edit and Delete.
- An editor for a new one and for one that exists, with a live preview of the songs the rules give: genres (chips, with the library's genres offered), file format and bitrate, when it was added, listening, taste, length, order and limit. What the editor has no field for (artists, albums, skipped lately, another format) is kept when a playlist is changed.
- Texts in English and Italian, and tests for the list, the page, the editor and the preview.
2026-11-13 09:46:03 +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
squidd
7981edacb6 Merge pull request 'feat(smart): smart playlists, playlists made of rules' (#103) from feat/smart-playlists into main 2026-11-13 09:37:57 +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
25f41dd5fc test(mixes): remove a throwaway check against a local database
It was committed by mistake with the mixes: it reads a database from a path on one machine and prints, so it checks nothing.
2026-11-13 09:23:11 +01:00
squidd
4b3618fa07 Merge pull request 'fix(musicbrainz): follow the redirect of an id that was merged' (#101) from fix/musicbrainz-merged-ids into main 2026-11-12 19:35:49 +01:00
tgiachi
6b40ea06fa fix(musicbrainz): follow the redirect of an id that was merged
When MusicBrainz merges two entries, the old id answers with a redirect to the new one. The client refused every redirect, so the description of that artist failed at every run of the job.

The client for MusicBrainz now follows a redirect only to https://musicbrainz.org/ws/2/artist/<id> or /release-group/<id>, with no credentials or port. Any other redirect is still refused. The new id is used for that request only.
2026-11-12 19:34:59 +01:00
squidd
5b9f98d8ed Merge pull request 'feat(web): mixes page, shuffle again and save as playlist' (#99) from feat/web-mixes into main 2026-11-12 18:37:55 +01:00
tgiachi
19fa5ff9ce feat(web): mixes page, shuffle again and save as playlist
- A Mixes link in the sidebar and a page with one card for each mix: the ones made from listening first, then one for each genre.
- A page for a mix: its songs, Play, Shuffle again (the next variant, one at a time) and Save as playlist (keeps the variant on screen, named with the title, with a link to the new playlist).
- Mix names are translated from the kind and the genre, since the server title is always English.
- Texts in English and Italian; tests for the list, the page, shuffle, save and the errors.
2026-11-12 18:36:41 +01:00
squidd
16fda24ff5 Merge pull request 'feat(mixes): playlists made for a listener, by listening and by genre' (#97) from feat/mixes into main 2026-11-12 17:27:24 +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
squidd
0899cfad4c Merge pull request 'feat(web): playlists' (#94) from feat/web-playlists into main 2026-11-12 17:10:07 +01:00
tgiachi
c0e8874e71 feat(web): playlists
A Playlists page lists the user's playlists and makes a new one. A playlist has its
own page: play it (songs that are not available are skipped), rename it, delete it
after a confirmation, move a song up or down and take one out. Every song of a list
gets an Add to playlist button that opens a window to choose a playlist or make a
new one, and says what it did.

TrackRow keeps the song as one button and takes extra buttons at its end, so the
add button is not inside the button that plays. A long playlist is read whole,
page after page. English and Italian texts, error texts for the new codes.

Closes #92
2026-11-12 17:04:44 +01:00
squidd
eebeb2b10c Merge pull request 'feat: find duplicate songs and delete the extra copies (server)' (#90) from feat/duplicates-api into main 2026-11-12 17:02:30 +01:00
tgiachi
ce109a14a3 fix(duplicates): move the playlist items of a removed copy to the one that stays
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.
2026-11-12 17:01:36 +01:00
tgiachi
3d986f051d Merge remote-tracking branch 'origin/main' into feat/duplicates-api 2026-11-12 17:00:00 +01:00
squidd
0404e0f94a Merge pull request 'feat(playlists): a user keeps playlists of tracks' (#91) from feat/playlists into main 2026-11-12 16:57:16 +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
05f4e33470 fix(duplicates): finish updating the index even if the client leaves after the file is deleted
Found reviewing the branch: a request cancelled between deleting the file and updating the index left a track whose file does not exist. The index step no longer depends on the request's context. Test first: it cancels the request at exactly that moment.
2026-11-12 16:52:38 +01:00
tgiachi
7180a747e9 docs: duplicates, library.allow_delete and the one exception to read-only music folders
README: the Duplicates feature, the new setting and its environment variable, the endpoints, and the two places that promised the music folders are never written. The example config and the compose file say how to turn it on and that the folder must then be writable.
2026-11-12 16:50:11 +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
d3e3bde2e4 feat(duplicates): find the copies, fingerprint their files and remove the extra ones
Groups come from the index. The check job reads the files of the groups and keeps their SHA-256, skipping a file that changed since the scan. Clean refuses unless deleting is on and no scan runs, works out again that the tracks are copies of one song, checks every file is still what the scan saw (so the last copy is never removed, and a link or a path that leaves the library is refused) before removing any, removes each file through an os.Root, then takes its track out of the index and moves its listens. Tested with real files, including the refusals; three of the safety rules were broken on purpose to see the tests fail.
2026-11-12 16:40:43 +01:00
tgiachi
65edfc4918 feat(storage): candidates for duplicates, file fingerprints and removing a copy from the index
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.
2026-11-12 16:37:15 +01:00
squidd
bbb1e9847b Merge pull request 'feat(images): ask again without the disc or edition note of a title' (#88) from feat/album-title-suffix into main 2026-11-12 16:36:37 +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
7e1e63bdd2 feat(duplicates): group the copies of a song and propose the one to keep
The same song is the same set of main artists, the same title and durations within 3 seconds, every pair within it; a file with no duration or no artist never matches. A group says whether its files were all read and are byte for byte the same. The copy to keep is the lossless one, then the higher bitrate, then the bigger file, then the oldest, whatever the order of the input.
2026-11-12 16:34:12 +01:00
tgiachi
309160951e feat(config): library.allow_delete, off by default, for deleting duplicate files
The one setting that lets Sonda delete files from the music folders. Off until the operator turns it on, in the file or with SONDA_ALLOW_DELETE; a value that is not true or false is an error, not ignored.
2026-11-12 16:33:11 +01:00
squidd
a64122efdd Merge pull request 'feat(images): find the cover of an album that has no MusicBrainz id' (#84) from feat/album-mbid-lookup into main 2026-11-12 16:23:36 +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
squidd
66a4ea5b5a Merge pull request 'feat: serve the web app from sondad (F4)' (#82) from feat/serve-web into main 2026-11-12 16:06:27 +01:00