Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Add new structs and helper to get auth token/sig from GQL API
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarbuzzi committed Jan 15, 2021
1 parent 614b492 commit 0ec1d3e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions structs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"log"
"net/url"
"path/filepath"
Expand Down Expand Up @@ -57,3 +58,40 @@ type Chunk struct {
URL *url.URL
Path string
}

// AuthGQLPayload represents the payload sent to the GQL endpoint to get the
// auth token and signature
type AuthGQLPayload struct {
OperationName string `json:"operationName"`
Query string `json:"query"`
Variables struct {
IsLive bool `json:"isLive"`
IsVod bool `json:"isVod"`
Login string `json:"login"`
PlayerType string `json:"playerType"`
VodID string `json:"vodID"`
} `json:"variables"`
}

func generateAuthPayload(vodID string) ([]byte, error) {
ap := AuthGQLPayload{
OperationName: "PlaybackAccessToken_Template",
Query: "query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) { streamPlaybackAccessToken(channelName: $login, params: {platform: \"web\", playerBackend: \"mediaplayer\", playerType: $playerType}) @include(if: $isLive) { value signature __typename } videoPlaybackAccessToken(id: $vodID, params: {platform: \"web\", playerBackend: \"mediaplayer\", playerType: $playerType}) @include(if: $isVod) { value signature __typename }}",
}
ap.Variables.IsLive = false
ap.Variables.IsVod = true
ap.Variables.PlayerType = "site"
ap.Variables.VodID = vodID
return json.Marshal(ap)
}

// AuthGQLPayload represents the response from to the GQL endpoint containing
// the auth token and signature
type AuthGQLResponse struct {
Data struct {
VideoPlaybackAccessToken struct {
Value string `json:"value"`
Signature string `json:"signature"`
} `json:"videoPlaybackAccessToken"`
} `json:"data"`
}

0 comments on commit 0ec1d3e

Please sign in to comment.