91 lines
1.5 KiB
Go
Raw Normal View History

2017-07-01 01:16:25 +02:00
package explore
2017-06-20 22:54:45 +02:00
import (
2018-03-14 01:02:41 +01:00
"strconv"
"time"
2017-06-20 22:54:45 +02:00
"github.com/aerogo/aero"
2017-10-28 03:53:12 +02:00
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
2017-11-12 11:18:16 +01:00
"github.com/animenotifier/notify.moe/utils"
2017-10-28 03:53:12 +02:00
)
2017-11-07 17:46:39 +01:00
// Filter ...
func Filter(ctx *aero.Context) string {
year := ctx.Get("year")
2018-04-13 17:55:52 +02:00
season := ctx.Get("season")
2017-11-07 17:46:39 +01:00
status := ctx.Get("status")
typ := ctx.Get("type")
2017-11-12 11:18:16 +01:00
user := utils.GetUser(ctx)
2018-04-13 17:55:52 +02:00
now := time.Now()
if year == "" {
year = strconv.Itoa(now.Year())
}
if season == "" {
season = arn.DateToSeason(now)
}
if status == "" {
status = "current"
}
if typ == "" {
typ = "tv"
}
results := filterAnime(year, season, status, typ)
if year == "any" {
year = ""
}
2017-11-07 17:46:39 +01:00
2018-04-13 17:55:52 +02:00
if season == "any" {
season = ""
}
2017-11-07 17:46:39 +01:00
2018-04-13 17:55:52 +02:00
if status == "any" {
status = ""
}
if typ == "any" {
typ = ""
}
return ctx.HTML(components.ExploreAnime(results, year, season, status, typ, user))
2017-11-07 17:46:39 +01:00
}
2018-04-13 17:55:52 +02:00
func filterAnime(year, season, status, typ string) []*arn.Anime {
2017-11-07 17:46:39 +01:00
var results []*arn.Anime
for anime := range arn.StreamAnime() {
2018-04-13 17:55:52 +02:00
if year != "any" {
if len(anime.StartDate) < 4 {
continue
}
if anime.StartDate[:4] != year {
continue
}
2017-11-07 17:46:39 +01:00
}
2018-04-13 17:55:52 +02:00
if status != "any" && anime.Status != status {
2017-11-07 17:46:39 +01:00
continue
}
2018-04-13 17:55:52 +02:00
if season != "any" && anime.Season() != season {
2017-11-07 17:46:39 +01:00
continue
}
2018-04-13 17:55:52 +02:00
if (typ != "any" || anime.Type == "music" || anime.Type == "tba") && anime.Type != typ {
2017-11-07 17:46:39 +01:00
continue
}
results = append(results, anime)
}
2018-03-14 01:02:41 +01:00
arn.SortAnimeByQualityDetailed(results, status)
2017-11-07 17:46:39 +01:00
return results
}