Browse Source

Add parameter to disable index refreshing

master
PrivateGER 3 years ago
parent
commit
a5551a1fd8
Signed by: PrivateGER GPG Key ID: CAE625C962F94C67
  1. 13
      DirectoryIndexers/DirectoryIndexer.go
  2. 17
      main.go

13
DirectoryIndexers/DirectoryIndexer.go

@ -44,13 +44,18 @@ func Index(path string, results chan FileList, oldFileList *FileList) {
var wg sync.WaitGroup var wg sync.WaitGroup
bar := progressbar.NewOptions(len(fileList), bar := progressbar.NewOptions(len(fileList),
progressbar.OptionSetDescription("Scanning files + metadata..."),
progressbar.OptionShowCount(), progressbar.OptionShowCount(),
progressbar.OptionShowIts()) progressbar.OptionShowIts())
for _, video := range fileList { for _, video := range fileList {
wg.Add(1) wg.Add(1)
go func(video os.FileInfo) { go func(video os.FileInfo) {
if len(filepath.Ext(video.Name())) < 1 {
wg.Done()
_ = bar.Add(1)
return
}
extension := filepath.Ext(video.Name())[1:] extension := filepath.Ext(video.Name())[1:]
// check if extension is one of valid yt-dlp extensions, if not ignore file // check if extension is one of valid yt-dlp extensions, if not ignore file
switch extension { switch extension {
@ -79,6 +84,7 @@ func Index(path string, results chan FileList, oldFileList *FileList) {
oldFileList.RUnlock() oldFileList.RUnlock()
wg.Done() wg.Done()
_ = bar.Add(1)
return return
} }
@ -112,11 +118,12 @@ func Index(path string, results chan FileList, oldFileList *FileList) {
if !bar.IsFinished() { if !bar.IsFinished() {
_ = bar.Finish() _ = bar.Finish()
} }
_ = bar.Close()
fmt.Println("Finished scan.")
results <- FL results <- FL
close(results) close(results)
fmt.Println("\nArchive scan finished.")
} }
func filenameToID(filename string) string { func filenameToID(filename string) string {

17
main.go

@ -15,9 +15,17 @@ import (
func main() { func main() {
var path string 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 var port int
flag.IntVar(&port, "port", 8000, "the port for the web panel to listen on") 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() flag.Parse()
@ -35,9 +43,12 @@ func main() {
FL.Lock() FL.Lock()
FL.Files = refreshedFL.Files FL.Files = refreshedFL.Files
FL.Unlock() FL.Unlock()
fmt.Println("File list refreshed")
time.Sleep(60 * time.Second) if !autorefresh {
return
}
time.Sleep(time.Duration(refreshInterval) * time.Second)
} }
}() }()

Loading…
Cancel
Save