|
@ -6,6 +6,8 @@ import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"os" |
|
|
"os" |
|
|
|
|
|
"strconv" |
|
|
|
|
|
"sync" |
|
|
"time" |
|
|
"time" |
|
|
"ytdlp-viewer/DirectoryIndexers" |
|
|
"ytdlp-viewer/DirectoryIndexers" |
|
|
"ytdlp-viewer/PageHandlers" |
|
|
"ytdlp-viewer/PageHandlers" |
|
@ -14,10 +16,14 @@ 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 (with a / suffix)") |
|
|
|
|
|
var port int |
|
|
|
|
|
flag.IntVar(&port, "port", 8000, "the port for the web panel to listen on") |
|
|
|
|
|
|
|
|
flag.Parse() |
|
|
flag.Parse() |
|
|
|
|
|
|
|
|
var FL DirectoryIndexers.FileList |
|
|
var FL DirectoryIndexers.FileList |
|
|
|
|
|
FL.RWMutex = &sync.RWMutex{} |
|
|
|
|
|
|
|
|
go func() { |
|
|
go func() { |
|
|
for { |
|
|
for { |
|
|
resultChannel := make(chan DirectoryIndexers.FileList) |
|
|
resultChannel := make(chan DirectoryIndexers.FileList) |
|
@ -25,7 +31,11 @@ func main() { |
|
|
fmt.Println("Starting scanner at", path) |
|
|
fmt.Println("Starting scanner at", path) |
|
|
go DirectoryIndexers.Index(path, resultChannel) |
|
|
go DirectoryIndexers.Index(path, resultChannel) |
|
|
|
|
|
|
|
|
FL = <-resultChannel |
|
|
refreshedFL := <-resultChannel |
|
|
|
|
|
FL.Lock() |
|
|
|
|
|
FL.Files = refreshedFL.Files |
|
|
|
|
|
FL.Unlock() |
|
|
|
|
|
|
|
|
time.Sleep(60 * time.Second) |
|
|
time.Sleep(60 * time.Second) |
|
|
} |
|
|
} |
|
|
}() |
|
|
}() |
|
@ -44,7 +54,7 @@ func main() { |
|
|
}) |
|
|
}) |
|
|
http.Handle("/videos/", http.StripPrefix("/videos/", http.FileServer(http.Dir(path)))) |
|
|
http.Handle("/videos/", http.StripPrefix("/videos/", http.FileServer(http.Dir(path)))) |
|
|
|
|
|
|
|
|
err := http.ListenAndServe(":8000", nil) |
|
|
err := http.ListenAndServe(":" + strconv.Itoa(port), nil) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println(err) |
|
|
fmt.Println(err) |
|
|
os.Exit(1) |
|
|
os.Exit(1) |
|
|