Add scanner status

This commit is contained in:
Deluan 2020-10-25 18:17:23 -04:00
parent c0ec0b28b9
commit af7eaa2b7a
5 changed files with 170 additions and 52 deletions

View file

@ -1,8 +1,11 @@
package cmd
import (
"time"
"github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/scanner"
"github.com/spf13/cobra"
)
@ -22,12 +25,23 @@ var scanCmd = &cobra.Command{
},
}
func waitScanToFinish(scanner scanner.Scanner) {
time.Sleep(500 * time.Millisecond)
ticker := time.Tick(100 * time.Millisecond)
for {
if !scanner.Scanning() {
return
}
<-ticker
}
}
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)
}
go func() { _ = scanner.Start(0) }()
scanner.RescanAll(fullRescan)
waitScanToFinish(scanner)
scanner.Stop()
if fullRescan {
log.Info("Finished full rescan")
} else {