71 lines
2.0 KiB
Go
71 lines
2.0 KiB
Go
|
package streams
|
|||
|
|
|||
|
import (
|
|||
|
"context"
|
|||
|
"encoding/json"
|
|||
|
"io"
|
|||
|
"net/http"
|
|||
|
"net/url"
|
|||
|
)
|
|||
|
|
|||
|
type CreateStreamMarkerRequest struct {
|
|||
|
// The ID of the broadcaster that’s streaming content.
|
|||
|
// 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.
|
|||
|
UserID string `json:"user_id"`
|
|||
|
|
|||
|
// A short description of the marker to help the user remember why they marked the location.
|
|||
|
// The maximum length of the description is 140 characters.
|
|||
|
Description string `json:"description"`
|
|||
|
}
|
|||
|
|
|||
|
type CreateStreamMarkerResponse struct {
|
|||
|
// A list that contains the single marker that you added.
|
|||
|
Data []StreamMarker `json:"data"`
|
|||
|
}
|
|||
|
|
|||
|
// Adds a marker to a live stream. A marker is an arbitrary point in a live stream that the broadcaster or editor wants to mark,
|
|||
|
// so they can return to that spot later to create video highlights (see Video Producer, Highlights in the Twitch UX).
|
|||
|
//
|
|||
|
// You may not add markers:
|
|||
|
//
|
|||
|
// - If the stream is not live
|
|||
|
//
|
|||
|
// - If the stream has not enabled video on demand (VOD)
|
|||
|
//
|
|||
|
// - If the stream is a premiere (a live, first-viewing event that combines uploaded videos with live chat)
|
|||
|
//
|
|||
|
// - If the stream is a rerun of a past broadcast, including past premieres.
|
|||
|
//
|
|||
|
// Requires a user access token that includes the channel:manage:broadcast scope.
|
|||
|
func (s *Streams) CreateStreamMarker(ctx context.Context, body *CreateStreamMarkerRequest) (*CreateStreamMarkerResponse, error) {
|
|||
|
endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "streams/markers"})
|
|||
|
|
|||
|
r, w := io.Pipe()
|
|||
|
|
|||
|
go func() {
|
|||
|
if err := json.NewEncoder(w).Encode(body); err != nil {
|
|||
|
w.CloseWithError(err)
|
|||
|
} else {
|
|||
|
w.Close()
|
|||
|
}
|
|||
|
}()
|
|||
|
|
|||
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
res, err := s.client.Do(req)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
defer res.Body.Close()
|
|||
|
|
|||
|
var data CreateStreamMarkerResponse
|
|||
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
return &data, nil
|
|||
|
}
|