organizer/main.go

40 lines
902 B
Go
Raw Normal View History

2023-01-13 19:23:36 +01:00
package main
import (
2023-01-15 15:55:47 +01:00
"os"
2023-01-13 20:04:57 +01:00
"os/exec"
"git.milar.in/milarin/channel"
2023-01-13 19:23:36 +01:00
"git.milar.in/nyaanime/logic"
"github.com/fsnotify/fsnotify"
)
func main() {
2023-01-13 20:04:57 +01:00
// check for ffprobe in PATH
if _, err := exec.LookPath("ffprobe"); err != nil {
panic(err) // TODO error handling
}
2023-01-13 19:23:36 +01:00
// get access token once at startup to be sure that an access token is obtainable at all
if _, err := logic.GetAnilistAccessToken(); err != nil {
panic(err) // TODO error handling
}
2023-01-14 12:11:10 +01:00
logic.PrintPriorityTables()
2023-01-13 19:23:36 +01:00
fsChan, err := WatchDirectory(fsnotify.Create, DownloadPath)
if err != nil {
panic(err) // TODO error handling
}
2023-01-14 12:11:10 +01:00
outputChan := channel.MapWithRunner(fsChan, InitializeRunner(), HandleFile)
2023-01-15 15:55:47 +01:00
channel.Each(outputChan, PrintByteChanFunc(os.Stdout))
2023-01-13 19:23:36 +01:00
}
2023-01-14 12:11:10 +01:00
func InitializeRunner() channel.Runner {
if ThreadCount <= 0 {
return channel.NewUnlimitedRunner()
}
return channel.NewLimitedRunner(ThreadCount)
}