66 "encoding/json"
77 "fmt"
88 "github.com/aetaric/checkrr/logging"
9+ "github.com/knadh/koanf/v2"
910 "net/http"
1011 "os"
1112 "path/filepath"
@@ -20,7 +21,6 @@ import (
2021 "github.com/h2non/filetype/matchers"
2122 "github.com/kalafut/imohash"
2223 log "github.com/sirupsen/logrus"
23- "github.com/spf13/viper"
2424 bolt "go.etcd.io/bbolt"
2525 "gopkg.in/vansante/go-ffprobe.v2"
2626)
@@ -40,8 +40,8 @@ type Checkrr struct {
4040 removeAudio []string
4141 removeLang []string
4242 ignoreHidden bool
43- config * viper. Viper
44- FullConfig * viper. Viper
43+ FullConfig * koanf. Koanf
44+ config * koanf. Koanf
4545 Chan * chan []string
4646 Logger * logging.Log
4747}
@@ -58,10 +58,7 @@ func (c *Checkrr) Run() {
5858 }
5959
6060 c .Stats = features.Stats {Log : * c .Logger , DB : c .DB }
61-
62- if c .FullConfig .Sub ("stats" ) != nil {
63- c .Stats .FromConfig (* c .FullConfig .Sub ("stats" ))
64- }
61+ c .Stats .FromConfig (* c .FullConfig .Cut ("stats" ))
6562
6663 // Connect to Sonarr, Radarr, and Lidarr
6764 c .connectServices ()
@@ -70,17 +67,17 @@ func (c *Checkrr) Run() {
7067 c .connectNotifications ()
7168
7269 // Setup CSV writer
73- if c .config .GetString ("csvfile" ) != "" {
74- c .csv = features.CSV {FilePath : c .config .GetString ("csvfile" ), Log : c .Logger }
70+ if c .config .String ("csvfile" ) != "" {
71+ c .csv = features.CSV {FilePath : c .config .String ("csvfile" ), Log : c .Logger }
7572 c .csv .Open ()
7673 }
7774
78- c .ignoreExts = c .config .GetStringSlice ("ignoreexts" )
79- c .ignorePaths = c .config .GetStringSlice ("ignorepaths" )
80- c .removeVideo = c .config .GetStringSlice ("removevideo" )
81- c .removeAudio = c .config .GetStringSlice ("removeaudio" )
82- c .removeLang = c .config .GetStringSlice ("removelang" )
83- c .ignoreHidden = c .config .GetBool ("ignorehidden" )
75+ c .ignoreExts = c .config .Strings ("ignoreexts" )
76+ c .ignorePaths = c .config .Strings ("ignorepaths" )
77+ c .removeVideo = c .config .Strings ("removevideo" )
78+ c .removeAudio = c .config .Strings ("removeaudio" )
79+ c .removeLang = c .config .Strings ("removelang" )
80+ c .ignoreHidden = c .config .Bool ("ignorehidden" )
8481
8582 // I'm tired of waiting for filetype to support this. We'll force it by adding to the matchers on the fly.
8683 // TODO: if h2non/filetype#120 ever gets completed, remove this logic
@@ -91,9 +88,9 @@ func (c *Checkrr) Run() {
9188
9289 c .Stats .Start ()
9390
94- c .Logger .Debug (c .config .GetStringSlice ("checkpath" ))
91+ c .Logger .Debug (c .config .Strings ("checkpath" ))
9592
96- for _ , path := range c .config .GetStringSlice ("checkpath" ) {
93+ for _ , path := range c .config .Strings ("checkpath" ) {
9794 c .Logger .WithFields (log.Fields {"startup" : true }).Debugf ("Path: %v" , path )
9895
9996 err := filepath .WalkDir (path , func (path string , d os.DirEntry , err error ) error {
@@ -184,20 +181,20 @@ func (c *Checkrr) Run() {
184181 ch <- []string {"time" }
185182}
186183
187- func (c * Checkrr ) FromConfig (conf * viper. Viper ) {
184+ func (c * Checkrr ) FromConfig (conf * koanf. Koanf ) {
188185 c .config = conf
189186}
190187
191188func (c * Checkrr ) connectServices () {
192- if viper . GetViper (). Sub ("arr" ) != nil {
193- arrConfig := viper . GetViper (). Sub ("arr" )
194- arrKeys := viper . GetViper (). Sub ("arr" ).AllKeys ()
189+ if c . FullConfig . Get ("arr" ) != nil {
190+ arrConfig := c . config . Cut ("arr" )
191+ arrKeys := c . config . Cut ("arr" ).Keys ()
195192 for _ , key := range arrKeys {
196193 if strings .Contains (key , "service" ) {
197194 k := strings .Split (key , "." )[0 ]
198- config := arrConfig .Sub (k )
195+ config := arrConfig .Cut (k )
199196
200- if config .GetString ("service" ) == "sonarr" {
197+ if config .String ("service" ) == "sonarr" {
201198 sonarr := connections.Sonarr {Log : c .Logger }
202199 sonarr .FromConfig (config )
203200 sonarrConnected , sonarrMessage := sonarr .Connect ()
@@ -207,7 +204,7 @@ func (c *Checkrr) connectServices() {
207204 }
208205 }
209206
210- if config .GetString ("service" ) == "radarr" {
207+ if config .String ("service" ) == "radarr" {
211208 radarr := connections.Radarr {Log : c .Logger }
212209 radarr .FromConfig (config )
213210 radarrConnected , radarrMessage := radarr .Connect ()
@@ -217,7 +214,7 @@ func (c *Checkrr) connectServices() {
217214 }
218215 }
219216
220- if config .GetString ("service" ) == "lidarr" {
217+ if config .String ("service" ) == "lidarr" {
221218 lidarr := connections.Lidarr {Log : c .Logger }
222219 lidarr .FromConfig (config )
223220 lidarrConnected , lidarrMessage := lidarr .Connect ()
@@ -232,9 +229,9 @@ func (c *Checkrr) connectServices() {
232229}
233230
234231func (c * Checkrr ) connectNotifications () {
235- if viper . GetViper (). Sub ("notifications" ) != nil {
232+ if c . FullConfig . Cut ("notifications" ) != nil {
236233 c .notifications = notifications.Notifications {Log : c .Logger }
237- c .notifications .FromConfig (* viper . GetViper (). Sub ("notifications" ))
234+ c .notifications .FromConfig (c . config . Cut ("notifications" ))
238235 c .notifications .Connect ()
239236 } else {
240237 c .Logger .WithFields (log.Fields {"Startup" : true , "Notifications Connected" : false }).Warn ("No config options for notifications found." )
@@ -434,7 +431,7 @@ func (c *Checkrr) recordBadFile(path string, fileType string, reason string) {
434431 c .Logger .WithFields (log.Fields {"DB Update" : "Failure" }).Warnf ("Error: %v" , err .Error ())
435432 }
436433
437- if c .config .GetString ("csvfile" ) != "" {
434+ if c .config .String ("csvfile" ) != "" {
438435 c .csv .Write (path , fileType )
439436 }
440437}
0 commit comments