Commit graph

184 commits

Author SHA1 Message Date
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
tgiachi
95c1fa3e27 build: make build and an image with the web app inside; README describes it
make build builds the app and then sondad with -tags webui. The Dockerfile builds the app in a Node stage and embeds it in the Go build, so the image serves it with no Node on the host. README: how to build, what the image holds, the policy of the page, and how to work on the interface with the dev server.
2026-11-12 15:56:36 +01:00
tgiachi
249b2cb7bc feat: embed the built web app in sondad behind the webui build tag
internal/webui carries web/'s build (written to internal/webui/dist by Vite, git-ignored) when sondad is built with -tags webui. Without the tag the app is absent and a plain go build and go test still work with no Node. main wires it into the router.
2026-11-12 15:56:34 +01:00
tgiachi
7acac73dd0 feat(api): serve the web app on / and for its own links, with a strict policy
A GET or HEAD outside /api is a file of the app, or its page for a link inside it (/admin/users). A file that is missing (under assets/ or with an extension) answers 404, never the page, so a missing script is not run as HTML; hidden files and folders are never served; everything else, and any unknown /api address, keeps the JSON 404. The page gets a Content-Security-Policy that allows only its own server (no address, no wildcard, no inline script), nosniff, DENY and no referrer. Hashed assets are cached for good and the page is asked again. With no app in the binary, / says how to build it. The app is an optional dependency, so existing wiring is unchanged.
2026-11-12 15:56:33 +01:00
tgiachi
f447a11269 fix(web): wait for the address in the search page test instead of assuming it
The test read the address right after the Artists section appeared, but the address is updated by an effect a moment later. On a busy machine it failed in every full run and passed alone. Closes #80.
2026-11-12 15:41:47 +01:00
squidd
e018bfde38 Merge pull request 'feat(web): bulk jobs in the admin area (F3d)' (#79) from feat/admin-jobs into main 2026-11-12 15:38:24 +01:00
tgiachi
82f6e91d7a feat(web): a Jobs section in the admin area
Three cards at /admin/jobs, for admins only; anyone else gets the notice and the server is not asked. The page reads which providers are on to block a job whose provider is off. README says the admin area now covers everything the API offers an admin.
2026-11-12 15:34:33 +01:00
tgiachi
3ca3226e91 feat(web): a card for each bulk job, with what it sends, progress, stop and the last result
Starting asks first and says the job goes through the whole library and what it sends; reading everything again is a separate choice. A job whose providers are off cannot be started and the card says which. The status follows the job while it runs.
2026-11-12 15:33:24 +01:00
tgiachi
c8bad5538b feat(web): hooks for the bulk jobs (covers, artist pictures, descriptions)
One set of hooks for the three jobs: read the status (again and again while it runs, by itself stopping), start (optionally reading everything again) and stop.
2026-11-12 15:31:53 +01:00
squidd
8339b043b7 Merge pull request 'feat(web): volume control in the player' (#78) from feat/volume into main 2026-11-12 15:29:36 +01:00
tgiachi
f1b99aed0a fix(web): line the volume control up with the other controls in the full-screen player 2026-11-12 15:24:41 +01:00
tgiachi
99d25acd9a feat(web): the volume control in the player bar and the full-screen player
Both places move the same volume. README mentions it.
2026-11-12 15:23:50 +01:00
tgiachi
606845ae72 feat(web): a volume control with a mute button and a slider
The slider shows zero while muted and moving it unmutes; on a phone the slider is hidden, since the device has its own volume, and the button stays.
2026-11-12 15:22:57 +01:00
tgiachi
edab170d3f feat(web): the audio follows the volume and mute of the player
The audio starts at the remembered level and follows every change, also while a track plays; once the engine is gone it is left alone.
2026-11-12 15:22:23 +01:00
tgiachi
394208de75 feat(web): volume and mute in the player state, remembered in the browser
The level is kept while muted so unmuting brings it back, moving it unmutes, pressing mute on silence raises it instead of doing nothing, and a browser that refuses storage just forgets it.
2026-11-12 15:21:41 +01:00
squidd
dd128a315f Merge pull request 'feat(web): external providers in the admin area (F3c)' (#76) from feat/admin-providers into main 2026-11-12 15:16:56 +01:00
tgiachi
fed1213030 feat(web): a Providers section in the admin area
One card for each provider at /admin/providers, for admins only; anyone else gets the notice and the server is not asked. README says what the admin area covers.
2026-11-12 15:12:23 +01:00
tgiachi
369bd2ec3f feat(web): choose what is sent to Lidarr when an artist is added
Nothing is asked of Lidarr until the admin loads its choices on purpose, which needs its address and a key. A folder Lidarr cannot use is shown and cannot be picked; saving sends all the options at once.
2026-11-12 15:11:20 +01:00
tgiachi
0ddcaff8e1 feat(web): the provider card with the switch, the write-only key, contact, address, test and removing data
Turning a provider on asks first and repeats what it will be sent; one that needs a key or an address cannot be turned on without it and the card says why. The key is never shown or filled in, and is gone from the page once saved; removing it says it also turns the provider off. The confirm dialog is now shared with the users section.
2026-11-12 15:09:54 +01:00
tgiachi
c3edc564f4 feat(web): hooks for the external providers
List them, change one (only the fields given are sent), test a key, remove what a provider gave, and read what Lidarr offers only when asked.
2026-11-12 15:05:42 +01:00
squidd
fc499214b4 Merge pull request 'feat(web): users in the admin area (F3b)' (#73) from feat/admin-users into main 2026-11-12 15:02:50 +01:00
tgiachi
a39c0f7719 fix(web): clear the short-password complaint when the password is changed
Found in a real browser: after the complaint, typing a valid password left it on screen until the next submit. Same in the reset dialog and the add form.
2026-11-12 14:59:37 +01:00
tgiachi
52569a0f8d feat(web): a Users section in the admin area
Opens at /admin/users next to Libraries, for admins only; anyone else gets the notice and the server is not asked. README says what the admin area covers.
2026-11-12 14:58:01 +01:00
tgiachi
9b1594e9f2 feat(web): the user list with its actions and the form to add a user
Give the admin role at once, take it away or delete an account after a question, reset a password in a dialog that forgets it (and ends that person's sessions), and add an account by email. Your own row has no buttons, and the last admin cannot be changed: the page says so.
2026-11-12 14:57:22 +01:00
tgiachi
b190835185 feat(web): hooks for listing, creating, changing and deleting users
Listing, creating, giving or taking the admin role, resetting a password and deleting, each refreshing the list when the list changes.
2026-11-12 14:55:26 +01:00
tgiachi
04526f8576 fix(web): build test users with an email address, so the type check passes
The tests of Discover, the Lidarr button and the admin libraries built a signed-in user with a username, which no longer exists since accounts are identified by email. They passed, but the type check failed on 18 fixtures and so did npm run build. Closes #71.
2026-11-12 14:52:20 +01:00