129 lines
3.3 KiB
Go
Raw Normal View History

2018-03-20 00:19:11 +00:00
package editor
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
)
const maxImageEntries = 70
2018-03-20 00:43:23 +00:00
// LowResolutionAnimeImages filters anime with low resolution images.
2018-03-20 00:19:11 +00:00
func LowResolutionAnimeImages(ctx *aero.Context) string {
return filterAnimeImages(ctx, "Anime with low resolution images", arn.AnimeImageLargeWidth, arn.AnimeImageLargeHeight)
}
// UltraLowResolutionAnimeImages filters anime with ultra low resolution images.
func UltraLowResolutionAnimeImages(ctx *aero.Context) string {
return filterAnimeImages(ctx, "Anime with ultra low resolution images", arn.AnimeImageLargeWidth/2, arn.AnimeImageLargeHeight/2)
}
func filterAnimeImages(ctx *aero.Context, title string, minExpectedWidth int, minExpectedHeight int) string {
2018-03-20 00:43:23 +00:00
year, _ := ctx.GetInt("year")
animeType := ctx.Get("type")
2018-03-20 00:19:11 +00:00
2018-03-20 00:43:23 +00:00
lowResAnime := arn.FilterAnime(func(anime *arn.Anime) bool {
if year != 0 && year != anime.StartDateTime().Year() {
return false
2018-03-20 00:19:11 +00:00
}
2018-03-20 00:43:23 +00:00
if animeType != "" && anime.Type != animeType {
return false
2018-03-20 00:19:11 +00:00
}
2018-03-20 00:43:23 +00:00
return anime.Image.Width < minExpectedWidth || anime.Image.Height < minExpectedHeight
2018-03-20 00:43:23 +00:00
})
2018-03-20 00:19:11 +00:00
2018-03-20 00:21:50 +00:00
// Sort
arn.SortAnimeByQuality(lowResAnime)
// Limit
2018-03-20 00:19:11 +00:00
count := len(lowResAnime)
if count > maxImageEntries {
lowResAnime = lowResAnime[:maxImageEntries]
}
return ctx.HTML(components.AnimeEditorListFull(
title,
2018-03-20 00:19:11 +00:00
lowResAnime,
count,
2018-03-20 15:53:23 +00:00
ctx.URI(),
googleImageSearch,
2018-03-20 00:19:11 +00:00
))
}
2018-03-20 15:53:23 +00:00
func googleImageSearch(anime *arn.Anime) string {
2018-03-20 15:57:55 +00:00
return "https://www.google.com/search?q=" + anime.Title.Canonical + " anime cover" + "&tbm=isch&tbs=imgo:1,isz:lt,islt:qsvga"
2018-03-20 15:53:23 +00:00
}
2018-03-20 00:43:23 +00:00
// // LowResolutionAnimeImages ...
// func LowResolutionAnimeImages(ctx *aero.Context) string {
// basePath := path.Join(arn.Root, "images/anime/original/")
// files, err := ioutil.ReadDir(basePath)
2018-03-20 00:19:11 +00:00
2018-03-20 00:43:23 +00:00
// if err != nil {
// return ctx.Error(http.StatusInternalServerError, "Error reading anime images directory", err)
// }
2018-03-20 00:19:11 +00:00
2018-03-20 00:43:23 +00:00
// lowResAnime := []*arn.Anime{}
2018-03-20 00:19:11 +00:00
2018-03-20 00:43:23 +00:00
// for _, file := range files {
// if file.IsDir() || strings.HasPrefix(file.Name(), ".") {
// continue
// }
2018-03-20 00:19:11 +00:00
2018-03-20 00:43:23 +00:00
// fullPath := path.Join(basePath, file.Name())
// width, height, _ := getImageDimensions(fullPath)
// if width < arn.AnimeImageLargeWidth*2 || height < arn.AnimeImageLargeHeight*2 {
// animeID := file.Name()
// animeID = strings.TrimSuffix(animeID, filepath.Ext(animeID))
// anime, err := arn.GetAnime(animeID)
// if err == nil {
// lowResAnime = append(lowResAnime, anime)
// }
// }
// }
// // Sort
// arn.SortAnimeByQuality(lowResAnime)
// // Limit
// count := len(lowResAnime)
// if count > maxImageEntries {
// lowResAnime = lowResAnime[:maxImageEntries]
// }
// return ctx.HTML(components.AnimeEditorListFull(
// "Anime with low resolution images",
// lowResAnime,
// count,
// "/editor/anime/missing/hiresimage",
// func(anime *arn.Anime) string {
// return "https://www.google.com/search?q=" + anime.Title.Canonical + "&tbm=isch"
// },
// ))
// }
// // getImageDimensions retrieves the dimensions for the given file path.
// func getImageDimensions(imagePath string) (int, int, error) {
// file, err := os.Open(imagePath)
// defer file.Close()
// if err != nil {
// return 0, 0, err
// }
// image, _, err := image.DecodeConfig(file)
// if err != nil {
// return 0, 0, err
// }
// return image.Width, image.Height, nil
// }