Files
cdnutterandClaude Opus 5.5 33053d1c5f Add refresh from source for entries and whole lists
- Every provider can look an entry up again by its ID (TMDB, TheTVDB,
  IGDB, Deezer, MusicBrainz, Wikipedia); search and lookup share parsing
- POST /api/items/{id}/refresh re-applies title, subtitle, year,
  description, link, details and artwork. Kept: the "why" note, rank,
  theater production/venue/cast and a theater entry's year, the Deezer
  preview match. Empty source fields don't erase existing values
- New items.image_custom column (migration 4; existing uploads marked)
  records artwork the owner chose; refresh keeps it unless asked
- Refused for custom lists and hand-added entries; entries the source
  dropped are reported, and a refresh whose title shares no words with
  the current one is rejected as a likely bad ID
- Editor: refresh button per row (asks about the owner's own artwork),
  and "Refresh all" with a confirm step, replace-my-art checkbox,
  progress with Stop, and a summary of problems

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 12:41:22 -07:00

95 lines
3.0 KiB
Go

//go:build live
// Live checks against the real music services: go test -tags live ./internal/providers
package providers
import (
"context"
"strings"
"testing"
"time"
)
func TestLiveMusic(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
reg := NewRegistry(func(context.Context) Credentials { return Credentials{} })
albums, _ := reg.For(ctx, "album")
for _, c := range []struct{ query, want string }{
{"death magnetic", "Death Magnetic"},
{"super mario galaxy soundtrack", "Super Mario Galaxy Original Soundtrack"},
{"chrono trigger original soundtrack", "Chrono Trigger Original Soundtrack"},
} {
res, err := albums.Search(ctx, c.query)
if err != nil {
t.Fatalf("%s: %v", c.query, err)
}
found := -1
for i, r := range res {
if r.Title == c.want {
found = i
break
}
}
t.Logf("%q → %q at #%d (%s, type %q)", c.query, c.want, found+1, pick(res, found).Provider, pick(res, found).Extra["type"])
if found < 0 || found > 2 {
t.Errorf("%q: want %q in the top 3", c.query, c.want)
}
}
ref, err := reg.MatchDeezer(ctx, "album", "Death Magnetic", "Metallica")
t.Logf("Death Magnetic → Deezer %q", ref)
if err != nil || !strings.HasPrefix(ref, "album:") {
t.Fatalf("match: %q %v", ref, err)
}
u, err := reg.DeezerPreview(ctx, ref)
if err != nil || !strings.HasPrefix(u, "https://") {
t.Fatalf("preview: %q %v", u, err)
}
t.Logf("preview URL host: %s", strings.SplitN(strings.TrimPrefix(u, "https://"), "/", 2)[0])
song, err := reg.MatchDeezer(ctx, "song", "Dreams", "Fleetwood Mac")
t.Logf("Dreams → Deezer %q", song)
if err != nil || song == "" {
t.Errorf("song match: %q %v", song, err)
}
}
func pick(res []Result, i int) Result {
if i < 0 {
return Result{}
}
return res[i]
}
func TestLiveLookup(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
reg := NewRegistry(func(context.Context) Credentials { return Credentials{} })
for _, c := range []struct{ category, provider, id, want string }{
{"album", "deezer", "album:14590454", "Death Magnetic"},
{"song", "deezer", "track:63480987", "Dreams"},
{"album", "musicbrainz", "release-group:5c8a25bf-4764-3cce-8f37-30af79d3b101", "Death Magnetic"},
{"theater", "wikipedia", "1678965", "Wicked"},
} {
res, err := reg.Lookup(ctx, c.category, c.provider, c.id)
if err != nil {
t.Errorf("%s %s: %v", c.provider, c.id, err)
continue
}
t.Logf("%s %s → %q | %q | %s | img=%v | desc=%d chars | extra=%v", c.provider, c.id, res.Title, res.Subtitle, res.Year, res.ImageURL != "", len(res.Overview), res.Extra)
if c.want != "" && !strings.HasPrefix(res.Title, c.want) {
t.Errorf("want %q, got %q", c.want, res.Title)
}
}
if _, err := reg.Lookup(ctx, "album", "deezer", "album:1"); err == nil {
t.Log("album:1 unexpectedly exists")
} else {
t.Logf("missing album → %v", err)
}
if _, err := reg.Lookup(ctx, "movie", "", ""); err != ErrNoSource {
t.Errorf("manual entry: want ErrNoSource, got %v", err)
}
}