2024-03-03 17:34:18 -05:00
|
|
|
|
package streams
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-03-03 17:34:18 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-03-03 17:34:18 -05:00
|
|
|
|
"go.fifitido.net/twitch/api/types"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GetStreamMarkersParams struct {
|
|
|
|
|
// A user ID. The request returns the markers from this user’s most recent video.
|
|
|
|
|
// This ID must match the user ID in the access token or the user in the access token must be one of the broadcaster’s editors.
|
|
|
|
|
//
|
|
|
|
|
// This parameter and the video_id query parameter are mutually exclusive.
|
|
|
|
|
UserID *string `url:"user_id,omitempty"`
|
|
|
|
|
|
|
|
|
|
// A video on demand (VOD)/video ID. The request returns the markers from this VOD/video.
|
|
|
|
|
// The user in the access token must own the video or the user must be one of the broadcaster’s editors.
|
|
|
|
|
//
|
|
|
|
|
// This parameter and the user_id query parameter are mutually exclusive.
|
|
|
|
|
VideoID *string `url:"video_id,omitempty"`
|
|
|
|
|
|
|
|
|
|
// The maximum number of items to return per page in the response.
|
|
|
|
|
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
|
|
|
|
// The default is 20.
|
|
|
|
|
First *int `url:"first,omitempty"`
|
|
|
|
|
|
|
|
|
|
// The cursor used to get the previous page of results.
|
|
|
|
|
// The Pagination object in the response contains the cursor’s value.
|
|
|
|
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
|
|
|
|
Before *types.Cursor `url:"before,omitempty"`
|
|
|
|
|
|
|
|
|
|
// The cursor used to get the next page of results.
|
|
|
|
|
// The Pagination object in the response contains the cursor’s value.
|
|
|
|
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
|
|
|
|
After *types.Cursor `url:"after,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetStreamMarkersResponse struct {
|
|
|
|
|
// The list of markers grouped by the user that created the marks.
|
|
|
|
|
Data []StreamMarkers `json:"data"`
|
|
|
|
|
|
|
|
|
|
// The information used to page through the list of results.
|
|
|
|
|
// The object is empty if there are no more pages left to page through.
|
|
|
|
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
|
|
|
|
Pagination types.Pagination `json:"pagination"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets a list of markers from the user’s most recent stream or from the specified VOD/video.
|
|
|
|
|
// A marker is an arbitrary point in a live stream that the broadcaster or editor marked,
|
|
|
|
|
// so they can return to that spot later to create video highlights (see Video Producer, Highlights in the Twitch UX).
|
|
|
|
|
//
|
|
|
|
|
// Requires a user access token that includes the user:read:broadcast or channel:manage:broadcast scope.
|
|
|
|
|
func (s *Streams) GetStreamMarkers(ctx context.Context, params *GetStreamMarkersParams) (*GetStreamMarkersResponse, error) {
|
|
|
|
|
v, _ := query.Values(params)
|
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(s.baseUrl, "streams/markers", v), nil)
|
2024-03-03 17:34:18 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := s.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return nil, fmt.Errorf("failed to get stream markers (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 17:34:18 -05:00
|
|
|
|
var data GetStreamMarkersResponse
|
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|