80 lines
1.7 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"
"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.")
2017-11-01 09:28:40 +00:00
defer arn.Node.Close()
2017-07-02 12:03:56 +00:00
if InvokeShellArgs() {
return
}
highPriority := []*arn.Anime{}
2017-07-10 18:35:45 +00:00
mediumPriority := []*arn.Anime{}
lowPriority := []*arn.Anime{}
2017-11-01 09:28:40 +00:00
for anime := range arn.StreamAnime() {
if anime.GetMapping("shoboi/anime") == "" {
continue
}
2017-10-03 06:08:52 +00:00
// The rest gets sorted by airing status
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 {
2017-09-24 03:01:15 +00:00
faint := color.New(color.Faint).SprintFunc()
episodes := anime.Episodes()
fmt.Println(faint(episodes))
2017-10-02 16:59:53 +00:00
fmt.Printf("+%d episodes | +%d available (%d total)\n", len(episodes.Items)-episodeCount, episodes.AvailableCount()-availableEpisodeCount, len(episodes.Items))
2017-09-24 03:01:15 +00:00
println()
2017-07-02 12:03:56 +00:00
}
}