Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加 webui #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Config struct {
Tmdb *TmdbConfig `json:"tmdb"` // TMDB 配置
Kodi *KodiConfig `json:"kodi"` // kodi配置
Collector *CollectorConfig `json:"collector"` // 刮削配置
Webui *Webui `json:"webui"` // webui配置
}

type KodiConfig struct {
Expand Down Expand Up @@ -47,3 +48,9 @@ type CollectorConfig struct {
ShowsDir []string `json:"shows_dir"` // 电视剧文件根目录,可多个
MusicVideosDir []string `json:"music_videos_dir"` // 音乐视频文件根目录,可多个
}

type Webui struct {
Enable bool `json:"enable"` // 是否开启webui
Listen string `json:"listen"` // 监听地址
Password string `json:"password"` // webui密码
}
5 changes: 5 additions & 0 deletions example.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@
"max_worker": 4,
"ffmpeg_path": "/usr/local/ffmpeg-5.0.1-amd64-static/ffmpeg",
"ffprobe_path": "/usr/local/ffmpeg-5.0.1-amd64-static/ffprobe"
},
"webui": {
"enable": false,
"listen": "localhost:2212",
"password": ""
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/fsnotify/fsnotify v1.6.0
golang.org/x/net v0.23.0
golang.org/x/net v0.24.0
)

require golang.org/x/sys v0.18.0 // indirect
require golang.org/x/sys v0.19.0 // indirect
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fengqi/kodi-metadata-tmdb-cli/shows"
"fengqi/kodi-metadata-tmdb-cli/tmdb"
"fengqi/kodi-metadata-tmdb-cli/utils"
"fengqi/kodi-metadata-tmdb-cli/webui"
"flag"
"fmt"
"runtime"
Expand Down Expand Up @@ -41,9 +42,10 @@ func main() {
ffmpeg.InitFfmpeg(c.Ffmpeg)

wg := &sync.WaitGroup{}
wg.Add(3)
wg.Add(4)
go shows.RunCollector(c)
go movies.RunCollector(c)
go music_videos.RunCollector(c)
go webui.RunWebui(c)
wg.Wait()
}
27 changes: 27 additions & 0 deletions webui/webui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package webui

import (
"fengqi/kodi-metadata-tmdb-cli/config"
"fengqi/kodi-metadata-tmdb-cli/utils"
"net/http"
)

func RunWebui(config *config.Config) {
if !config.Webui.Enable {
return
}

// Routes
http.HandleFunc("/", hello)

// Start server
utils.Logger.InfoF("webui started on http://%s", config.Webui.Listen)
if err := http.ListenAndServe(config.Webui.Listen, nil); err != nil {
panic(err)
}
}

// Handler
func hello(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello"))
}