mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Add watchlist endpoint, add new request method & change SortType name and consts
This commit is contained in:
parent
141173d3c8
commit
c5f2b55f34
3 changed files with 199 additions and 12 deletions
21
video.go
21
video.go
|
|
@ -1,6 +1,7 @@
|
|||
package crunchyroll
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
|
@ -193,6 +194,26 @@ func SeriesFromID(crunchy *Crunchyroll, id string) (*Series, error) {
|
|||
return series, nil
|
||||
}
|
||||
|
||||
// AddToWatchlist adds the current episode to the watchlist.
|
||||
func (s *Series) AddToWatchlist() error {
|
||||
endpoint := fmt.Sprintf("https://beta.crunchyroll.com/content/v1/watchlist/%s?locale=%s", s.crunchy.Config.AccountID, s.crunchy.Locale)
|
||||
body, _ := json.Marshal(map[string]string{"content_id": s.ID})
|
||||
req, err := http.NewRequest(http.MethodPost, endpoint, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
_, err = s.crunchy.requestFull(req)
|
||||
return err
|
||||
}
|
||||
|
||||
// RemoveFromWatchlist removes the current episode from the watchlist.
|
||||
func (s *Series) RemoveFromWatchlist() error {
|
||||
endpoint := fmt.Sprintf("https://beta.crunchyroll.com/content/v1/watchlist/%s/%s?locale=%s", s.crunchy.Config.AccountID, s.ID, s.crunchy.Locale)
|
||||
_, err := s.crunchy.request(endpoint, http.MethodDelete)
|
||||
return err
|
||||
}
|
||||
|
||||
// Seasons returns all seasons of a series.
|
||||
func (s *Series) Seasons() (seasons []*Season, err error) {
|
||||
if s.children != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue