feat(anime): add episode api support

This commit is contained in:
2026-04-18 05:54:15 +02:00
parent df3a6e3610
commit 9eb3e21ffa
4 changed files with 102 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package jikan
import (
"context"
"fmt"
"time"
)
func (c *Client) GetEpisodes(ctx context.Context, animeID int, page int) (EpisodesResponse, error) {
if page < 1 {
page = 1
}
cacheKey := fmt.Sprintf("anime:%d:episodes:%d", animeID, page)
var cached EpisodesResponse
if c.getCache(ctx, cacheKey, &cached) {
return cached, nil
}
var stale EpisodesResponse
hasStale := c.getStaleCache(ctx, cacheKey, &stale)
var result EpisodesResponse
reqURL := fmt.Sprintf("%s/anime/%d/episodes?page=%d", c.baseURL, animeID, page)
if err := c.fetchWithRetry(ctx, reqURL, &result); err != nil {
if hasStale {
return stale, nil
}
return EpisodesResponse{}, err
}
c.setCache(ctx, cacheKey, result, 12*time.Hour)
return result, nil
}

View File

@@ -156,6 +156,18 @@ type TopAnimeResponse struct {
Pagination Pagination `json:"pagination"`
}
type Episode struct {
MalID int `json:"mal_id"`
Title string `json:"title"`
Filler bool `json:"filler"`
Recap bool `json:"recap"`
}
type EpisodesResponse struct {
Data []Episode `json:"data"`
Pagination Pagination `json:"pagination"`
}
type JikanRelationEntry struct {
MalID int `json:"mal_id"`
Type string `json:"type"`