-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (44 loc) · 1.65 KB
/
main.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
package main
import (
"fmt"
"log"
"time"
"net/http"
"github.com/danstis/Plex-Sync/config"
"github.com/danstis/Plex-Sync/logger"
"github.com/danstis/Plex-Sync/plex"
"github.com/danstis/Plex-Sync/web"
"github.com/gorilla/handlers"
)
func main() {
log.Printf("Plex-Sync v%v", plex.Version)
settings, err := config.GetConfig()
if err != nil {
log.Fatal(err)
return
}
plex.CacheLifetime = settings.CacheLifetime
r := web.NewRouter()
loggedRouter := handlers.LoggingHandler(logger.CreateLogger("logs/plex-sync-webserver.log", settings.Logging.MaxLogSize, settings.Logging.MaxLogCount, settings.Logging.MaxLogAge), r)
go http.ListenAndServe(fmt.Sprintf(":%v", settings.WebServerPort), loggedRouter)
log.Printf("Started webserver http://localhost:%v", settings.WebServerPort)
log.SetOutput(logger.CreateLogger("logs/plex-sync.log", settings.Logging.MaxLogSize, settings.Logging.MaxLogCount, settings.Logging.MaxLogAge))
for settings.LocalServer.Hostname == "" || settings.RemoteServer.Hostname == "" {
log.Printf("No local or remote server defined. Please populate the server settings in the WebInterface.")
time.Sleep(time.Duration(settings.SyncInterval) * time.Second)
}
for {
token := plex.Token()
if token != "" {
if err := settings.LocalServer.GetToken(token); err != nil {
log.Printf("ERROR: %v", err)
}
if err := settings.RemoteServer.GetToken(token); err != nil {
log.Printf("ERROR: %v", err)
}
plex.SyncWatchedTv(settings.LocalServer, settings.RemoteServer)
}
log.Printf("Sleeping for %v...", time.Duration(settings.SyncInterval)*time.Second)
time.Sleep(time.Duration(settings.SyncInterval) * time.Second)
}
}