2022-08-15 15:55:27 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.milar.in/milarin/adverr"
|
2022-08-18 14:25:37 +02:00
|
|
|
"git.milar.in/milarin/anilist"
|
2022-08-15 15:55:27 +02:00
|
|
|
"git.milar.in/milarin/envvars"
|
2022-08-15 16:45:52 +02:00
|
|
|
"git.milar.in/nyaanime/model"
|
2022-08-15 15:55:27 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
PollRate = envvars.Object("POLL_RATE", 30*time.Minute, time.ParseDuration)
|
|
|
|
|
|
|
|
AnilistUsername = envvars.String("ANILIST_USERNAME", "username")
|
|
|
|
AnilistAccessToken = envvars.String("ANILIST_TOKEN", "")
|
|
|
|
|
|
|
|
StoragePath = envvars.String("STORAGE_PATH", "")
|
|
|
|
StorageUser = envvars.String("STORAGE_USER", "")
|
|
|
|
StoragePass = envvars.String("STORAGE_PASS", "")
|
|
|
|
|
2022-08-18 14:25:37 +02:00
|
|
|
AnimeStatus = envvars.ObjectSlice("ANIME_STATUS", ",", ParseMediaListStatus)
|
|
|
|
|
2022-08-15 15:55:27 +02:00
|
|
|
// essential torrent properties
|
|
|
|
|
|
|
|
MaxResolution = envvars.Object("MAX_RESOLUTION", model.Resolution4K, model.ParseResolution)
|
|
|
|
MinResolution = envvars.Object("MIN_RESOLUTION", model.ResolutionHD, model.ParseResolution)
|
|
|
|
|
|
|
|
EssentialLanguages = envvars.StringSlice("ESSENTIAL_LANGUAGES", ",")
|
|
|
|
EssentialSubtitles = envvars.StringSlice("ESSENTIAL_SUBTITLES", ",")
|
|
|
|
|
|
|
|
MaxSeeders = envvars.Int("MAX_SEEDERS", math.MaxInt)
|
|
|
|
MinSeeders = envvars.Int("MIN_SEEDERS", 0)
|
|
|
|
|
|
|
|
MaxLeechers = envvars.Int("MAX_LEECHERS", math.MaxInt)
|
|
|
|
MinLeechers = envvars.Int("MIN_LEECHERS", 0)
|
|
|
|
|
|
|
|
MaxDownloads = envvars.Int("MAX_DOWNLOADS", math.MaxInt)
|
|
|
|
MinDownloads = envvars.Int("MIN_DOWNLOADS", 0)
|
|
|
|
|
|
|
|
TrustedOnly = envvars.Bool("TRUSTED_ONLY", false)
|
|
|
|
|
|
|
|
// preferred torrent properties
|
|
|
|
|
|
|
|
PreferredLanguages = envvars.StringSlice("PREFERRED_LANGUAGES", ",")
|
|
|
|
PreferredSubtitles = envvars.StringSlice("PREFERRED_SUBTITLES", ",")
|
|
|
|
|
|
|
|
/*
|
|
|
|
TODO
|
|
|
|
|
|
|
|
PreferMoreLanguages = envvars.Bool("PREFERER_MORE_LANGUAGES", false)
|
|
|
|
PreferMoreSubtitles = envvars.Bool("PREFERER_MORE_SUBTITLES", false)
|
|
|
|
*/
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-08-18 14:25:37 +02:00
|
|
|
if len(AnimeStatus) == 0 {
|
|
|
|
AnimeStatus = []anilist.MediaListStatus{
|
|
|
|
anilist.MediaListStatusCurrent,
|
|
|
|
anilist.MediaListStatusPlanning,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-15 15:55:27 +02:00
|
|
|
// get access token once at startup to be sure that an access token is obtainable at all
|
|
|
|
if _, err := GetAnilistAccessToken(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ticker := time.NewTicker(PollRate)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
checkTorrents()
|
|
|
|
for range ticker.C {
|
|
|
|
checkTorrents()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkTorrents() {
|
2022-08-15 16:15:20 +02:00
|
|
|
fmt.Println("checking torrents")
|
|
|
|
start := time.Now()
|
2022-08-15 15:55:27 +02:00
|
|
|
|
|
|
|
torrents, err := GetLatestNyaaContent()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(adverr.Wrap("retrieving torrents failed", err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-18 14:25:37 +02:00
|
|
|
_, err = GetCurrentlyWatchingAnimesByAnimeID()
|
2022-08-15 15:55:27 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(adverr.Wrap("retrieving anime list failed", err))
|
|
|
|
return
|
2022-08-18 14:25:37 +02:00
|
|
|
}
|
2022-08-15 15:55:27 +02:00
|
|
|
|
|
|
|
parsedTorrentsByAnimeEp := FilterEssentialTorrents(ParseTorrentsByAnimeEp(torrents))
|
|
|
|
|
|
|
|
for _, parsedTorrents := range parsedTorrentsByAnimeEp {
|
|
|
|
for _, parsedTorrent := range parsedTorrents {
|
|
|
|
fmt.Println(parsedTorrent, "|", parsedTorrent.Torrent.StringWithoutTitle())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-15 16:15:20 +02:00
|
|
|
duration := time.Since(start)
|
|
|
|
fmt.Printf("check took %s. sleeping for %s\n", duration, PollRate-duration)
|
2022-08-15 15:55:27 +02:00
|
|
|
}
|