mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Added caching
This commit is contained in:
parent
0e8738a304
commit
a5d9696c9c
5 changed files with 72 additions and 1 deletions
16
episode.go
16
episode.go
|
|
@ -10,6 +10,8 @@ import (
|
|||
type Episode struct {
|
||||
crunchy *Crunchyroll
|
||||
|
||||
children []*Stream
|
||||
|
||||
siteCache map[string]interface{}
|
||||
|
||||
ID string `json:"id"`
|
||||
|
|
@ -134,7 +136,11 @@ func (e *Episode) AudioLocale() (LOCALE, error) {
|
|||
|
||||
// Streams returns all streams which are available for the episode
|
||||
func (e *Episode) Streams() ([]*Stream, error) {
|
||||
return fromVideoStreams(e.crunchy, fmt.Sprintf("https://beta-api.crunchyroll.com/cms/v2/%s/%s/%s/videos/%s/streams?locale=%s&Signature=%s&Policy=%s&Key-Pair-Id=%s",
|
||||
if e.children != nil {
|
||||
return e.children, nil
|
||||
}
|
||||
|
||||
streams, err := fromVideoStreams(e.crunchy, fmt.Sprintf("https://beta-api.crunchyroll.com/cms/v2/%s/%s/%s/videos/%s/streams?locale=%s&Signature=%s&Policy=%s&Key-Pair-Id=%s",
|
||||
e.crunchy.Config.CountryCode,
|
||||
e.crunchy.Config.MaturityRating,
|
||||
e.crunchy.Config.Channel,
|
||||
|
|
@ -143,4 +149,12 @@ func (e *Episode) Streams() ([]*Stream, error) {
|
|||
e.crunchy.Config.Signature,
|
||||
e.crunchy.Config.Policy,
|
||||
e.crunchy.Config.KeyPairID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if e.crunchy.cache {
|
||||
e.children = streams
|
||||
}
|
||||
return streams, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue