This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructs.go
91 lines (83 loc) · 2.85 KB
/
structs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"encoding/json"
"log"
"net/url"
"path/filepath"
"runtime"
"strings"
)
func isValidFilename(fn string) bool {
log.Printf("[isValidFilename] validating: %s\n", fn)
if runtime.GOOS != "windows" {
return true
}
// source: https://msdn.microsoft.com/en-us/library/aa365247
// first, check for bad characters
log.Println("[isValidFilename] checking for bad characters")
badChars := []string{"<", ">", ":", "\"", "/", "\\", "|", "?", "*"}
for _, badChar := range badChars {
if strings.Contains(fn, badChar) {
return false
}
}
// next, check for bad names
log.Println("[isValidFilename] checking for bad names")
badNames := []string{
"CON", "PRN", "AUX", "NUL",
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
}
for _, badName := range badNames {
if fn == badName || string(fn[:len(fn)-len(filepath.Ext(fn))]) == badName {
return false
}
}
// finally, make sure it doesn't end in " " or "."
log.Println("[isValidFilename] checking final character")
if string(fn[len(fn)-1]) == " " || string(fn[len(fn)-1]) == "." {
return false
}
return true
}
// Chunk represents a video chunk from the m3u
type Chunk struct {
Name string
Length float64
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"`
}