diff --git a/DirectoryIndexers/DirectoryIndexer.go b/DirectoryIndexers/DirectoryIndexer.go index 5e4ad38..699a585 100644 --- a/DirectoryIndexers/DirectoryIndexer.go +++ b/DirectoryIndexers/DirectoryIndexer.go @@ -44,13 +44,18 @@ func Index(path string, results chan FileList, oldFileList *FileList) { var wg sync.WaitGroup bar := progressbar.NewOptions(len(fileList), - progressbar.OptionSetDescription("Scanning files + metadata..."), progressbar.OptionShowCount(), progressbar.OptionShowIts()) for _, video := range fileList { wg.Add(1) go func(video os.FileInfo) { + if len(filepath.Ext(video.Name())) < 1 { + wg.Done() + _ = bar.Add(1) + return + } + extension := filepath.Ext(video.Name())[1:] // check if extension is one of valid yt-dlp extensions, if not ignore file switch extension { @@ -79,6 +84,7 @@ func Index(path string, results chan FileList, oldFileList *FileList) { oldFileList.RUnlock() wg.Done() + _ = bar.Add(1) return } @@ -112,11 +118,12 @@ func Index(path string, results chan FileList, oldFileList *FileList) { if !bar.IsFinished() { _ = bar.Finish() } + _ = bar.Close() + + fmt.Println("Finished scan.") results <- FL close(results) - - fmt.Println("\nArchive scan finished.") } func filenameToID(filename string) string { diff --git a/main.go b/main.go index 70e32d1..353e1ce 100644 --- a/main.go +++ b/main.go @@ -15,9 +15,17 @@ import ( func main() { var path string - flag.StringVar(&path, "path", "./", "the full path to the ytdlp archive (with a / suffix)") + flag.StringVar(&path, "path", "./", "the full path to the ytdlp archive") + // append last slash in case it's not provided + if path[len(path)-1:] != "/" { + path += "/" + } var port int flag.IntVar(&port, "port", 8000, "the port for the web panel to listen on") + var autorefresh bool + flag.BoolVar(&autorefresh, "refresh", false, "whether should the index be updated every x seconds") + var refreshInterval int + flag.IntVar(&refreshInterval, "interval", 60, "the interval for the index to update in seconds") flag.Parse() @@ -35,9 +43,12 @@ func main() { FL.Lock() FL.Files = refreshedFL.Files FL.Unlock() - fmt.Println("File list refreshed") - time.Sleep(60 * time.Second) + if !autorefresh { + return + } + + time.Sleep(time.Duration(refreshInterval) * time.Second) } }()