Add scan command

This commit is contained in:
Deluan 2020-07-02 20:08:41 -04:00 committed by Deluan Quintão
parent 8181aba61f
commit 3a7d70c908
4 changed files with 61 additions and 4 deletions

36
cmd/scan.go Normal file
View file

@ -0,0 +1,36 @@
package cmd
import (
"github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/log"
"github.com/spf13/cobra"
)
var fullRescan bool
func init() {
scanCmd.Flags().BoolVarP(&fullRescan, "full", "f", false, "check all subfolders, ignoring timestamps")
rootCmd.AddCommand(scanCmd)
}
var scanCmd = &cobra.Command{
Use: "scan",
Short: "Scan music folder",
Long: "Scan music folder for updates",
Run: func(cmd *cobra.Command, args []string) {
runScanner()
},
}
func runScanner() {
scanner := CreateScanner(conf.Server.MusicFolder)
err := scanner.RescanAll(fullRescan)
if err != nil {
log.Error("Error scanning media folder", "folder", conf.Server.MusicFolder, err)
}
if fullRescan {
log.Info("Finished full rescan")
} else {
log.Info("Finished rescan")
}
}