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.")
|
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
|
|
|
|
2017-09-24 01:39:26 +00:00
|
|
|
if InvokeShellArgs() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:51:44 +00:00
|
|
|
highPriority := []*arn.Anime{}
|
2017-07-10 18:35:45 +00:00
|
|
|
mediumPriority := []*arn.Anime{}
|
2017-07-06 15:51:44 +00:00
|
|
|
lowPriority := []*arn.Anime{}
|
|
|
|
|
2017-11-01 09:28:40 +00:00
|
|
|
for anime := range arn.StreamAnime() {
|
2017-07-06 15:51:44 +00:00
|
|
|
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":
|
2017-07-06 15:51:44 +00:00
|
|
|
highPriority = append(highPriority, anime)
|
2017-07-10 18:35:45 +00:00
|
|
|
case "upcoming":
|
|
|
|
mediumPriority = append(mediumPriority, anime)
|
|
|
|
default:
|
2017-07-06 15:51:44 +00:00
|
|
|
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)
|
2017-07-06 15:51:44 +00:00
|
|
|
|
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)
|
|
|
|
}
|
2017-07-06 15:51:44 +00:00
|
|
|
}
|
|
|
|
|
2017-09-24 01:39:26 +00:00
|
|
|
func refreshQueue(queue []*arn.Anime) {
|
2017-07-06 15:51:44 +00:00
|
|
|
for _, anime := range queue {
|
2017-09-24 01:39:26 +00:00
|
|
|
refresh(anime)
|
|
|
|
}
|
|
|
|
}
|
2017-09-23 16:55:33 +00:00
|
|
|
|
2017-09-24 01:39:26 +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
|
|
|
|
2017-09-24 01:39:26 +00:00
|
|
|
episodeCount := len(anime.Episodes().Items)
|
|
|
|
availableEpisodeCount := anime.Episodes().AvailableCount()
|
2017-07-02 12:03:56 +00:00
|
|
|
|
2017-09-24 01:39:26 +00:00
|
|
|
err := anime.RefreshEpisodes()
|
2017-07-02 12:08:25 +00:00
|
|
|
|
2017-09-24 01:39:26 +00:00
|
|
|
if err != nil {
|
|
|
|
if strings.Contains(err.Error(), "missing a Shoboi ID") {
|
|
|
|
return
|
2017-07-02 12:03:56 +00:00
|
|
|
}
|
2017-09-24 01:39:26 +00:00
|
|
|
|
|
|
|
color.Red(err.Error())
|
|
|
|
} else {
|
2017-09-24 03:01:15 +00:00
|
|
|
faint := color.New(color.Faint).SprintFunc()
|
|
|
|
episodes := anime.Episodes()
|
|
|
|
|
2018-03-09 20:21:37 +00:00
|
|
|
fmt.Println(faint(episodes.ListString()))
|
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
|
|
|
}
|
|
|
|
}
|