Added caching

This commit is contained in:
bytedream 2022-02-07 14:07:35 +01:00
parent 0e8738a304
commit a5d9696c9c
5 changed files with 72 additions and 1 deletions

View file

@ -11,6 +11,8 @@ import (
type Stream struct {
crunchy *Crunchyroll
children []*Format
HardsubLocale LOCALE
AudioLocale LOCALE
Subtitles []*Subtitle
@ -35,6 +37,10 @@ func StreamsFromID(crunchy *Crunchyroll, id string) ([]*Stream, error) {
// Formats returns all formats which are available for the stream
func (s *Stream) Formats() ([]*Format, error) {
if s.children != nil {
return s.children, nil
}
resp, err := s.crunchy.Client.Get(s.streamURL)
if err != nil {
return nil, err
@ -57,6 +63,10 @@ func (s *Stream) Formats() ([]*Format, error) {
Subtitles: s.Subtitles,
})
}
if s.crunchy.cache {
s.children = formats
}
return formats, nil
}