-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
77 lines (57 loc) · 1.33 KB
/
main.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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os/exec"
"time"
"github.com/mattn/go-shellwords"
)
//Setting setting.json struct
type Setting struct {
StartHour int `json:"startHour"`
RecTime string `json:"recTime"`
OutputDir string `json:"outputDir"`
RtmpURL string `json:"rtmpUrl"`
FileName string `json:"fileName"`
FileExtention string `json:"fileExtention"`
}
func runCmdStr(cmdstr string) error {
log.Println(cmdstr)
c, err := shellwords.Parse(cmdstr)
failOnError(err)
switch len(c) {
case 0:
return nil
case 1:
err := exec.Command(c[0]).Run()
failOnError(err)
default:
err := exec.Command(c[0], c[1:]...).Run()
failOnError(err)
}
return nil
}
func failOnError(err error) {
if err != nil {
panic(err)
}
}
func main() {
bytes, err := ioutil.ReadFile("setting.json")
failOnError(err)
var setting []Setting
if err := json.Unmarshal(bytes, &setting); err != nil {
failOnError(err)
}
t := time.Now()
hour := t.Hour()
for _, schedule := range setting {
if schedule.StartHour == hour {
fileName := t.Format("20060102150405") + "_" + schedule.FileName + schedule.FileExtention
cmdstr := "rtmpdump --live --rtmp " + schedule.RtmpURL + " --timeout 60 -B " + schedule.RecTime + " -o " + schedule.OutputDir + fileName
runCmdStr(cmdstr)
break
}
}
}