organizer/main.go

58 lines
1.4 KiB
Go
Raw Normal View History

2023-01-13 19:23:36 +01:00
package main
import (
"os"
2023-01-13 20:04:57 +01:00
"os/exec"
"time"
2023-01-13 20:04:57 +01:00
"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
}
//anime := adverr.Must(logic.SearchAnimeByTitle("トモちゃんは女の子!"))
//animeEp1 := model.AnimeEpisode{Anime: anime, Episode: 2}
//animeEp2 := model.AnimeEpisode{Anime: anime, Episode: 3}
//animeEp3 := model.AnimeEpisode{Anime: anime, Episode: 4}
//PrepareTelegramAnimeEpMessage(animeEp1)
//PrepareTelegramAnimeEpMessage(animeEp2)
//PrepareTelegramAnimeEpMessage(animeEp3)
time.Sleep(time.Minute)
os.Exit(0)
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
}