mirror of
https://github.com/JackDallas/Premiumizearr.git
synced 2026-01-08 13:53:31 +01:00
Compare commits
2 Commits
download-h
...
v1.2.2-rc1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47efc229f9 | ||
|
|
b03a37bbd2 |
@@ -81,11 +81,9 @@ func loadConfigFromDisk(altConfigLocation string) (Config, error) {
|
||||
var config Config
|
||||
|
||||
log.Trace("Trying to load config from disk")
|
||||
|
||||
configLocation := path.Join(altConfigLocation, "config.yaml")
|
||||
|
||||
log.Tracef("Reading config from %s", configLocation)
|
||||
|
||||
file, err := ioutil.ReadFile(configLocation)
|
||||
|
||||
if err != nil {
|
||||
@@ -93,15 +91,41 @@ func loadConfigFromDisk(altConfigLocation string) (Config, error) {
|
||||
return config, ErrFailedToFindConfigFile
|
||||
}
|
||||
|
||||
log.Trace("Attempting to unmarshal config")
|
||||
err = yaml.Unmarshal(file, &config)
|
||||
log.Trace("Loading to interface")
|
||||
var configInterface map[interface{}]interface{}
|
||||
err = yaml.Unmarshal(file, &configInterface)
|
||||
if err != nil {
|
||||
log.Trace("Failed to unmarshal config")
|
||||
log.Errorf("Failed to unmarshal config file: %+v", err)
|
||||
return config, ErrInvalidConfigFile
|
||||
}
|
||||
|
||||
log.Trace("Config loaded, running version update")
|
||||
config, updated := versionUpdateConfig(config)
|
||||
log.Trace("Unmarshalling to struct")
|
||||
err = yaml.Unmarshal(file, &config)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to unmarshal config file: %+v", err)
|
||||
return config, ErrInvalidConfigFile
|
||||
}
|
||||
|
||||
log.Trace("Checking for missing config fields")
|
||||
updated := false
|
||||
|
||||
if configInterface["PollBlackholeDirectory"] == nil {
|
||||
log.Info("PollBlackholeDirectory not set, setting to false")
|
||||
config.PollBlackholeDirectory = false
|
||||
updated = true
|
||||
}
|
||||
|
||||
if configInterface["SimultaneousDownloads"] == nil {
|
||||
log.Info("SimultaneousDownloads not set, setting to 5")
|
||||
config.SimultaneousDownloads = 5
|
||||
updated = true
|
||||
}
|
||||
|
||||
if configInterface["PollBlackholeIntervalMinutes"] == nil {
|
||||
log.Info("PollBlackholeIntervalMinutes not set, setting to 10")
|
||||
config.PollBlackholeIntervalMinutes = 10
|
||||
updated = true
|
||||
}
|
||||
|
||||
config.altConfigLocation = altConfigLocation
|
||||
|
||||
@@ -123,17 +147,6 @@ func loadConfigFromDisk(altConfigLocation string) (Config, error) {
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func versionUpdateConfig(config Config) (Config, bool) {
|
||||
updated := false
|
||||
// 1.1.3
|
||||
if config.SimultaneousDownloads == 0 {
|
||||
config.SimultaneousDownloads = 5
|
||||
updated = true
|
||||
}
|
||||
|
||||
return config, updated
|
||||
}
|
||||
|
||||
func defaultConfig() Config {
|
||||
return Config{
|
||||
PremiumizemeAPIKey: "xxxxxxxxx",
|
||||
@@ -141,13 +154,15 @@ func defaultConfig() Config {
|
||||
{Name: "Sonarr", URL: "http://localhost:8989", APIKey: "xxxxxxxxx", Type: Sonarr},
|
||||
{Name: "Radarr", URL: "http://localhost:7878", APIKey: "xxxxxxxxx", Type: Radarr},
|
||||
},
|
||||
BlackholeDirectory: "",
|
||||
DownloadsDirectory: "",
|
||||
UnzipDirectory: "",
|
||||
BindIP: "0.0.0.0",
|
||||
BindPort: "8182",
|
||||
WebRoot: "",
|
||||
SimultaneousDownloads: 5,
|
||||
BlackholeDirectory: "",
|
||||
PollBlackholeDirectory: false,
|
||||
PollBlackholeIntervalMinutes: 10,
|
||||
DownloadsDirectory: "",
|
||||
UnzipDirectory: "",
|
||||
BindIP: "0.0.0.0",
|
||||
BindPort: "8182",
|
||||
WebRoot: "",
|
||||
SimultaneousDownloads: 5,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,10 @@ type Config struct {
|
||||
|
||||
Arrs []ArrConfig `yaml:"Arrs"`
|
||||
|
||||
BlackholeDirectory string `yaml:"BlackholeDirectory"`
|
||||
BlackholeDirectory string `yaml:"BlackholeDirectory"`
|
||||
PollBlackholeDirectory bool `yaml:"PollBlackholeDirectory"`
|
||||
PollBlackholeIntervalMinutes int `yaml:"PollBlackholeIntervalMinutes"`
|
||||
|
||||
DownloadsDirectory string `yaml:"DownloadsDirectory"`
|
||||
|
||||
UnzipDirectory string `yaml:"UnzipDirectory"`
|
||||
|
||||
@@ -48,7 +48,7 @@ func (dw *DirectoryWatcherService) ConfigUpdatedCallback(currentConfig config.Co
|
||||
if currentConfig.BlackholeDirectory != newConfig.BlackholeDirectory {
|
||||
log.Info("Blackhole directory changed, restarting directory watcher...")
|
||||
log.Info("Running initial directory scan...")
|
||||
go dw.initialDirectoryScan(dw.config.BlackholeDirectory)
|
||||
go dw.directoryScan(dw.config.BlackholeDirectory)
|
||||
dw.watchDirectory.UpdatePath(newConfig.BlackholeDirectory)
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func (dw *DirectoryWatcherService) Start() {
|
||||
go dw.processUploads()
|
||||
|
||||
log.Info("Running initial directory scan...")
|
||||
go dw.initialDirectoryScan(dw.config.BlackholeDirectory)
|
||||
go dw.directoryScan(dw.config.BlackholeDirectory)
|
||||
|
||||
// Build and start a DirectoryWatcher
|
||||
dw.watchDirectory = directory_watcher.NewDirectoryWatcher(dw.config.BlackholeDirectory,
|
||||
@@ -80,14 +80,24 @@ func (dw *DirectoryWatcherService) Start() {
|
||||
dw.addFileToQueue,
|
||||
)
|
||||
|
||||
dw.watchDirectory.Watch()
|
||||
if dw.config.PollBlackholeDirectory {
|
||||
log.Info("Starting directory poller...")
|
||||
for {
|
||||
time.Sleep(time.Duration(dw.config.PollBlackholeIntervalMinutes) * time.Minute)
|
||||
log.Info("Running directory scan of %s", dw.config.BlackholeDirectory)
|
||||
dw.directoryScan(dw.config.BlackholeDirectory)
|
||||
log.Infof("Scan complete, next scan in %d minutes", dw.config.PollBlackholeIntervalMinutes)
|
||||
}
|
||||
} else {
|
||||
dw.watchDirectory.Watch()
|
||||
}
|
||||
}
|
||||
|
||||
func (dw *DirectoryWatcherService) initialDirectoryScan(p string) {
|
||||
log.Trace("Initial directory scan")
|
||||
func (dw *DirectoryWatcherService) directoryScan(p string) {
|
||||
log.Trace("Running directory scan")
|
||||
files, err := ioutil.ReadDir(p)
|
||||
if err != nil {
|
||||
log.Errorf("Error with initial directory scan %+v", err)
|
||||
log.Errorf("Error with directory scan %+v", err)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
@@ -110,7 +120,7 @@ func (dw *DirectoryWatcherService) checkFile(path string) bool {
|
||||
}
|
||||
|
||||
if fi.IsDir() {
|
||||
log.Errorf("Directory created in blackhole %s ignoring (Warning premiumizearrzed does not look in subfolders!)", path)
|
||||
log.Errorf("Directory created in blackhole %s ignoring (Warning premiumizearrd does not look in subfolders!)", path)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user