74 lines
1.6 KiB
Go
Raw Normal View History

2017-07-02 12:03:56 +00:00
package main
import (
2017-07-02 12:08:25 +00:00
"fmt"
"strconv"
"strings"
2017-07-02 12:03:56 +00:00
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
func main() {
color.Yellow("Refreshing episode information for each anime.")
if InvokeShellArgs() {
return
}
highPriority := []*arn.Anime{}
2017-07-10 18:35:45 +00:00
mediumPriority := []*arn.Anime{}
lowPriority := []*arn.Anime{}
2017-07-02 12:03:56 +00:00
for anime := range arn.MustStreamAnime() {
if anime.GetMapping("shoboi/anime") == "" {
continue
}
2017-07-10 18:35:45 +00:00
switch anime.Status {
case "current":
highPriority = append(highPriority, anime)
2017-07-10 18:35:45 +00:00
case "upcoming":
mediumPriority = append(mediumPriority, anime)
default:
lowPriority = append(lowPriority, anime)
}
}
2017-09-23 16:55:33 +00:00
color.Cyan("High priority queue (%d):", len(highPriority))
refreshQueue(highPriority)
2017-09-23 16:55:33 +00:00
color.Cyan("Medium priority queue (%d):", len(mediumPriority))
refreshQueue(mediumPriority)
2017-07-10 18:35:45 +00:00
2017-09-23 16:55:33 +00:00
color.Cyan("Low priority queue (%d):", len(lowPriority))
refreshQueue(lowPriority)
color.Green("Finished.")
}
func refreshQueue(queue []*arn.Anime) {
for _, anime := range queue {
refresh(anime)
}
}
2017-09-23 16:55:33 +00:00
func refresh(anime *arn.Anime) {
fmt.Println(anime.ID, "|", anime.Title.Canonical, "|", anime.GetMapping("shoboi/anime"))
2017-07-02 12:08:25 +00:00
episodeCount := len(anime.Episodes().Items)
availableEpisodeCount := anime.Episodes().AvailableCount()
2017-07-02 12:03:56 +00:00
err := anime.RefreshEpisodes()
2017-07-02 12:08:25 +00:00
if err != nil {
if strings.Contains(err.Error(), "missing a Shoboi ID") {
return
2017-07-02 12:03:56 +00:00
}
color.Red(err.Error())
} else {
fmt.Println("+"+strconv.Itoa(len(anime.Episodes().Items)-episodeCount)+" airing", "|", "+"+strconv.Itoa(anime.Episodes().AvailableCount()-availableEpisodeCount)+" available")
2017-07-02 12:03:56 +00:00
}
}