2023-01-13 19:23:36 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/user"
|
2023-01-14 12:11:10 +01:00
|
|
|
"runtime"
|
2023-01-13 19:23:36 +01:00
|
|
|
"strconv"
|
2023-01-15 21:09:26 +01:00
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"git.milar.in/nyaanime/logic"
|
2023-01-13 19:23:36 +01:00
|
|
|
|
|
|
|
"git.milar.in/milarin/envvars/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-01-15 21:09:26 +01:00
|
|
|
DownloadPath = envvars.String("DOWNLOAD_PATH", "")
|
|
|
|
ThreadCount = envvars.Int("THREADS", runtime.NumCPU())
|
2023-01-15 13:59:48 +01:00
|
|
|
DeleteLowPriorityFiles = envvars.Bool("DELETE_LOW_PRIORITY_FILES", false)
|
|
|
|
|
2023-01-18 10:59:48 +01:00
|
|
|
TelegramBotToken = envvars.String("TELEGRAM_API_TOKEN", "")
|
|
|
|
TelegramChatID = envvars.Int64("TELEGRAM_CHAT_ID", 0)
|
2023-01-22 13:40:42 +01:00
|
|
|
TelegramOrganizeMessagePatternStr = logic.EscSeqReplacer.Replace(envvars.String("TELEGRAM_ORGANIZE_MESSAGE_PATTERN", `<u><b>Recently Downloaded Animes ({{len .}} eps)</b></u>{{range .}}\n{{.Anime.Title.UserPreferred}} Episode {{.Episode}}{{end}}`))
|
2023-01-18 10:59:48 +01:00
|
|
|
TelegramOrganizeMessagePattern = template.Must(template.New("TELEGRAM_ORGANIZE_MESSAGE_PATTERN").Parse(TelegramOrganizeMessagePatternStr))
|
|
|
|
TelegramOrganizeMessageSendCondition = envvars.ObjectSlice("TELEGRAM_ORGANIZE_MESSAGE_SEND_CONDITION", ",", []SendCondition{SendConditionAlways}, SendConditionFromString)
|
2023-01-18 11:33:00 +01:00
|
|
|
TelegramOrganizeMessageSendInterval = envvars.Duration("TELEGRAM_ORGANIZE_MESSAGE_SEND_INTERVAL", 0)
|
2023-01-19 10:16:43 +01:00
|
|
|
TelegramOrganizeMessageSendOffset = envvars.Duration("TELEGRAM_ORGANIZE_MESSAGE_SEND_OFFSET", 0)
|
2023-01-15 21:09:26 +01:00
|
|
|
|
2023-01-13 19:23:36 +01:00
|
|
|
Uid = envvars.Object("UID", 1000, func(s string) (int, error) {
|
|
|
|
if uid, err := strconv.Atoi(s); err == nil {
|
|
|
|
return uid, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
usr, err := user.Lookup(s)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return strconv.Atoi(usr.Uid)
|
|
|
|
})
|
|
|
|
|
|
|
|
Gid = envvars.Object("GID", 1000, func(s string) (int, error) {
|
|
|
|
if gid, err := strconv.Atoi(s); err == nil {
|
|
|
|
return gid, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
grp, err := user.LookupGroup(s)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return strconv.Atoi(grp.Gid)
|
|
|
|
})
|
|
|
|
)
|