94 lines
1.9 KiB
Go
Raw Normal View History

2017-06-29 05:02:09 +00:00
package main
import (
"os"
"time"
"github.com/animenotifier/arn"
"github.com/animenotifier/shoboi"
"github.com/fatih/color"
)
func main() {
color.Yellow("Syncing Shoboi Anime")
// Get a slice of all anime
allAnime, _ := arn.AllAnime()
// Iterate over the slice
count := 0
for _, anime := range allAnime {
if sync(anime) {
count++
}
}
// Log
color.Green("Successfully added Shoboi IDs for %d anime", count)
// This is a lazy hack: Wait 5 minutes for goroutines to finish their remaining work.
time.Sleep(5 * time.Minute)
color.Green("Finished.")
}
func sync(anime *arn.Anime) bool {
// If we already have the ID, nothing to do here
if anime.GetMapping("shoboi/anime") != "" {
return false
}
// Log ID and title
os.Stdout.Write([]byte(anime.ID + " | [JP] " + anime.Title.Japanese + " | [EN] " + anime.Title.English))
// Search Japanese title
if anime.GetMapping("shoboi/anime") == "" && anime.Title.Japanese != "" {
search(anime, anime.Title.Japanese)
}
// Search English title
if anime.GetMapping("shoboi/anime") == "" && anime.Title.English != "" {
search(anime, anime.Title.English)
}
// Did we get the ID?
if anime.GetMapping("shoboi/anime") != "" {
println(color.GreenString("✔"))
time.Sleep(2 * time.Second)
return true
}
println(color.RedString("✘"))
return false
}
// Search for a specific title
func search(anime *arn.Anime, title string) {
2017-06-29 05:09:29 +00:00
shoboi, err := shoboi.SearchAnime(title)
2017-06-29 05:02:09 +00:00
if err != nil {
color.Red(err.Error())
return
}
2017-06-29 05:09:29 +00:00
if shoboi == nil {
2017-06-29 05:02:09 +00:00
return
}
2017-06-29 05:09:29 +00:00
// Copy titles
if shoboi.TitleJapanese != "" {
anime.Title.Japanese = shoboi.TitleJapanese
}
if shoboi.TitleHiragana != "" {
anime.Title.Hiragana = shoboi.TitleHiragana
}
if shoboi.FirstChannel != "" {
anime.FirstChannel = shoboi.FirstChannel
}
2017-06-29 05:02:09 +00:00
// This will start a goroutine that saves the anime
2017-06-29 05:09:29 +00:00
anime.AddMapping("shoboi/anime", shoboi.TID, "")
2017-06-29 05:02:09 +00:00
}