This repository has been archived by the owner on Jun 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
UpdateLiveMedia.go
72 lines (62 loc) · 2.06 KB
/
UpdateLiveMedia.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
package hitGox
import (
"bytes"
"encoding/json"
"fmt"
"log"
just "github.com/toby3d/hitGox/tools"
f "github.com/valyala/fasthttp"
)
type update struct {
MediaUserName string `json:"media_user_name"`
MediaID string `json:"media_id"`
MediaCategoryID string `json:"media_category_id"`
MediaLiveDelay string `json:"media_live_delay"`
MediaHidden string `json:"media_hidden"`
MediaRecording string `json:"media_recording"`
MediaMature string `json:"media_mature"`
MediaHostedName string `json:"media_hosted_name"`
MediaCountries []string `json:"media_countries"`
MediaStatus string `json:"media_status"`
MediaDescription string `json:"media_description"`
}
func (account *Account) UpdateLiveMedia(channel string, changes Livestream) (*LiveMedia, error) {
var args f.Args
args.Add("authToken", account.AuthToken)
var upd = struct {
Livestream []update `json:"livestream"`
}{}
upd.Livestream = append(upd.Livestream, update{
MediaUserName: changes.MediaName,
MediaID: changes.MediaID,
MediaCategoryID: changes.MediaCategoryID,
MediaLiveDelay: changes.MediaLiveDelay,
MediaRecording: changes.MediaRecording,
MediaMature: changes.MediaMature,
MediaStatus: changes.MediaStatus,
MediaDescription: changes.MediaDescription,
MediaHidden: changes.MediaHidden,
})
upd.Livestream[0].MediaCountries = append(upd.Livestream[0].MediaCountries, changes.MediaCountries[0])
if changes.MediaHidden == "" {
upd.Livestream[0].MediaHidden = "0"
}
if len(changes.MediaHostedMedia.Livestream) != 0 {
upd.Livestream[0].MediaHostedName = changes.MediaHostedMedia.Livestream[0].MediaUserName
} else {
upd.Livestream[0].MediaHostedName = "off"
}
dst, err := json.Marshal(&upd)
if err != nil {
return nil, err
}
log.Printf("%#v", string(dst))
url := fmt.Sprintf(APIEndpoint, fmt.Sprint("media/live/", channel))
resp, err := just.PUT(dst, url, &args)
if err != nil {
return nil, err
}
var obj LiveMedia
json.NewDecoder(bytes.NewReader(resp)).Decode(&obj)
return &obj, nil
}