mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Move functions into their own, separate files & add docs
This commit is contained in:
parent
d1859b4c25
commit
ec872d8c86
12 changed files with 681 additions and 638 deletions
32
simulcast.go
32
simulcast.go
|
|
@ -1,5 +1,37 @@
|
|||
package crunchyroll
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Simulcasts returns all available simulcast seasons for the current locale.
|
||||
func (c *Crunchyroll) Simulcasts() (s []*Simulcast, err error) {
|
||||
seasonListEndpoint := fmt.Sprintf("https://beta.crunchyroll.com/content/v1/season_list?locale=%s", c.Locale)
|
||||
resp, err := c.request(seasonListEndpoint, http.MethodGet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var jsonBody map[string]interface{}
|
||||
if err = json.NewDecoder(resp.Body).Decode(&jsonBody); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse 'season_list' response: %w", err)
|
||||
}
|
||||
|
||||
for _, item := range jsonBody["items"].([]interface{}) {
|
||||
simulcast := &Simulcast{}
|
||||
if err := decodeMapToStruct(item, simulcast); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s = append(s, simulcast)
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Simulcast contains all information about a simulcast season.
|
||||
type Simulcast struct {
|
||||
ID string `json:"id"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue