Details pane: director and cast from Trakt

With a Trakt client ID, the details of a movie or series show the
director(s) or creators and up to 8 cast members with their roles below
the plot, in every view. The title is found on Trakt by its TMDb/TVDB
(else IMDb) id, then its people are read. Casts are cached and, like
posters, only loaded once the selection rests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 23:31:33 +02:00
co-authored by Claude Opus 5.5
parent 8775c27aab
commit 12e825cff0
13 changed files with 468 additions and 17 deletions
+52
View File
@@ -85,3 +85,55 @@ func TestCompact(t *testing.T) {
}
}
}
func TestPeople(t *testing.T) {
var paths []string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
paths = append(paths, r.URL.RequestURI())
switch r.URL.Path {
case "/search/tmdb/272":
w.Write([]byte(`[{"type":"movie","score":1000,"movie":{"title":"Batman Begins","year":2005,"ids":{"trakt":1,"slug":"batman-begins-2005","tmdb":272}}}]`))
case "/movies/1/people":
w.Write([]byte(`{"cast":[{"character":"Bruce Wayne","characters":["Bruce Wayne","Batman"],"person":{"name":"Christian Bale","ids":{"trakt":1}}},
{"character":"Alfred","characters":["Alfred"],"person":{"name":"Michael Caine","ids":{"trakt":2}}}],
"crew":{"directing":[{"job":"Director","jobs":["Director"],"person":{"name":"Christopher Nolan"}},{"job":"Assistant Director","jobs":["Assistant Director"],"person":{"name":"Someone"}}],
"writing":[{"job":"Screenplay","jobs":["Screenplay"],"person":{"name":"David S. Goyer"}}]}}`))
case "/search/tvdb/81189":
w.Write([]byte(`[{"type":"show","score":1000,"show":{"title":"Breaking Bad","year":2008,"ids":{"trakt":1388,"tvdb":81189}}}]`))
case "/shows/1388/people":
w.Write([]byte(`{"cast":[{"character":"Walter White","characters":["Walter White"],"episode_count":62,"person":{"name":"Bryan Cranston"}}],
"crew":{"created by":[{"job":"Creator","jobs":["Creator"],"person":{"name":"Vince Gilligan"}}]}}`))
case "/search/tmdb/5":
w.Write([]byte(`[]`))
default:
http.NotFound(w, r)
}
}))
defer srv.Close()
c := NewClient("id", "ua")
c.SetBaseURL(srv.URL)
movie, err := c.People(context.Background(), Ref{Kind: Movies, TMDB: 272, IMDB: "tt0372784"})
if err != nil {
t.Fatal(err)
}
if len(movie.Cast) != 2 || movie.Cast[0].Name != "Christian Bale" || movie.Cast[0].Role != "Bruce Wayne / Batman" {
t.Errorf("cast %+v", movie.Cast)
}
if len(movie.Leaders) != 1 || movie.Leaders[0].Name != "Christopher Nolan" {
t.Errorf("directors %+v", movie.Leaders)
}
if paths[0] != "/search/tmdb/272?type=movie" {
t.Errorf("lookup %q", paths[0])
}
show, err := c.People(context.Background(), Ref{Kind: Shows, TVDB: 81189})
if err != nil || show.Cast[0].Name != "Bryan Cranston" || len(show.Leaders) != 1 || show.Leaders[0].Name != "Vince Gilligan" {
t.Errorf("show %+v %v", show, err)
}
if _, err := c.People(context.Background(), Ref{Kind: Movies, TMDB: 5}); !errors.Is(err, ErrNotFound) {
t.Errorf("unknown title: %v", err)
}
if (Ref{Kind: Shows, TVDB: 81189}).Key() != "show:tvdb:81189" || (Ref{Kind: Movies}).Key() != "" {
t.Error("keys")
}
}