2023-07-27 10:29:54 +00:00
|
|
|
|
package twitch
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"net/http"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
|
// ChannelStreamSchedule represents the schedule of a channels with
|
|
|
|
|
// its segments represening single planned streams
|
|
|
|
|
ChannelStreamSchedule struct {
|
2023-11-05 12:15:42 +00:00
|
|
|
|
Segments []ChannelStreamScheduleSegment `json:"segments"`
|
|
|
|
|
BroadcasterID string `json:"broadcaster_id"`
|
|
|
|
|
BroadcasterName string `json:"broadcaster_name"`
|
|
|
|
|
BroadcasterLogin string `json:"broadcaster_login"`
|
2023-07-27 10:29:54 +00:00
|
|
|
|
Vacation struct {
|
|
|
|
|
StartTime time.Time `json:"start_time"`
|
|
|
|
|
EndTime time.Time `json:"end_time"`
|
|
|
|
|
} `json:"vacation"`
|
|
|
|
|
}
|
2023-11-05 12:15:42 +00:00
|
|
|
|
|
|
|
|
|
ChannelStreamScheduleSegment struct {
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
StartTime time.Time `json:"start_time"`
|
|
|
|
|
EndTime time.Time `json:"end_time"`
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
CanceledUntil *time.Time `json:"canceled_until"`
|
|
|
|
|
Category struct {
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
} `json:"category"`
|
|
|
|
|
IsRecurring bool `json:"is_recurring"`
|
|
|
|
|
}
|
2023-07-27 10:29:54 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// GetChannelStreamSchedule gets the broadcaster’s streaming schedule
|
|
|
|
|
func (c *Client) GetChannelStreamSchedule(ctx context.Context, channel string) (*ChannelStreamSchedule, error) {
|
|
|
|
|
channelID, err := c.GetIDForUsername(strings.TrimLeft(channel, "#@"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errors.Wrap(err, "getting channel user-id")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var payload struct {
|
|
|
|
|
Data *ChannelStreamSchedule `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return payload.Data, errors.Wrap(
|
|
|
|
|
c.Request(ClientRequestOpts{
|
|
|
|
|
AuthType: AuthTypeAppAccessToken,
|
|
|
|
|
Context: ctx,
|
|
|
|
|
Method: http.MethodGet,
|
|
|
|
|
OKStatus: http.StatusOK,
|
|
|
|
|
Out: &payload,
|
|
|
|
|
URL: fmt.Sprintf("https://api.twitch.tv/helix/schedule?broadcaster_id=%s", channelID),
|
|
|
|
|
}),
|
|
|
|
|
"executing request",
|
|
|
|
|
)
|
|
|
|
|
}
|