u
This commit is contained in:
parent
6bfd2d8736
commit
e46e16f8c9
@ -41,8 +41,8 @@ type PlayConfig struct {
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Input []any `json:"input"`
|
Input []any `json:"input"`
|
||||||
inputItems []InputItem `json:"-"` // contains video file or dir
|
InputItems []InputItem `json:"-"` // contains video file or dir
|
||||||
PlayList []InputItem `json:"-"` // only contains video file
|
VideoList []InputItem `json:"-"` // only contains video file
|
||||||
Play PlayConfig `json:"play"`
|
Play PlayConfig `json:"play"`
|
||||||
Output OutputConfig `json:"output"`
|
Output OutputConfig `json:"output"`
|
||||||
}
|
}
|
||||||
@ -52,18 +52,18 @@ var GlobalConfig Config
|
|||||||
func init() {
|
func init() {
|
||||||
GlobalConfig = Config{}
|
GlobalConfig = Config{}
|
||||||
err := readConfig("config.json")
|
err := readConfig("config.json")
|
||||||
for i, item := range GlobalConfig.inputItems {
|
for i, item := range GlobalConfig.InputItems {
|
||||||
if item.ItemType == "file" {
|
if item.ItemType == "file" {
|
||||||
GlobalConfig.PlayList = append(GlobalConfig.PlayList, item)
|
GlobalConfig.VideoList = append(GlobalConfig.VideoList, item)
|
||||||
} else if item.ItemType == "dir" {
|
} else if item.ItemType == "dir" {
|
||||||
videos, err := getAllVideos(item.Path)
|
videos, err := getAllVideos(item.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("input[%v] walk error: %v", i, err)
|
log.Fatalf("input[%v] walk error: %v", i, err)
|
||||||
}
|
}
|
||||||
GlobalConfig.PlayList = append(GlobalConfig.PlayList, videos...)
|
GlobalConfig.VideoList = append(GlobalConfig.VideoList, videos...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(GlobalConfig.PlayList) == 0 {
|
if len(GlobalConfig.VideoList) == 0 {
|
||||||
log.Fatal("No input video found")
|
log.Fatal("No input video found")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -122,7 +122,7 @@ func validateInputConfig() error {
|
|||||||
return fmt.Errorf("video_path[%v] is not supported", i)
|
return fmt.Errorf("video_path[%v] is not supported", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalConfig.inputItems = append(GlobalConfig.inputItems, inputItem)
|
GlobalConfig.InputItems = append(GlobalConfig.InputItems, inputItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
4
main.go
4
main.go
@ -18,7 +18,7 @@ func main() {
|
|||||||
if !utils.HasFFMPEG() {
|
if !utils.HasFFMPEG() {
|
||||||
log.Fatal("ffmpeg not found")
|
log.Fatal("ffmpeg not found")
|
||||||
}
|
}
|
||||||
GlobalStreamer = streamer.NewStreamer(config.GlobalConfig.PlayList)
|
GlobalStreamer = streamer.NewStreamer(config.GlobalConfig.VideoList)
|
||||||
go input()
|
go input()
|
||||||
go startWatcher()
|
go startWatcher()
|
||||||
GlobalStreamer.Stream()
|
GlobalStreamer.Stream()
|
||||||
@ -54,7 +54,7 @@ func startWatcher() {
|
|||||||
}
|
}
|
||||||
defer watcher.Close()
|
defer watcher.Close()
|
||||||
|
|
||||||
for _, item := range config.GlobalConfig.PlayList {
|
for _, item := range config.GlobalConfig.InputItems {
|
||||||
if item.ItemType == "dir" {
|
if item.ItemType == "dir" {
|
||||||
err = watcher.Add(item.Path)
|
err = watcher.Add(item.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user