Can now refresh a single anime in refresh-episodes

This commit is contained in:
Eduard Urbach 2017-09-24 03:39:26 +02:00
parent 7bce362eeb
commit eb4b4c7b54
2 changed files with 60 additions and 20 deletions

View File

@ -12,6 +12,10 @@ import (
func main() { func main() {
color.Yellow("Refreshing episode information for each anime.") color.Yellow("Refreshing episode information for each anime.")
if InvokeShellArgs() {
return
}
highPriority := []*arn.Anime{} highPriority := []*arn.Anime{}
mediumPriority := []*arn.Anime{} mediumPriority := []*arn.Anime{}
lowPriority := []*arn.Anime{} lowPriority := []*arn.Anime{}
@ -32,34 +36,38 @@ func main() {
} }
color.Cyan("High priority queue (%d):", len(highPriority)) color.Cyan("High priority queue (%d):", len(highPriority))
refresh(highPriority) refreshQueue(highPriority)
color.Cyan("Medium priority queue (%d):", len(mediumPriority)) color.Cyan("Medium priority queue (%d):", len(mediumPriority))
refresh(mediumPriority) refreshQueue(mediumPriority)
color.Cyan("Low priority queue (%d):", len(lowPriority)) color.Cyan("Low priority queue (%d):", len(lowPriority))
refresh(lowPriority) refreshQueue(lowPriority)
color.Green("Finished.") color.Green("Finished.")
} }
func refresh(queue []*arn.Anime) { func refreshQueue(queue []*arn.Anime) {
for _, anime := range queue { for _, anime := range queue {
fmt.Println(anime.ID, "|", anime.Title.Canonical, "|", anime.GetMapping("shoboi/anime")) refresh(anime)
}
episodeCount := len(anime.Episodes().Items) }
availableEpisodeCount := anime.Episodes().AvailableCount()
func refresh(anime *arn.Anime) {
err := anime.RefreshEpisodes() fmt.Println(anime.ID, "|", anime.Title.Canonical, "|", anime.GetMapping("shoboi/anime"))
if err != nil { episodeCount := len(anime.Episodes().Items)
if strings.Contains(err.Error(), "missing a Shoboi ID") { availableEpisodeCount := anime.Episodes().AvailableCount()
continue
} err := anime.RefreshEpisodes()
color.Red(err.Error()) if err != nil {
} else { if strings.Contains(err.Error(), "missing a Shoboi ID") {
fmt.Println("+"+strconv.Itoa(len(anime.Episodes().Items)-episodeCount)+" airing", "|", "+"+strconv.Itoa(anime.Episodes().AvailableCount()-availableEpisodeCount)+" available") return
} }
color.Red(err.Error())
} else {
fmt.Println("+"+strconv.Itoa(len(anime.Episodes().Items)-episodeCount)+" airing", "|", "+"+strconv.Itoa(anime.Episodes().AvailableCount()-availableEpisodeCount)+" available")
} }
} }

View File

@ -0,0 +1,32 @@
package main
import (
"flag"
"github.com/animenotifier/arn"
)
// Shell parameters
var animeID string
// Shell flags
func init() {
flag.StringVar(&animeID, "id", "", "ID of the anime you want to refresh")
flag.Parse()
}
// InvokeShellArgs ...
func InvokeShellArgs() bool {
if animeID != "" {
anime, err := arn.GetAnime(animeID)
if err != nil {
panic(err)
}
refresh(anime)
return true
}
return false
}