ANIME_STATUS introduced

This commit is contained in:
Timon Ringwald 2022-08-18 14:25:37 +02:00
parent 0da5aa0a6f
commit a45849821a
6 changed files with 58 additions and 19 deletions

View File

@ -5,8 +5,14 @@ import (
"git.milar.in/milarin/anilist"
"git.milar.in/milarin/channel"
"git.milar.in/milarin/slices"
)
type Pair[A, B any] struct {
First A
Second B
}
func GetCurrentlyWatchingAnimesByAnimeID() (map[anilist.MediaID]*anilist.MediaList, error) {
watchingAnimesChannel, err := GetCurrentlyWatchingAnimes()
if err != nil {
@ -23,21 +29,15 @@ func GetCurrentlyWatchingAnimes() (<-chan *anilist.MediaList, error) {
return nil, ErrAnimeListNotObtainable.Wrap(err, "access token acquisition failed")
}
currentMedia := anilist.NewApi(token).GetMediaList(context.Background(), anilist.MediaListQuery{
media := slices.Map(AnimeStatus, func(status anilist.MediaListStatus) <-chan *anilist.MediaList {
return anilist.NewApi(token).GetMediaList(context.Background(), anilist.MediaListQuery{
UserName: AnilistUsername,
Type: anilist.MediaTypeAnime,
Status: anilist.MediaListStatusCurrent,
}, nil)
Status: status,
}, nil).Chan
})
plannedMedia := anilist.NewApi(token).GetMediaList(context.Background(), anilist.MediaListQuery{
UserName: AnilistUsername,
Type: anilist.MediaTypeAnime,
Status: anilist.MediaListStatusPlanning,
}, nil)
// TODO add completedMedia for re-downloading last episode?
return channel.Merge(currentMedia.Chan, plannedMedia.Chan), nil
return channel.Merge(media...), nil
}
var (

View File

@ -11,4 +11,5 @@ var (
ErrStorageRequestFailed = adverr.NewErrTmpl("ErrStorageRequestFailed", "request to file storage could not be made")
ErrAnimeListNotObtainable = adverr.NewErrTmpl("ErrAnimeListNotObtainable", "anime list from anilist.co not obtainable (reason: %s)")
ErrTorrentNotObtainable = adverr.NewErrTmpl("ErrTorrentNotObtainable", "torrents from nyaa.si not obtainable (reason: %s)")
ErrInvalidAnimeStatus = adverr.NewErrTmpl("ErrInvalidAnimeStatus", "invalid status '%s' in ANIME_STATUS (allowed: %s)")
)

1
go.mod
View File

@ -7,6 +7,7 @@ require (
git.milar.in/milarin/anilist v1.5.0
git.milar.in/milarin/channel v0.0.7
git.milar.in/milarin/envvars v1.0.3
git.milar.in/milarin/slices v0.0.0-20220818114116-f7ab541d0a5b
git.milar.in/nyaanime/model v0.0.0-20220815143950-c3d8a5af20c3
git.milar.in/nyaanime/parsers v0.0.0-20220815144327-52de61265e27
github.com/PuerkitoBio/goquery v1.8.0

2
go.sum
View File

@ -6,6 +6,8 @@ git.milar.in/milarin/channel v0.0.7 h1:cVKtwgH/EE7U+XTHcoFCClJ4LR349KanzjX9xKwRc
git.milar.in/milarin/channel v0.0.7/go.mod h1:We83LTI8S7u7II3pD+A2ChCDWJfCkcBUCUqii9HjTtM=
git.milar.in/milarin/envvars v1.0.3 h1:go6pYExUzPx+aLvJ5BKNkaANkBNmcrlRJ8TtWsk4uWY=
git.milar.in/milarin/envvars v1.0.3/go.mod h1:rLh/HN6S254h6m2lklnImcpsy4kHFxaOjM6+Nv9GHKI=
git.milar.in/milarin/slices v0.0.0-20220818114116-f7ab541d0a5b h1:886jJlrbGpjKijCvtK9Nzwi4JZhWFFCTRWBc4yiM+TY=
git.milar.in/milarin/slices v0.0.0-20220818114116-f7ab541d0a5b/go.mod h1:XRNfE99aNKeaPOY1phjOlpIQqeGCW1LOqqh8UHS+vAk=
git.milar.in/nyaanime/model v0.0.0-20220815143950-c3d8a5af20c3 h1:GyAhYs3Nl8CuzfOeLKmWwRe/Z+pEEtnWty39HfGz6iE=
git.milar.in/nyaanime/model v0.0.0-20220815143950-c3d8a5af20c3/go.mod h1:OzhQgj0b/Hf9fg8VXYxYt8ONQOvHm8xC44TmS9kQ150=
git.milar.in/nyaanime/parsers v0.0.0-20220815144327-52de61265e27 h1:0+5j9MMJQS8+Luss19hD6hvNFxcBDRal2XwSUTyq7WU=

14
main.go
View File

@ -6,6 +6,7 @@ import (
"time"
"git.milar.in/milarin/adverr"
"git.milar.in/milarin/anilist"
"git.milar.in/milarin/envvars"
"git.milar.in/nyaanime/model"
)
@ -20,6 +21,8 @@ var (
StorageUser = envvars.String("STORAGE_USER", "")
StoragePass = envvars.String("STORAGE_PASS", "")
AnimeStatus = envvars.ObjectSlice("ANIME_STATUS", ",", ParseMediaListStatus)
// essential torrent properties
MaxResolution = envvars.Object("MAX_RESOLUTION", model.Resolution4K, model.ParseResolution)
@ -53,6 +56,13 @@ var (
)
func main() {
if len(AnimeStatus) == 0 {
AnimeStatus = []anilist.MediaListStatus{
anilist.MediaListStatusCurrent,
anilist.MediaListStatusPlanning,
}
}
// get access token once at startup to be sure that an access token is obtainable at all
if _, err := GetAnilistAccessToken(); err != nil {
panic(err)
@ -77,11 +87,11 @@ func checkTorrents() {
return
}
/*watchingAnimes, err := GetCurrentlyWatchingAnimesByAnimeID()
_, err = GetCurrentlyWatchingAnimesByAnimeID()
if err != nil {
fmt.Println(adverr.Wrap("retrieving anime list failed", err))
return
}*/
}
parsedTorrentsByAnimeEp := FilterEssentialTorrents(ParseTorrentsByAnimeEp(torrents))

View File

@ -1,6 +1,31 @@
package main
type Pair[A, B any] struct {
First A
Second B
import (
"strings"
"git.milar.in/milarin/anilist"
"git.milar.in/milarin/slices"
)
var AllMediaListStatuses = []anilist.MediaListStatus{
anilist.MediaListStatusCurrent,
anilist.MediaListStatusPlanning,
anilist.MediaListStatusCompleted,
anilist.MediaListStatusDropped,
anilist.MediaListStatusPaused,
anilist.MediaListStatusRepeating,
}
func ParseMediaListStatus(str string) (anilist.MediaListStatus, error) {
s := anilist.MediaListStatus(str)
allStatusesStr := slices.Map(AllMediaListStatuses, func(status anilist.MediaListStatus) string {
return string(status)
})
if !slices.Contains(AllMediaListStatuses, s) {
return s, ErrInvalidAnimeStatus.New(s, strings.Join(allStatusesStr, ","))
}
return s, nil
}