Added single ID refresh

This commit is contained in:
Eduard Urbach 2018-03-20 04:31:52 +01:00
parent 5d40a46720
commit c16ea9df34

View File

@ -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)