mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Add available function to check if episode streams are available
This commit is contained in:
parent
6c476df24e
commit
0ffae4ddda
3 changed files with 15 additions and 0 deletions
|
|
@ -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()
|
||||
|
|
|
|||
5
url.go
5
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
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue