Add available function to check if season streams are available

This commit is contained in:
bytedream 2022-05-18 21:47:17 +02:00
parent 43be2eee14
commit f635bf1a2e
3 changed files with 14 additions and 3 deletions

View file

@ -70,8 +70,9 @@ func SeasonFromID(crunchy *Crunchyroll, id string) (*Season, error) {
}
// AudioLocale returns the audio locale of the season.
// Will fail if no streams are available, thus use Season.Available
// to prevent any misleading errors.
func (s *Season) AudioLocale() (LOCALE, error) {
// TODO: Add a function like Episode.Available to prevent this from returning an unwanted error when the account is non-premium
episodes, err := s.Episodes()
if err != nil {
return "", err
@ -79,6 +80,15 @@ func (s *Season) AudioLocale() (LOCALE, error) {
return episodes[0].AudioLocale()
}
// Available returns if downloadable streams for this season are available.
func (s *Season) Available() (bool, error) {
episodes, err := s.Episodes()
if err != nil {
return false, err
}
return episodes[0].Available(), nil
}
// Episodes returns all episodes which are available for the season.
func (s *Season) Episodes() (episodes []*Episode, err error) {
if s.children != nil {