2017-10-06 20:07:12 +00:00
|
|
|
package editor
|
2017-07-08 19:11:03 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
"github.com/animenotifier/notify.moe/components"
|
|
|
|
)
|
|
|
|
|
2017-10-06 20:07:12 +00:00
|
|
|
const maxAniListEntries = 70
|
|
|
|
|
2017-10-02 12:56:51 +00:00
|
|
|
// AniList ...
|
|
|
|
func AniList(ctx *aero.Context) string {
|
2018-03-07 21:06:02 +00:00
|
|
|
year, _ := ctx.GetInt("year")
|
|
|
|
animeType := ctx.Get("type")
|
|
|
|
|
2017-10-27 07:11:56 +00:00
|
|
|
missing := arn.FilterAnime(func(anime *arn.Anime) bool {
|
2018-03-07 21:06:02 +00:00
|
|
|
if year != 0 && year != anime.StartDateTime().Year() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if animeType != "" && anime.Type != animeType {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-07-08 19:11:03 +00:00
|
|
|
return anime.GetMapping("anilist/anime") == ""
|
|
|
|
})
|
|
|
|
|
|
|
|
sort.Slice(missing, func(i, j int) bool {
|
2017-10-06 20:07:12 +00:00
|
|
|
a := missing[i]
|
|
|
|
b := missing[j]
|
|
|
|
|
|
|
|
aPop := a.Popularity.Total()
|
|
|
|
bPop := b.Popularity.Total()
|
|
|
|
|
|
|
|
if aPop == bPop {
|
|
|
|
return a.Title.Canonical < b.Title.Canonical
|
|
|
|
}
|
|
|
|
|
|
|
|
return aPop > bPop
|
2017-07-08 19:11:03 +00:00
|
|
|
})
|
|
|
|
|
2018-03-07 20:25:24 +00:00
|
|
|
count := len(missing)
|
|
|
|
|
|
|
|
if count > maxAniListEntries {
|
2017-10-06 20:07:12 +00:00
|
|
|
missing = missing[:maxAniListEntries]
|
|
|
|
}
|
|
|
|
|
2018-03-07 20:25:24 +00:00
|
|
|
return ctx.HTML(components.AnimeEditorListFull(
|
|
|
|
"Anime without Anilist links",
|
|
|
|
missing,
|
|
|
|
count,
|
2018-03-20 15:53:23 +00:00
|
|
|
ctx.URI(),
|
2018-03-07 20:25:24 +00:00
|
|
|
func(anime *arn.Anime) string {
|
|
|
|
return "https://anilist.co/search?type=anime&q=" + anime.Title.Canonical
|
|
|
|
},
|
|
|
|
))
|
2017-07-08 19:11:03 +00:00
|
|
|
}
|