2017-11-16 15:38:49 +00:00
|
|
|
package popular
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
|
|
|
"github.com/animenotifier/notify.moe/arn/stringutils"
|
2017-11-16 15:38:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// AnimeTitles returns a list of the 500 most popular anime titles.
|
2019-06-01 04:55:49 +00:00
|
|
|
func AnimeTitles(ctx aero.Context) error {
|
2017-11-16 15:38:49 +00:00
|
|
|
maxLength, err := ctx.GetInt("count")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusBadRequest, "Invalid value for count parameter", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
popularAnimeTitles := []string{}
|
|
|
|
popularAnime := arn.AllAnime()
|
|
|
|
arn.SortAnimeByPopularity(popularAnime)
|
|
|
|
|
|
|
|
if len(popularAnime) > maxLength {
|
|
|
|
popularAnime = popularAnime[:maxLength]
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, anime := range popularAnime {
|
2017-11-16 15:56:34 +00:00
|
|
|
popularAnimeTitles = append(popularAnimeTitles, anime.Title.Canonical)
|
2017-11-16 15:38:49 +00:00
|
|
|
|
2018-04-19 20:01:28 +00:00
|
|
|
if stringutils.ContainsUnicodeLetters(anime.Title.Japanese) {
|
2017-11-16 15:38:49 +00:00
|
|
|
popularAnimeTitles = append(popularAnimeTitles, anime.Title.Japanese)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.JSON(popularAnimeTitles)
|
|
|
|
}
|