95 lines
2.1 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"
2019-04-23 05:45:17 +00:00
"github.com/akyoto/color"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2017-07-02 12:03:56 +00:00
)
func main() {
color.Yellow("Refreshing episode information for each anime.")
2018-03-28 22:26:19 +00:00
defer color.Green("Finished.")
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)
}
}
2018-03-27 01:13:45 +00:00
switch queue {
case "high":
2018-03-27 01:16:54 +00:00
color.Cyan("High priority queue (%d):", len(highPriority))
2018-03-27 01:13:45 +00:00
refreshQueue(highPriority)
2018-03-27 01:13:45 +00:00
case "medium":
2018-03-27 01:16:54 +00:00
color.Cyan("Medium priority queue (%d):", len(mediumPriority))
2018-03-27 01:13:45 +00:00
refreshQueue(mediumPriority)
2017-07-10 18:35:45 +00:00
2018-03-27 01:13:45 +00:00
case "low":
2018-03-27 01:16:54 +00:00
color.Cyan("Low priority queue (%d):", len(lowPriority))
2018-03-27 01:13:45 +00:00
refreshQueue(lowPriority)
default:
color.Cyan("High priority queue (%d):", len(highPriority))
refreshQueue(highPriority)
color.Cyan("Medium priority queue (%d):", len(mediumPriority))
refreshQueue(mediumPriority)
color.Cyan("Low priority queue (%d):", len(lowPriority))
refreshQueue(lowPriority)
}
}
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
2019-08-28 08:06:42 +00:00
episodeCount := len(anime.Episodes())
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()
2019-08-28 08:06:42 +00:00
fmt.Println(faint(episodes.HumanReadable()))
fmt.Printf("+%d episodes | +%d available (%d total)\n", len(episodes)-episodeCount, episodes.AvailableCount()-availableEpisodeCount, len(episodes))
2017-09-24 03:01:15 +00:00
println()
2017-07-02 12:03:56 +00:00
}
}