Add alternative names and cover art for soundtracks
Alternative names (#32): - PUT /api/v1/soundtracks/{uuid}/alternative-names replaces a soundtrack's alternative names (trimmed, deduplicated, without the soundtrack's own name). - alternative_names is in the soundtrack and statistics responses. - /find matches them too and shows which name matched. Covers (#12), stored in COVERS_PATH and off when it is not set: - GET, PUT (upload) and DELETE /api/v1/soundtracks/{uuid}/cover, and PUT .../cover/source to pick a SteamGridDB game or AniList anime by ID. Uploaded and picked covers are never replaced automatically. - With STEAMGRIDDB_API_KEY, a background job searches SteamGridDB, then AniList, by name, alternative names and the name without bracketed parts, at startup, after a sync and after names change. Search results are ranked by matching words, so "Civilization IV" gets "Sid Meier's Civilization IV". - cover_modified (Unix seconds) is in the soundtrack and statistics responses, so clients can cache covers. The new columns are added to migration 000006, which is not released yet. Closes #12, closes #32 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f79f51ea4c
commit
bb8de5548d
39 files changed
+2418
-99
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
"music-server/internal/testutil/fakedb"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -24,11 +25,54 @@ func TestLibrarySoundtracks(t *testing.T) {
|
||||
soundtracks, err := NewLibraryService(store).Soundtracks(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, soundtracks, 2)
|
||||
assert.Equal(t, Soundtrack{Uuid: a.Uuid, Name: "A Game"}, soundtracks[0])
|
||||
assert.Equal(t, Soundtrack{Uuid: a.Uuid, Name: "A Game", AlternativeNames: []string{}}, soundtracks[0])
|
||||
assert.Equal(t, b.Uuid, soundtracks[1].Uuid)
|
||||
assert.Equal(t, int32(3), soundtracks[1].TimesPlayed)
|
||||
}
|
||||
|
||||
func TestLibrarySetAlternativeNames(t *testing.T) {
|
||||
store := fakedb.New()
|
||||
st := store.AddSoundtrack(repository.Soundtrack{SoundtrackName: "Final Fantasy VII"})
|
||||
l := NewLibraryService(store)
|
||||
ctx := context.Background()
|
||||
|
||||
soundtrack, err := l.SetAlternativeNames(ctx, st.Uuid,
|
||||
[]string{" FF7 ", "ff7", "", "final fantasy vii", "ファイナルファンタジーVII", " "})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []string{"FF7", "ファイナルファンタジーVII"}, soundtrack.AlternativeNames,
|
||||
"trimmed, without empty names, duplicates or the soundtrack's own name")
|
||||
|
||||
stored, err := l.Soundtrack(ctx, st.Uuid)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []string{"FF7", "ファイナルファンタジーVII"}, stored.AlternativeNames)
|
||||
|
||||
soundtrack, err = l.SetAlternativeNames(ctx, st.Uuid, nil)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []string{}, soundtrack.AlternativeNames, "an empty list removes them")
|
||||
|
||||
_, err = l.SetAlternativeNames(ctx, uuid.New(), []string{"x"})
|
||||
assert.ErrorIs(t, err, ErrNotFound)
|
||||
}
|
||||
|
||||
func TestLibrarySetAlternativeNamesSearchesForACoverAgain(t *testing.T) {
|
||||
store := fakedb.New()
|
||||
checked := pgtype.Timestamptz{Time: time.Now(), Valid: true}
|
||||
without := store.AddSoundtrack(repository.Soundtrack{SoundtrackName: "No cover", CoverChecked: checked})
|
||||
file := "cover.jpg"
|
||||
with := store.AddSoundtrack(repository.Soundtrack{SoundtrackName: "Cover", CoverFile: &file, CoverChecked: checked})
|
||||
l := NewLibraryService(store)
|
||||
|
||||
_, err := l.SetAlternativeNames(context.Background(), without.Uuid, []string{"x"})
|
||||
require.NoError(t, err)
|
||||
_, err = l.SetAlternativeNames(context.Background(), with.Uuid, []string{"y"})
|
||||
require.NoError(t, err)
|
||||
|
||||
st, _ := store.Soundtrack("No cover")
|
||||
assert.False(t, st.CoverChecked.Valid, "searched again with the new names")
|
||||
st, _ = store.Soundtrack("Cover")
|
||||
assert.True(t, st.CoverChecked.Valid, "a soundtrack with a cover keeps it")
|
||||
}
|
||||
|
||||
func TestLibrarySoundtrackWithSongs(t *testing.T) {
|
||||
store := fakedb.New()
|
||||
st := addSoundtrackWithSongs(t, store, t.TempDir(), "Game A", 0, "Song B", "Song A")
|
||||
|
||||
Reference in new issue
Block a user