mirror of
https://github.com/5rahim/seanime
synced 2026-05-02 22:42:11 +02:00
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package core
|
|
|
|
import (
|
|
"github.com/dustin/go-humanize"
|
|
"seanime/internal/library/scanner"
|
|
"seanime/internal/util"
|
|
)
|
|
|
|
// initLibraryWatcher will initialize the library watcher.
|
|
// - Used by AutoScanner
|
|
func (a *App) initLibraryWatcher(path string) {
|
|
// Create a new watcher
|
|
watcher, err := scanner.NewWatcher(&scanner.NewWatcherOptions{
|
|
Logger: a.Logger,
|
|
WSEventManager: a.WSEventManager,
|
|
})
|
|
if err != nil {
|
|
a.Logger.Error().Err(err).Msg("app: Failed to initialize watcher")
|
|
return
|
|
}
|
|
|
|
// Initialize library file watcher
|
|
err = watcher.InitLibraryFileWatcher(&scanner.WatchLibraryFilesOptions{
|
|
LibraryPath: path,
|
|
})
|
|
if err != nil {
|
|
a.Logger.Error().Err(err).Msg("app: Failed to watch library files")
|
|
return
|
|
}
|
|
|
|
dirSize, _ := util.DirSize(path)
|
|
a.TotalLibrarySize = dirSize
|
|
|
|
a.Logger.Info().Msgf("watcher: Library size: %s", humanize.Bytes(dirSize))
|
|
|
|
// Set the watcher
|
|
a.Watcher = watcher
|
|
|
|
// Start watching
|
|
a.Watcher.StartWatching(
|
|
func() {
|
|
// Notify the auto scanner when a file action occurs
|
|
a.AutoScanner.Notify()
|
|
})
|
|
|
|
}
|