From 5e12a496e74d43c7dead490913f8093bf12b2e1e Mon Sep 17 00:00:00 2001 From: mkelvers Date: Tue, 30 Jun 2026 21:24:14 +0200 Subject: [PATCH] feat: add description field to allanime provider show --- integrations/playback/allanime/sequels.go | 30 +++++++++++++++++-- .../playback/allanime/sequels_test.go | 5 +++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/integrations/playback/allanime/sequels.go b/integrations/playback/allanime/sequels.go index 304e649d..c7a19c62 100644 --- a/integrations/playback/allanime/sequels.go +++ b/integrations/playback/allanime/sequels.go @@ -1,17 +1,22 @@ package allanime import ( + "bytes" "context" "errors" "fmt" + stdhtml "html" "strconv" "strings" + + "golang.org/x/net/html" ) type ProviderShow struct { ID string Name string EnglishName string + Description string MalID int Status string Thumbnail string @@ -43,7 +48,7 @@ func (c *AllAnimeProvider) DirectSequels(ctx context.Context, show ProviderShow) } func (c *AllAnimeProvider) GetProviderShow(ctx context.Context, showID string) (ProviderShow, error) { - query := `query($showId: String!) { show(_id: $showId) { _id name englishName malId status thumbnail type season episodeCount availableEpisodesDetail } }` + query := `query($showId: String!) { show(_id: $showId) { _id name englishName description malId status thumbnail type season episodeCount availableEpisodesDetail } }` result, err := c.graphqlRequest(ctx, query, map[string]any{"showId": showID}) if err != nil { return ProviderShow{}, err @@ -58,7 +63,7 @@ func (c *AllAnimeProvider) GetProviderShow(ctx context.Context, showID string) ( func (c *AllAnimeProvider) SeasonalShows(ctx context.Context, season string, year int) ([]ProviderShow, error) { const pageSize = 40 - query := `query($search: SearchInput, $page: Int) { shows(search: $search, limit: 40, page: $page, countryOrigin: ALL) { edges { _id name englishName malId status thumbnail type season episodeCount availableEpisodesDetail } } }` + query := `query($search: SearchInput, $page: Int) { shows(search: $search, limit: 40, page: $page, countryOrigin: ALL) { edges { _id name englishName description malId status thumbnail type season episodeCount availableEpisodesDetail } } }` if season == "" { return nil, errors.New("allanime: season is required") } @@ -103,6 +108,7 @@ func providerShowFrom(raw map[string]any) ProviderShow { ID: stringValue(raw["_id"]), Name: stringValue(raw["name"]), EnglishName: stringValue(raw["englishName"]), + Description: plainText(stringValue(raw["description"])), MalID: intValue(raw["malId"]), Status: stringValue(raw["status"]), Thumbnail: stringValue(raw["thumbnail"]), @@ -114,6 +120,26 @@ func providerShowFrom(raw map[string]any) ProviderShow { } } +func plainText(value string) string { + tokenizer := html.NewTokenizer(bytes.NewBufferString(value)) + var out strings.Builder + for { + switch tokenizer.Next() { + case html.ErrorToken: + return out.String() + case html.TextToken: + text := strings.Join(strings.Fields(stdhtml.UnescapeString(string(tokenizer.Text()))), " ") + if text == "" { + continue + } + if out.Len() > 0 { + out.WriteByte(' ') + } + out.WriteString(text) + } + } +} + func stringValue(value any) string { valueString, _ := value.(string) return valueString diff --git a/integrations/playback/allanime/sequels_test.go b/integrations/playback/allanime/sequels_test.go index 56468580..79ffd978 100644 --- a/integrations/playback/allanime/sequels_test.go +++ b/integrations/playback/allanime/sequels_test.go @@ -35,7 +35,7 @@ func TestDirectSequelsReturnsOnlyPlayableSequels(t *testing.T) { func TestGetProviderShowKeepsOnlyPositiveIntegerEpisodes(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - _, _ = w.Write([]byte(`{"data":{"show":{"_id":"season-2","name":"Example Season 2","englishName":"Example Season 2","malId":"42","status":"Finished","episodeCount":"2","availableEpisodesDetail":{"sub":["2","1","0","1.5"],"dub":["1"],"raw":[]}}}}`)) + _, _ = w.Write([]byte(`{"data":{"show":{"_id":"season-2","name":"Example Season 2","englishName":"Example Season 2","description":"A useful
synopsis & summary.","malId":"42","status":"Finished","episodeCount":"2","availableEpisodesDetail":{"sub":["2","1","0","1.5"],"dub":["1"],"raw":[]}}}}`)) })) defer server.Close() @@ -50,6 +50,9 @@ func TestGetProviderShowKeepsOnlyPositiveIntegerEpisodes(t *testing.T) { if got.MalID != 42 || len(got.SubEpisodes) != 2 || len(got.DubEpisodes) != 1 { t.Fatalf("GetProviderShow = %+v", got) } + if got.Description != "A useful synopsis & summary." { + t.Fatalf("Description = %q", got.Description) + } } func TestSeasonalShowsReturnsPlayableTVAnime(t *testing.T) {