45 lines
978 B
Go
45 lines
978 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"git.milar.in/milarin/channel"
|
|
"git.milar.in/nyaanime/logic"
|
|
"github.com/fsnotify/fsnotify"
|
|
)
|
|
|
|
func main() {
|
|
// check for ffprobe in PATH
|
|
if _, err := exec.LookPath("ffprobe"); err != nil {
|
|
panic(err) // TODO error handling
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
logic.PrintPriorityTables()
|
|
|
|
fsChan, err := WatchDirectory(fsnotify.Create, DownloadPath)
|
|
if err != nil {
|
|
panic(err) // TODO error handling
|
|
}
|
|
|
|
outputChan := channel.MapWithRunner(fsChan, InitializeRunner(), HandleFile)
|
|
channel.Each(outputChan, PrintStringBuilder)
|
|
}
|
|
|
|
func PrintStringBuilder(b *strings.Builder) {
|
|
fmt.Println(b.String())
|
|
}
|
|
|
|
func InitializeRunner() channel.Runner {
|
|
if ThreadCount <= 0 {
|
|
return channel.NewUnlimitedRunner()
|
|
}
|
|
return channel.NewLimitedRunner(ThreadCount)
|
|
}
|