2021-02-23 16:01:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2021-04-02 17:04:15 +00:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2021-02-23 16:01:29 +00:00
|
|
|
"openmediacenter/apiGo/api"
|
|
|
|
"openmediacenter/apiGo/database"
|
2021-04-02 17:04:15 +00:00
|
|
|
"openmediacenter/apiGo/static"
|
2021-02-23 16:01:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
fmt.Println("init OpenMediaCenter server")
|
2021-04-02 17:04:15 +00:00
|
|
|
port := 8081
|
2021-02-23 16:01:29 +00:00
|
|
|
|
|
|
|
db, verbose, pathPrefix := handleCommandLineArguments()
|
|
|
|
// todo some verbosity logger or sth
|
|
|
|
|
|
|
|
fmt.Printf("Use verbose output: %t\n", verbose)
|
|
|
|
fmt.Printf("Videopath prefix: %s\n", *pathPrefix)
|
|
|
|
|
|
|
|
// set pathprefix in database settings object
|
|
|
|
database.SettingsVideoPrefix = *pathPrefix
|
|
|
|
|
|
|
|
database.InitDB(db)
|
|
|
|
defer database.Close()
|
|
|
|
|
|
|
|
api.AddVideoHandlers()
|
|
|
|
api.AddSettingsHandlers()
|
|
|
|
api.AddTagHandlers()
|
|
|
|
api.AddActorsHandlers()
|
|
|
|
|
2021-04-02 17:04:15 +00:00
|
|
|
// add the static files
|
|
|
|
static.ServeStaticFiles()
|
|
|
|
|
|
|
|
api.ServerInit()
|
|
|
|
|
|
|
|
fmt.Printf("OpenMediacenter server up and running on port %d\n", port)
|
|
|
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
|
2021-02-23 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func handleCommandLineArguments() (*database.DatabaseConfig, bool, *string) {
|
|
|
|
dbhostPtr := flag.String("DBHost", "127.0.0.1", "database host name")
|
|
|
|
dbPortPtr := flag.Int("DBPort", 3306, "database port")
|
|
|
|
dbUserPtr := flag.String("DBUser", "mediacenteruser", "database username")
|
|
|
|
dbPassPtr := flag.String("DBPassword", "mediapassword", "database username")
|
|
|
|
dbNamePtr := flag.String("DBName", "mediacenter", "database name")
|
|
|
|
|
|
|
|
verbosePtr := flag.Bool("v", true, "Verbose log output")
|
|
|
|
|
|
|
|
pathPrefix := flag.String("ReindexPrefix", "/var/www/openmediacenter", "Prefix path for videos to reindex")
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
return &database.DatabaseConfig{
|
|
|
|
DBHost: *dbhostPtr,
|
|
|
|
DBPort: *dbPortPtr,
|
|
|
|
DBUser: *dbUserPtr,
|
|
|
|
DBPassword: *dbPassPtr,
|
|
|
|
DBName: *dbNamePtr,
|
|
|
|
}, *verbosePtr, pathPrefix
|
|
|
|
}
|