Real-image posters of library titles: use the 500 px copy
Library titles fetched Radarr's/Sonarr's 250×375 poster copy, which real images show at up to 640 pixels, so movie posters looked soft next to series posters that came from the provider's full-size original (Sonarr behind a login). With real images the 500×750 copy is used; block-character posters keep the small one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019reK4DUGYqDUjniWYJvwUW
This commit is contained in:
+38
-14
@@ -8,18 +8,42 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSmallVariant(t *testing.T) {
|
||||
for in, want := range map[string]string{
|
||||
"/MediaCover/1/poster.jpg?lastWrite=5": "/MediaCover/1/poster-250.jpg?lastWrite=5",
|
||||
"/MediaCover/1/poster.jpg": "/MediaCover/1/poster-250.jpg",
|
||||
"/MediaCover/1/fanart.jpg": "/MediaCover/1/fanart.jpg",
|
||||
func TestScaledVariant(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
in string
|
||||
width int
|
||||
want string
|
||||
}{
|
||||
{"/MediaCover/1/poster.jpg?lastWrite=5", 250, "/MediaCover/1/poster-250.jpg?lastWrite=5"},
|
||||
{"/MediaCover/1/poster.jpg", 500, "/MediaCover/1/poster-500.jpg"},
|
||||
{"/MediaCover/1/fanart.jpg", 250, "/MediaCover/1/fanart.jpg"},
|
||||
} {
|
||||
if got := smallVariant(in); got != want {
|
||||
t.Errorf("smallVariant(%q) = %q, want %q", in, got, want)
|
||||
if got := scaledVariant(tc.in, tc.width); got != tc.want {
|
||||
t.Errorf("scaledVariant(%q, %d) = %q, want %q", tc.in, tc.width, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLargePosterUsesThe500Variant(t *testing.T) {
|
||||
var paths []string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
paths = append(paths, r.URL.Path)
|
||||
w.Write([]byte("IMG"))
|
||||
}))
|
||||
defer srv.Close()
|
||||
c := NewClient(srv.URL, "secret")
|
||||
_, fetch, _ := c.Poster([]Image{{CoverType: "poster", URL: "/MediaCover/1/poster.jpg"}}, true)
|
||||
if _, err := fetch(context.Background(), true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := fetch(context.Background(), false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Join(paths, " ") != "/MediaCover/1/poster-500.jpg /MediaCover/1/poster-250.jpg" {
|
||||
t.Errorf("requests = %v", paths)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPosterLocalUsesAPIKey(t *testing.T) {
|
||||
var paths []string
|
||||
var keys []string
|
||||
@@ -40,7 +64,7 @@ func TestPosterLocalUsesAPIKey(t *testing.T) {
|
||||
if !ok || key == "" {
|
||||
t.Fatal("no poster")
|
||||
}
|
||||
data, err := fetch(context.Background())
|
||||
data, err := fetch(context.Background(), false)
|
||||
if err != nil || string(data) != "IMG" {
|
||||
t.Fatalf("data=%q err=%v", data, err)
|
||||
}
|
||||
@@ -67,7 +91,7 @@ func TestPosterRemoteSendsNoAPIKey(t *testing.T) {
|
||||
if !ok || key != srv.URL+"/p.jpg" {
|
||||
t.Fatalf("key=%q ok=%v", key, ok)
|
||||
}
|
||||
if _, err := fetch(context.Background()); err != nil {
|
||||
if _, err := fetch(context.Background(), false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "" {
|
||||
@@ -111,7 +135,7 @@ func TestPosterFallsBackToTheProviderWhenTheInstanceHasNoCopy(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatal("no poster")
|
||||
}
|
||||
data, err := fetch(context.Background())
|
||||
data, err := fetch(context.Background(), false)
|
||||
if err != nil || string(data) != "REMOTE" {
|
||||
t.Fatalf("data=%q err=%v", data, err)
|
||||
}
|
||||
@@ -121,7 +145,7 @@ func TestPosterFallsBackToTheProviderWhenTheInstanceHasNoCopy(t *testing.T) {
|
||||
|
||||
// Without a remote address the local failure is reported.
|
||||
_, fetch, _ = c.Poster([]Image{{CoverType: "poster", URL: "/MediaCover/9/poster.jpg"}}, true)
|
||||
if _, err := fetch(context.Background()); err == nil {
|
||||
if _, err := fetch(context.Background(), false); err == nil {
|
||||
t.Error("expected the local error")
|
||||
}
|
||||
}
|
||||
@@ -148,7 +172,7 @@ func TestPosterTriesTheKeyInTheQueryWhenGivenALoginPage(t *testing.T) {
|
||||
|
||||
c := NewClient(srv.URL, "secret")
|
||||
_, fetch, _ := c.Poster([]Image{{CoverType: "poster", URL: "/MediaCover/89/poster.jpg"}}, true)
|
||||
data, err := fetch(context.Background())
|
||||
data, err := fetch(context.Background(), false)
|
||||
if err != nil || string(data) != "IMAGE" {
|
||||
t.Fatalf("data=%q err=%v, hits=%v", data, err, hits)
|
||||
}
|
||||
@@ -173,7 +197,7 @@ func TestPosterUsesTheProviderWhenTheInstanceOnlyShowsALogin(t *testing.T) {
|
||||
|
||||
c := NewClient(instance.URL, "secret")
|
||||
_, fetch, _ := c.Poster([]Image{{CoverType: "poster", URL: "/MediaCover/89/poster.jpg", RemoteURL: remote.URL + "/p.jpg"}}, true)
|
||||
data, err := fetch(context.Background())
|
||||
data, err := fetch(context.Background(), false)
|
||||
if err != nil || string(data) != "WEBP" {
|
||||
t.Fatalf("data=%q err=%v", data, err)
|
||||
}
|
||||
@@ -186,7 +210,7 @@ func TestPosterUsesTheProviderWhenTheInstanceOnlyShowsALogin(t *testing.T) {
|
||||
|
||||
// Without a provider address the failure says what came back.
|
||||
_, fetch, _ = c.Poster([]Image{{CoverType: "poster", URL: "/MediaCover/89/poster.jpg"}}, true)
|
||||
_, err = fetch(context.Background())
|
||||
_, err = fetch(context.Background(), false)
|
||||
if err == nil || !strings.Contains(err.Error(), "text/html") || !strings.Contains(err.Error(), "login") {
|
||||
t.Errorf("error = %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user