Add available function to check if episode streams are available

This commit is contained in:
bytedream 2022-05-16 22:24:21 +02:00
parent 6c476df24e
commit 0ffae4ddda
3 changed files with 15 additions and 0 deletions

View file

@ -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()