package twitch import ( "fmt" "github.com/tidwall/gjson" ) type PlaybackAccessToken struct { Signature string Token string } // Assumes streamer is live // If no vodID give "" func getPlaybackAccessToken(streamerName string, vodID string) (PlaybackAccessToken, error) { var isVod bool var isLive bool if vodID != "" { isVod = true isLive = false } else { isVod = false isLive = true } payload1 := []TwitchPayload{ { "extensions": map[string]interface{}{ "persistedQuery": map[string]interface{}{ "version": 1, "sha256Hash": "0828119ded1c13477966434e15800ff57ddacf13ba1911c129dc2200705b0712", }, }, "operationName": "PlaybackAccessToken", "variables": map[string]interface{}{ "isLive": isLive, "login": streamerName, "isVod": isVod, "vodID": vodID, "playerType": "site", }, }, } _, body, err := parseResponse(payload1) if err != nil { return PlaybackAccessToken{}, err } fmt.Println(string(body)) var token string var signature string if isLive { token = gjson.Get(string(body), "0.data.streamPlaybackAccessToken.value").String() signature = gjson.Get(string(body), "0.data.streamPlaybackAccessToken.signature").String() if err != nil { return PlaybackAccessToken{}, err } } else { token = gjson.Get(string(body), "0.data.videoPlaybackAccessToken.value").String() signature = gjson.Get(string(body), "0.data.videoPlaybackAccessToken.signature").String() if err != nil { return PlaybackAccessToken{}, err } } return PlaybackAccessToken{ Signature: signature, Token: token, }, nil }