-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
114 lines (89 loc) · 1.83 KB
/
config.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net"
"os"
"strings"
)
const VERSION = 2
var (
VIDEOFORMATS = []string{".mp4", ".rmvb", ".avi", ".mkv", ".mov"}
configpath = flag.String("cfg", "config.cfg", "config file")
videos []*VideoList
PthSep = string(os.PathSeparator)
serverinfo map[string]interface{}
videoinfos *TimeOutMap
videoimgs *TimeOutMap
)
type FileType int
const (
UNKNOWN FileType = iota
VIDEO
SRT
DIR
FILE
)
type VideoList struct {
Files []string `json:"files"`
Subtitles []string `json:"subtitles"`
}
type Format struct {
Duration string `json:"duration"`
Size string `json:"size"`
}
type Streams struct {
Index int `json:"index"`
CodecName string `json:"codec_name"`
CodecType string `json:"codec_type"`
Width int `json:"width"`
Height int `json:"height"`
}
type Metadata struct {
Streams []Streams `json:"streams"`
Format Format `json:"format"`
}
type Config struct {
Name string
FilePath []PathConfig
}
type PathConfig struct {
Path string
Sub bool
}
func LoadConfig(filepath string) (*Config, error) {
config := new(Config)
body, err := ioutil.ReadFile(filepath)
if err != nil {
return nil, err
}
err = json.Unmarshal(body, config)
if err != nil {
return nil, err
}
config.Name = strings.TrimSpace(config.Name)
if config.Name == "" {
return nil, fmt.Errorf("config.cfg name can not empty!")
}
if len(filepath) < 1 {
return nil, fmt.Errorf("config.cfg filepath can not empty!")
}
return config, nil
}
func getLocalAddr() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
panic(err)
}
for _, address := range addrs {
// 检查ip地址判断是否回环地址
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP.String()
}
}
}
return "0.0.0.0"
}