diff --git a/episode.go b/episode.go index 3c9d38f..7d477ce 100644 --- a/episode.go +++ b/episode.go @@ -112,6 +112,8 @@ func EpisodeFromID(crunchy *Crunchyroll, id string) (*Episode, error) { // Every episode in a season (should) have the same audio locale, // so if you want to get the audio locale of a season, just call // this method on the first episode of the season. +// Will fail if no streams are available, thus use Available to +// prevent any misleading errors. func (e *Episode) AudioLocale() (LOCALE, error) { streams, err := e.Streams() if err != nil { @@ -120,6 +122,11 @@ func (e *Episode) AudioLocale() (LOCALE, error) { return streams[0].AudioLocale, nil } +// Available returns if downloadable streams for this episodes are available. +func (e *Episode) Available() bool { + return e.crunchy.Config.Premium || !e.IsPremiumOnly +} + // GetFormat returns the format which matches the given resolution and subtitle locale. func (e *Episode) GetFormat(resolution string, subtitle LOCALE, hardsub bool) (*Format, error) { streams, err := e.Streams() diff --git a/url.go b/url.go index 32603fc..c84a3b9 100644 --- a/url.go +++ b/url.go @@ -49,6 +49,11 @@ func (c *Crunchyroll) ExtractEpisodesFromUrl(url string, audio ...LOCALE) ([]*Ep } for _, episode := range episodes { + // if no episode streams are available, calling episode.AudioLocale + // will result in an unwanted error + if !episode.Available() { + continue + } locale, err := episode.AudioLocale() if err != nil { return nil, err diff --git a/utils/sort.go b/utils/sort.go index a44717d..e06946c 100644 --- a/utils/sort.go +++ b/utils/sort.go @@ -52,6 +52,9 @@ func SortEpisodesByAudio(episodes []*crunchyroll.Episode) (map[crunchyroll.LOCAL var wg sync.WaitGroup var lock sync.Mutex for _, episode := range episodes { + if !episode.Available() { + continue + } episode := episode wg.Add(1) go func() {