From 8e7caa715fda17bb13e276f6889109ba6033d4d9 Mon Sep 17 00:00:00 2001 From: Brian Doherty Date: Sat, 5 Nov 2022 11:20:01 -0500 Subject: [PATCH] Added option to scan at startup. --- README.md | 3 ++- cmd/gonic/gonic.go | 5 +++++ server/server.go | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f3c464d..dae45f32 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,8 @@ view the admin UI at http://localhost:4747 | `GONIC_TLS_KEY` | `-tls-key` | **optional** path to a TLS key (enables HTTPS listening) | | `GONIC_PROXY_PREFIX` | `-proxy-prefix` | **optional** url path prefix to use if behind reverse proxy. eg `/gonic` (see example configs below) | | `GONIC_SCAN_INTERVAL` | `-scan-interval` | **optional** interval (in minutes) to check for new music (automatic scanning disabled if omitted) | -| `GONIC_SCAN_WATCHER ` | `-scan-watcher-enabled` | **optional** whether to watch file system for new music and rescan | +| `GONIC_SCAN_AT_START_ENABLED` | `-scan-at-start-enabled` | **optional** whether to perform an initial scan at startup | +| `GONIC_SCAN_WATCHER_ENABLED ` | `-scan-watcher-enabled` | **optional** whether to watch file system for new music and rescan | | `GONIC_JUKEBOX_ENABLED` | `-jukebox-enabled` | **optional** whether the subsonic [jukebox api](https://airsonic.github.io/docs/jukebox/) should be enabled | | `GONIC_GENRE_SPLIT` | `-genre-split` | **optional** a string or character to split genre tags on for multi-genre support (eg. `;`) | diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index 39aecb7e..3805cc3d 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -1,4 +1,5 @@ // Package main is the gonic server entrypoint +// //nolint:lll // flags help strings package main @@ -36,6 +37,7 @@ func main() { confCachePath := set.String("cache-path", "", "path to cache") confDBPath := set.String("db-path", "gonic.db", "path to database (optional)") confScanInterval := set.Int("scan-interval", 0, "interval (in minutes) to automatically scan music (optional)") + confScanAtStart := set.Bool("scan-at-start-enabled", false, "whether to perform an initial scan at startup") confScanWatcher := set.Bool("scan-watcher-enabled", false, "whether to watch file system for new music and rescan (optional)") confJukeboxEnabled := set.Bool("jukebox-enabled", false, "whether the subsonic jukebox api should be enabled (optional)") confProxyPrefix := set.String("proxy-prefix", "", "url path prefix to use if behind proxy. eg '/gonic' (optional)") @@ -141,6 +143,9 @@ func main() { if *confJukeboxEnabled { g.Add(server.StartJukebox()) } + if *confScanAtStart { + server.ScanAtStart() + } if err := g.Run(); err != nil { log.Panicf("error in job: %v", err) diff --git a/server/server.go b/server/server.go index 1aa06725..8e078546 100644 --- a/server/server.go +++ b/server/server.go @@ -344,6 +344,12 @@ func (s *Server) StartScanTicker(dur time.Duration) (FuncExecute, FuncInterrupt) } } +func (s *Server) ScanAtStart() { + if _, err := s.scanner.ScanAndClean(scanner.ScanOptions{}); err != nil { + log.Printf("error scanning: %v", err) + } +} + func (s *Server) StartScanWatcher() (FuncExecute, FuncInterrupt) { return func() error { log.Printf("starting job 'scan watcher'\n")