organizer/main.go

45 lines
1005 B
Go
Raw Normal View History

2023-01-13 19:23:36 +01:00
package main
import (
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"
)
2023-01-15 19:43:36 +01:00
var Runner = InitializeRunner()
2023-01-13 19:23:36 +01:00
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-15 21:09:26 +01:00
if err := InitTelegramBot(); err != nil {
panic(err) // TODO error handling
}
2023-01-14 12:11:10 +01:00
logic.PrintPriorityTables()
2023-01-15 19:43:36 +01:00
fileChan, err := WatchDirectory(fsnotify.Create, DownloadPath)
2023-01-13 19:23:36 +01:00
if err != nil {
panic(err) // TODO error handling
}
2023-01-15 19:43:36 +01:00
fileHandleChan := channel.Map(fileChan, NewFileHandle)
workChan, logChan := channel.Tee(fileHandleChan)
go channel.Each(workChan, HandleFileInRunner)
channel.Each(logChan, PrintFileHandle)
2023-01-13 19:23:36 +01:00
}
2023-01-14 12:11:10 +01:00
2023-01-15 19:43:36 +01:00
func HandleFileInRunner(fh *FileHandle) {
Runner.Run(func() { HandleFile(fh) })
2023-01-14 12:11:10 +01:00
}