twitch

package
v0.0.0-...-f900513 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetCurrentTwitchUserURL     = "https://api.twitch.tv/helix/users"
	GetUserFollowsURLFormat     = "https://api.twitch.tv/helix/users/follows?from_id=%s"
	GetLiveStreamsURLFormat     = "https://api.twitch.tv/helix/streams?type=live&user_id=%s"
	GetChannelAccessTokenFormat = "https://api.twitch.tv/api/channels/%s/access_token?client_id=%s"
	GetStreamsURLFormat         = "" /* 135-byte string literal not displayed */
)

The constant definitions for the URLs to be used to interact with the Twitch API.

Variables

This section is empty.

Functions

func GetStream

func GetStream(client *http.Client, channelName, accessToken, streamQuality string) (*m3u8.Variant, error)

GetStream will load the stream details for the provided channel name. The streamQuality parameter should be either audio_only or a target video resolution.

func InitEnv

func InitEnv(redisURL string)

InitEnv provides a package level initialization point for any work that is environment specific

func SaveUsersCurrentStream

func SaveUsersCurrentStream(user *User, stream *Stream)

SaveUsersCurrentStream will append the provided stream's User ID to the list of recently played. The list is set to automatically expire after 24 hours. This expiration time will be updated on each stream start.

Types

type ChannelAccessToken

type ChannelAccessToken struct {
	Sig   string `json:"sig"`
	Token string `json:"token"`
}

ChannelAccessToken is used for loading the stream URL for a specific channel. For some reason this type of request auth needs to be used instead of the other oauth process.

type Follow

type Follow struct {
	FromID string `json:"from_id"`
	ToID   string `json:"to_id"`
}

Follow describes a single follower relationship, FromID is the user doing the following and ToID is the user being followed.

func (*Follow) String

func (f *Follow) String() string

type Follows

type Follows struct {
	Data []*Follow
}

Follows is a wrapper around the response when requesting a set of follower relationships

func GetFollows

func GetFollows(client *http.Client, user *User) (*Follows, error)

GetFollows will load the following information for the provided Twitch user. The channels returned will be all of the channels followed by this user.

func (*Follows) FollowIDsList

func (follows *Follows) FollowIDsList() []string

FollowIDsList will extract the user IDs from the calling Follows struct into a single slice

type Pagination

type Pagination struct {
	Cursor string `json:"cursor"`
}

Pagination wraps the cursor used to perform pagination on endpoints that support it. The cursor should be used in following requests to indicate the current page.

type PlaybackCommand

type PlaybackCommand int
const (
	PLAY PlaybackCommand = iota
	RESUME
	PAUSE
	PREVIOUS
	NEXT
	STOP
)

type Stream

type Stream struct {
	ID           string   `json:"id"`
	UserID       string   `json:"user_id"`
	CommunityIDs []string `json:"community_ids"`
	Type         string   `json:"type"`
	Title        string   `json:"title"`
	ViewerCount  int      `json:"viewer_count"`
	ThumbnailURL string   `json:"thumbnail_url"`
}

Stream describes the properties for a particular stream on Twitch

func FindStreamForCommand

func FindStreamForCommand(user *User, liveStreams []*Stream, command PlaybackCommand, response *skillserver.EchoResponse) *Stream

func (*Stream) String

func (s *Stream) String() string

type StreamsResponse

type StreamsResponse struct {
	Data []*Stream
	*Pagination
}

StreamsResponse container around the Twitch streams response.

func FindLiveStreams

func FindLiveStreams(client *http.Client, uids []string) (*StreamsResponse, error)

FindLiveStreams will request the data for all currently live streams on Twitch for the provided list of user IDs.

type User

type User struct {
	ID              string `json:"id"`
	Login           string `json:"login"`
	DisplayName     string `json:"display_name"`
	Type            string `json:"type"`
	BroadcasterType string `json:"broadcaster_type"`
}

User contains all the properties for a particular Twitch user.

func GetUserByID

func GetUserByID(client *http.Client, accessToken, id string) (*User, error)

GetUserByID will load details for the user specified by the provided id. If the ID is the empty string, the current user will be determined from the provided access token.

func (*User) String

func (u *User) String() string

type UserResponse

type UserResponse struct {
	Data []*User
}

UserResponse is a container around the response from the Twitch /users endpoint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL