From c16ea9df34fb6ceb4d7d748dc969342e4e0b4869 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 20 Mar 2018 04:31:52 +0100 Subject: [PATCH] Added single ID refresh --- .../refresh-anime-thumbnails.go | 76 ++++++++++++------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/patches/refresh-anime-thumbnails/refresh-anime-thumbnails.go b/patches/refresh-anime-thumbnails/refresh-anime-thumbnails.go index bfc50f96..fc1b228a 100644 --- a/patches/refresh-anime-thumbnails/refresh-anime-thumbnails.go +++ b/patches/refresh-anime-thumbnails/refresh-anime-thumbnails.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "io/ioutil" "os" @@ -16,36 +17,59 @@ func main() { defer arn.Node.Close() defer color.Green("Finished.") + // Parse flags + var animeID string + flag.StringVar(&animeID, "id", "", "ID of the anime that you want to refresh") + flag.Parse() + + // Refresh 1 anime in case ID was specified + if animeID != "" { + anime, _ := arn.GetAnime(animeID) + + if anime != nil { + sync(anime) + } + + return + } + + // Otherwise refresh all anime for anime := range arn.StreamAnime() { - base := path.Join(arn.Root, "/images/anime/original/", anime.ID) - - if _, err := os.Stat(base + ".png"); err == nil { - update(anime, base+".png") - continue - } - - if _, err := os.Stat(base + ".jpg"); err == nil { - update(anime, base+".jpg") - continue - } - - if _, err := os.Stat(base + ".jpeg"); err == nil { - update(anime, base+".jpg") - continue - } - - if _, err := os.Stat(base + ".gif"); err == nil { - update(anime, base+".gif") - continue - } - - if _, err := os.Stat(base + ".webp"); err == nil { - update(anime, base+".webp") - continue - } + sync(anime) } } +// sync refreshes the image of the given anime. +func sync(anime *arn.Anime) { + base := path.Join(arn.Root, "/images/anime/original/", anime.ID) + + if _, err := os.Stat(base + ".png"); err == nil { + update(anime, base+".png") + return + } + + if _, err := os.Stat(base + ".jpg"); err == nil { + update(anime, base+".jpg") + return + } + + if _, err := os.Stat(base + ".jpeg"); err == nil { + update(anime, base+".jpg") + return + } + + if _, err := os.Stat(base + ".gif"); err == nil { + update(anime, base+".gif") + return + } + + if _, err := os.Stat(base + ".webp"); err == nil { + update(anime, base+".webp") + return + } +} + +// update expects a file to load as image for the anime and updates it. func update(anime *arn.Anime, filePath string) { fmt.Println(anime.ID, anime)