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>
This commit is contained in:
cdnutterandClaude Opus 5.5 committed 2026-09-25 12:41:22 -07:00
1 parent 4ea7cbc984
commit 33053d1c5f
18 files changed
+852 -148

No files matched your search

+81 -13
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"
"sync"
"time"
)
@@ -79,19 +80,8 @@ func (t *tvdb) Search(ctx context.Context, query string) ([]Result, error) {
} `json:"data"`
}
u := "https://api4.thetvdb.com/v4/search?" + url.Values{"query": {query}, "type": {"series"}, "limit": {"20"}}.Encode()
for attempt := 0; ; attempt++ {
tok, err := t.token(ctx, attempt > 0)
if err != nil {
return nil, err
}
err = t.r.getJSON(ctx, u, map[string]string{"Authorization": "Bearer " + tok}, &resp)
if isStatus(err, 401) && attempt == 0 {
continue
}
if err != nil {
return nil, err
}
break
if err := t.get(ctx, u, &resp); err != nil {
return nil, err
}
out := make([]Result, 0, len(resp.Data))
for _, s := range resp.Data {
@@ -128,3 +118,81 @@ func (t *tvdb) Search(ctx context.Context, query string) ([]Result, error) {
}
return out, nil
}
// get calls the API with a token, logging in again once if it expired.
func (t *tvdb) get(ctx context.Context, u string, out any) error {
for attempt := 0; ; attempt++ {
tok, err := t.token(ctx, attempt > 0)
if err != nil {
return err
}
err = t.r.getJSON(ctx, u, map[string]string{"Authorization": "Bearer " + tok}, out)
if isStatus(err, 401) && attempt == 0 {
continue
}
return err
}
}
// Lookup refreshes one series by its TheTVDB ID, preferring English titles
// and overviews.
func (t *tvdb) Lookup(ctx context.Context, providerID string) (Result, error) {
if _, err := strconv.ParseInt(providerID, 10, 64); err != nil {
return Result{}, ErrGone
}
var s struct {
Data struct {
Name string `json:"name"`
Slug string `json:"slug"`
Image string `json:"image"`
Year string `json:"year"`
FirstAired string `json:"firstAired"`
Overview string `json:"overview"`
OriginalNetwork struct {
Name string `json:"name"`
} `json:"originalNetwork"`
LatestNetwork struct {
Name string `json:"name"`
} `json:"latestNetwork"`
} `json:"data"`
}
err := t.get(ctx, "https://api4.thetvdb.com/v4/series/"+providerID+"/extended?short=true", &s)
if isStatus(err, 404) {
return Result{}, ErrGone
}
if err != nil {
return Result{}, err
}
d := s.Data
res := Result{
Provider: "tvdb",
ProviderID: providerID,
Title: d.Name,
Subtitle: d.OriginalNetwork.Name,
Year: d.Year,
ImageURL: d.Image,
ExternalURL: "https://thetvdb.com/series/" + d.Slug,
Overview: truncate(d.Overview, maxDescription),
}
if res.Subtitle == "" {
res.Subtitle = d.LatestNetwork.Name
}
if res.Year == "" {
res.Year = yearOf(d.FirstAired)
}
var eng struct {
Data struct {
Name string `json:"name"`
Overview string `json:"overview"`
} `json:"data"`
}
if err := t.get(ctx, "https://api4.thetvdb.com/v4/series/"+providerID+"/translations/eng", &eng); err == nil {
if eng.Data.Name != "" {
res.Title = eng.Data.Name
}
if eng.Data.Overview != "" {
res.Overview = truncate(eng.Data.Overview, maxDescription)
}
}
return res, nil
}