mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Added caching
This commit is contained in:
parent
0e8738a304
commit
a5d9696c9c
5 changed files with 72 additions and 1 deletions
|
|
@ -9,6 +9,8 @@ import (
|
|||
type Season struct {
|
||||
crunchy *Crunchyroll
|
||||
|
||||
children []*Episode
|
||||
|
||||
ID string `json:"id"`
|
||||
ChannelID string `json:"channel_id"`
|
||||
|
||||
|
|
@ -69,6 +71,10 @@ func SeasonFromID(crunchy *Crunchyroll, id string) (*Season, error) {
|
|||
|
||||
// Episodes returns all episodes which are available for the season
|
||||
func (s *Season) Episodes() (episodes []*Episode, err error) {
|
||||
if s.children != nil {
|
||||
return s.children, nil
|
||||
}
|
||||
|
||||
resp, err := s.crunchy.request(fmt.Sprintf("https://beta-api.crunchyroll.com/cms/v2/%s/%s/%s/episodes?season_id=%s&locale=%s&Signature=%s&Policy=%s&Key-Pair-Id=%s",
|
||||
s.crunchy.Config.CountryCode,
|
||||
s.crunchy.Config.MaturityRating,
|
||||
|
|
@ -101,5 +107,8 @@ func (s *Season) Episodes() (episodes []*Episode, err error) {
|
|||
episodes = append(episodes, episode)
|
||||
}
|
||||
|
||||
if s.crunchy.cache {
|
||||
s.children = episodes
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue