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 package main
import ( import (
"flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -16,36 +17,59 @@ func main() {
defer arn.Node.Close() defer arn.Node.Close()
defer color.Green("Finished.") 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() { for anime := range arn.StreamAnime() {
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) base := path.Join(arn.Root, "/images/anime/original/", anime.ID)
if _, err := os.Stat(base + ".png"); err == nil { if _, err := os.Stat(base + ".png"); err == nil {
update(anime, base+".png") update(anime, base+".png")
continue return
} }
if _, err := os.Stat(base + ".jpg"); err == nil { if _, err := os.Stat(base + ".jpg"); err == nil {
update(anime, base+".jpg") update(anime, base+".jpg")
continue return
} }
if _, err := os.Stat(base + ".jpeg"); err == nil { if _, err := os.Stat(base + ".jpeg"); err == nil {
update(anime, base+".jpg") update(anime, base+".jpg")
continue return
} }
if _, err := os.Stat(base + ".gif"); err == nil { if _, err := os.Stat(base + ".gif"); err == nil {
update(anime, base+".gif") update(anime, base+".gif")
continue return
} }
if _, err := os.Stat(base + ".webp"); err == nil { if _, err := os.Stat(base + ".webp"); err == nil {
update(anime, base+".webp") update(anime, base+".webp")
continue return
}
} }
} }
// update expects a file to load as image for the anime and updates it.
func update(anime *arn.Anime, filePath string) { func update(anime *arn.Anime, filePath string) {
fmt.Println(anime.ID, anime) fmt.Println(anime.ID, anime)