Added check for low res images

This commit is contained in:
Eduard Urbach 2018-03-20 01:19:11 +01:00
parent 54472ae927
commit f3b788f50c
3 changed files with 89 additions and 0 deletions

View File

@ -27,6 +27,7 @@ component EditorTabs(url string)
Tab("Shoboi", "list", "/editor/anime/missing/shoboi") Tab("Shoboi", "list", "/editor/anime/missing/shoboi")
Tab("AniList", "list", "/editor/anime/missing/anilist") Tab("AniList", "list", "/editor/anime/missing/anilist")
Tab("Genres", "list", "/editor/anime/missing/genres") Tab("Genres", "list", "/editor/anime/missing/genres")
Tab("Hi-Res Image", "list", "/editor/anime/missing/hiresimage")
//- a.tab.ajax(href="/admin", aria-label="Admin") //- a.tab.ajax(href="/admin", aria-label="Admin")
//- Icon("wrench") //- Icon("wrench")

View File

@ -0,0 +1,83 @@
package editor
import (
"image"
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"strings"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
)
const maxImageEntries = 70
// LowResolutionAnimeImages ...
func LowResolutionAnimeImages(ctx *aero.Context) string {
basePath := path.Join(arn.Root, "images/anime/original/")
files, err := ioutil.ReadDir(basePath)
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Error reading anime images directory", err)
}
lowResAnime := []*arn.Anime{}
for _, file := range files {
if file.IsDir() || strings.HasPrefix(file.Name(), ".") {
continue
}
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)
}
}
}
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
}

View File

@ -254,10 +254,15 @@ func Configure(app *aero.Application) {
l.Page("/editor/anime/missing/genres", editor.Genres) l.Page("/editor/anime/missing/genres", editor.Genres)
l.Page("/editor/anime/missing/genres/:year", editor.Genres) l.Page("/editor/anime/missing/genres/:year", editor.Genres)
l.Page("/editor/anime/missing/genres/:year/:type", editor.Genres) l.Page("/editor/anime/missing/genres/:year/:type", editor.Genres)
l.Page("/editor/anime/missing/hiresimage", editor.LowResolutionAnimeImages)
// Editor - MALdiff
l.Page("/editor/anime/maldiff", editor.CompareMAL) l.Page("/editor/anime/maldiff", editor.CompareMAL)
l.Page("/editor/anime/maldiff/:year", editor.CompareMAL) l.Page("/editor/anime/maldiff/:year", editor.CompareMAL)
l.Page("/editor/anime/maldiff/:year/:status", editor.CompareMAL) l.Page("/editor/anime/maldiff/:year/:status", editor.CompareMAL)
l.Page("/editor/anime/maldiff/:year/:status/:type", editor.CompareMAL) l.Page("/editor/anime/maldiff/:year/:status/:type", editor.CompareMAL)
// Editor - Kitsu
l.Page("/editor/anime/kitsu/new", editor.NewKitsuAnime) l.Page("/editor/anime/kitsu/new", editor.NewKitsuAnime)
// Editor - Companies // Editor - Companies