Improved twist.moe updater
This commit is contained in:
parent
06fddad8bd
commit
112bec862e
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
@ -22,9 +21,6 @@ func main() {
|
|||||||
color.Yellow("Refreshing twist.moe links for %d anime", len(idList))
|
color.Yellow("Refreshing twist.moe links for %d anime", len(idList))
|
||||||
|
|
||||||
for count, animeID := range idList {
|
for count, animeID := range idList {
|
||||||
// Wait for rate limiter
|
|
||||||
<-rateLimiter.C
|
|
||||||
|
|
||||||
anime, animeErr := arn.GetAnime(animeID)
|
anime, animeErr := arn.GetAnime(animeID)
|
||||||
|
|
||||||
if animeErr != nil {
|
if animeErr != nil {
|
||||||
@ -35,37 +31,13 @@ func main() {
|
|||||||
// Log
|
// Log
|
||||||
fmt.Fprintf(os.Stdout, "[%d / %d] ", count+1, len(idList))
|
fmt.Fprintf(os.Stdout, "[%d / %d] ", count+1, len(idList))
|
||||||
|
|
||||||
// Get twist.moe feed
|
// Refresh
|
||||||
feed, err := twist.GetFeedByKitsuID(animeID)
|
anime.RefreshEpisodes()
|
||||||
|
|
||||||
if err != nil {
|
// Ok
|
||||||
color.Red("Error querying ID %s: %v", animeID, err)
|
color.Green("Found %d episodes for anime %s", len(anime.Episodes().Items), animeID)
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
episodes := feed.Episodes
|
// Wait for rate limiter
|
||||||
|
<-rateLimiter.C
|
||||||
// // Sort by episode number
|
|
||||||
// sort.Slice(episodes, func(a, b int) bool {
|
|
||||||
// return episodes[a].Number < episodes[b].Number
|
|
||||||
// })
|
|
||||||
|
|
||||||
for _, episode := range episodes {
|
|
||||||
arnEpisode := anime.EpisodeByNumber(episode.Number)
|
|
||||||
|
|
||||||
if arnEpisode == nil {
|
|
||||||
color.Red("Anime %s Episode %d not found", anime.ID, episode.Number)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if arnEpisode.Links == nil {
|
|
||||||
arnEpisode.Links = map[string]string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
arnEpisode.Links["twist.moe"] = strings.Replace(episode.Link, "https://test.twist.moe/", "https://twist.moe/", 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
arn.PanicOnError(anime.Episodes().Save())
|
|
||||||
color.Green("Found %d episodes for anime %s", len(episodes), animeID)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user