From a5551a1fd8681efa42545799d18f52ce42e12228 Mon Sep 17 00:00:00 2001 From: PrivateGER Date: Mon, 18 Oct 2021 19:22:29 +0200 Subject: [PATCH] Add parameter to disable index refreshing --- DirectoryIndexers/DirectoryIndexer.go | 13 ++++++++++--- main.go | 17 ++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) 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) } }()