2021-02-23 16:01:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-05-05 19:32:35 +00:00
|
|
|
"flag"
|
2021-02-23 16:01:29 +00:00
|
|
|
"fmt"
|
|
|
|
"openmediacenter/apiGo/api"
|
2021-09-16 20:38:28 +00:00
|
|
|
api2 "openmediacenter/apiGo/api/api"
|
2021-09-06 18:20:33 +00:00
|
|
|
"openmediacenter/apiGo/config"
|
2021-02-23 16:01:29 +00:00
|
|
|
"openmediacenter/apiGo/database"
|
2022-05-05 19:32:35 +00:00
|
|
|
"openmediacenter/apiGo/housekeeping"
|
2021-04-02 17:04:15 +00:00
|
|
|
"openmediacenter/apiGo/static"
|
2021-04-18 19:16:38 +00:00
|
|
|
"openmediacenter/apiGo/videoparser"
|
2021-09-21 08:45:52 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2021-02-23 16:01:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
fmt.Println("init OpenMediaCenter server")
|
2021-09-21 08:45:52 +00:00
|
|
|
const port uint16 = 8081
|
2021-09-27 22:36:14 +00:00
|
|
|
errc := make(chan error, 1)
|
2021-02-23 16:01:29 +00:00
|
|
|
|
2022-05-05 19:32:35 +00:00
|
|
|
housekPTr := flag.Bool("HouseKeeping", false, "Run housekeeping tasks")
|
|
|
|
|
2021-09-06 18:20:33 +00:00
|
|
|
config.Init()
|
|
|
|
|
2021-09-09 21:33:04 +00:00
|
|
|
// todo some verbosity logger or sth
|
|
|
|
fmt.Printf("Use verbose output: %t\n", config.GetConfig().General.VerboseLogging)
|
|
|
|
fmt.Printf("Videopath prefix: %s\n", config.GetConfig().General.ReindexPrefix)
|
2021-02-23 16:01:29 +00:00
|
|
|
|
2021-09-27 22:36:14 +00:00
|
|
|
err := database.InitDB()
|
|
|
|
if err != nil {
|
|
|
|
errc <- err
|
|
|
|
}
|
2021-02-23 16:01:29 +00:00
|
|
|
defer database.Close()
|
|
|
|
|
2022-05-05 19:32:35 +00:00
|
|
|
// check if we should run the housekeeping tasks
|
|
|
|
if *housekPTr {
|
|
|
|
housekeeping.RunHouseKeepingTasks()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-21 08:45:52 +00:00
|
|
|
api.AddHandlers()
|
2021-02-23 16:01:29 +00:00
|
|
|
|
2021-04-18 19:16:38 +00:00
|
|
|
videoparser.SetupSettingsWebsocket()
|
2022-06-25 12:02:25 +00:00
|
|
|
videoparser.InitFileWatcher()
|
2021-04-18 19:16:38 +00:00
|
|
|
|
2021-04-02 17:04:15 +00:00
|
|
|
// add the static files
|
|
|
|
static.ServeStaticFiles()
|
|
|
|
|
2021-09-21 08:45:52 +00:00
|
|
|
// init api
|
|
|
|
go func() {
|
|
|
|
errc <- api2.ServerInit(port)
|
|
|
|
}()
|
|
|
|
|
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigs, os.Interrupt)
|
|
|
|
select {
|
|
|
|
case err := <-errc:
|
|
|
|
fmt.Printf("failed to serve: %v\n", err)
|
|
|
|
case sig := <-sigs:
|
|
|
|
fmt.Printf("terminating server: %v\n", sig)
|
|
|
|
}
|
2021-02-23 16:01:29 +00:00
|
|
|
}
|