2017-06-30 23:16:25 +00:00
|
|
|
package explore
|
2017-06-20 20:54:45 +00:00
|
|
|
|
|
|
|
import (
|
2018-03-14 00:02:41 +00:00
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
2017-06-20 20:54:45 +00:00
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2017-10-28 01:53:12 +00:00
|
|
|
"github.com/animenotifier/notify.moe/components"
|
2017-11-12 10:18:16 +00:00
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
2017-10-28 01:53:12 +00:00
|
|
|
)
|
|
|
|
|
2019-09-10 00:49:51 +00:00
|
|
|
// Filter filters the anime for the explore page.
|
2019-06-01 04:55:49 +00:00
|
|
|
func Filter(ctx aero.Context) error {
|
2017-11-07 16:46:39 +00:00
|
|
|
year := ctx.Get("year")
|
2018-04-13 15:55:52 +00:00
|
|
|
season := ctx.Get("season")
|
2017-11-07 16:46:39 +00:00
|
|
|
status := ctx.Get("status")
|
|
|
|
typ := ctx.Get("type")
|
2017-11-12 10:18:16 +00:00
|
|
|
user := utils.GetUser(ctx)
|
2018-04-13 15:55:52 +00: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 16:46:39 +00:00
|
|
|
|
2018-04-13 15:55:52 +00:00
|
|
|
if season == "any" {
|
|
|
|
season = ""
|
|
|
|
}
|
2017-11-07 16:46:39 +00:00
|
|
|
|
2018-04-13 15:55:52 +00:00
|
|
|
if status == "any" {
|
|
|
|
status = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if typ == "any" {
|
|
|
|
typ = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.HTML(components.ExploreAnime(results, year, season, status, typ, user))
|
2017-11-07 16:46:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 15:55:52 +00:00
|
|
|
func filterAnime(year, season, status, typ string) []*arn.Anime {
|
2019-05-08 08:16:47 +00:00
|
|
|
results := make([]*arn.Anime, 0, 1024)
|
2017-11-07 16:46:39 +00:00
|
|
|
|
|
|
|
for anime := range arn.StreamAnime() {
|
2018-04-13 15:55:52 +00:00
|
|
|
if year != "any" {
|
|
|
|
if len(anime.StartDate) < 4 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if anime.StartDate[:4] != year {
|
|
|
|
continue
|
|
|
|
}
|
2017-11-07 16:46:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 15:55:52 +00:00
|
|
|
if status != "any" && anime.Status != status {
|
2017-11-07 16:46:39 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-04-13 15:55:52 +00:00
|
|
|
if season != "any" && anime.Season() != season {
|
2017-11-07 16:46:39 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-04-13 15:55:52 +00:00
|
|
|
if (typ != "any" || anime.Type == "music" || anime.Type == "tba") && anime.Type != typ {
|
2017-11-07 16:46:39 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
results = append(results, anime)
|
|
|
|
}
|
|
|
|
|
2018-03-14 00:02:41 +00:00
|
|
|
arn.SortAnimeByQualityDetailed(results, status)
|
2017-11-07 16:46:39 +00:00
|
|
|
return results
|
|
|
|
}
|