revert: remove torrent streaming feature
This commit is contained in:
@@ -16,7 +16,6 @@ type Client struct {
|
||||
topCache *expirable.LRU[int, TopAnimeResult]
|
||||
animeCache *expirable.LRU[int, Anime]
|
||||
relationsCache *expirable.LRU[int, JikanRelationsResponse]
|
||||
episodesCache *expirable.LRU[string, EpisodesResult]
|
||||
}
|
||||
|
||||
func NewClient() *Client {
|
||||
@@ -24,7 +23,6 @@ func NewClient() *Client {
|
||||
topCache := expirable.NewLRU[int, TopAnimeResult](100, nil, time.Hour*1)
|
||||
animeCache := expirable.NewLRU[int, Anime](1000, nil, time.Hour*24)
|
||||
relationsCache := expirable.NewLRU[int, JikanRelationsResponse](1000, nil, time.Hour*24)
|
||||
episodesCache := expirable.NewLRU[string, EpisodesResult](500, nil, time.Hour*6)
|
||||
|
||||
return &Client{
|
||||
httpClient: &http.Client{Timeout: 10 * time.Second},
|
||||
@@ -33,7 +31,6 @@ func NewClient() *Client {
|
||||
topCache: topCache,
|
||||
animeCache: animeCache,
|
||||
relationsCache: relationsCache,
|
||||
episodesCache: episodesCache,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,44 +63,3 @@ func (c *Client) fetchWithRetry(urlStr string, out interface{}) error {
|
||||
}
|
||||
return fmt.Errorf("max retries exceeded for %s", urlStr)
|
||||
}
|
||||
|
||||
// GetEpisodes fetches episodes for an anime (paginated, 100 per page)
|
||||
func (c *Client) GetEpisodes(animeID int, page int) (EpisodesResult, error) {
|
||||
cacheKey := fmt.Sprintf("%d-%d", animeID, page)
|
||||
if cached, ok := c.episodesCache.Get(cacheKey); ok {
|
||||
return cached, nil
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/anime/%d/episodes?page=%d", c.baseURL, animeID, page)
|
||||
var resp EpisodesResponse
|
||||
if err := c.fetchWithRetry(url, &resp); err != nil {
|
||||
return EpisodesResult{}, err
|
||||
}
|
||||
|
||||
result := EpisodesResult{
|
||||
Episodes: resp.Data,
|
||||
HasNextPage: resp.Pagination.HasNextPage,
|
||||
}
|
||||
c.episodesCache.Add(cacheKey, result)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetAllEpisodes fetches all episodes for an anime (handles pagination)
|
||||
func (c *Client) GetAllEpisodes(animeID int) ([]Episode, error) {
|
||||
var allEpisodes []Episode
|
||||
page := 1
|
||||
|
||||
for {
|
||||
result, err := c.GetEpisodes(animeID, page)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
allEpisodes = append(allEpisodes, result.Episodes...)
|
||||
if !result.HasNextPage {
|
||||
break
|
||||
}
|
||||
page++
|
||||
}
|
||||
|
||||
return allEpisodes, nil
|
||||
}
|
||||
|
||||
@@ -169,24 +169,3 @@ func (a Anime) DisplayTitle() string {
|
||||
}
|
||||
return a.Title
|
||||
}
|
||||
|
||||
// Episode represents a single anime episode from Jikan API
|
||||
type Episode struct {
|
||||
MalID int `json:"mal_id"`
|
||||
Title string `json:"title"`
|
||||
TitleJP string `json:"title_japanese"`
|
||||
TitleRom string `json:"title_romanji"`
|
||||
Aired string `json:"aired"`
|
||||
Filler bool `json:"filler"`
|
||||
Recap bool `json:"recap"`
|
||||
}
|
||||
|
||||
type EpisodesResponse struct {
|
||||
Data []Episode `json:"data"`
|
||||
Pagination Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
type EpisodesResult struct {
|
||||
Episodes []Episode
|
||||
HasNextPage bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user