This commit is contained in:
Eduard Urbach 2018-03-17 00:28:36 +01:00
parent 7f5f58d60d
commit 5cc1ded99d
7 changed files with 32 additions and 16 deletions

View File

@ -35,7 +35,7 @@ func BenchmarkRenderAnimeList(b *testing.B) {
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
for pb.Next() { for pb.Next() {
components.AnimeList(animeList, user, user) components.AnimeList(animeList.Items, -1, user, user)
} }
}) })
} }

View File

@ -2,16 +2,17 @@ package main
import ( import (
"fmt" "fmt"
"path/filepath" "net/http"
"strings" "strings"
"github.com/aerogo/http/client"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/animenotifier/kitsu" "github.com/animenotifier/kitsu"
"github.com/fatih/color" "github.com/fatih/color"
) )
func main() { func main() {
color.Yellow("Syncing Anime") color.Yellow("Importing Kitsu anime")
defer arn.Node.Close() defer arn.Node.Close()
defer color.Green("Finished.") defer color.Green("Finished.")
@ -26,17 +27,17 @@ func main() {
// Iterate over the stream // Iterate over the stream
for anime := range allAnime { for anime := range allAnime {
sync(anime) importKitsuAnime(anime)
} }
} }
func sync(data *kitsu.Anime) *arn.Anime { func importKitsuAnime(data *kitsu.Anime) *arn.Anime {
anime, err := arn.GetAnime(data.ID) anime, err := arn.GetAnime(data.ID)
// This stops overwriting existing data // This stops overwriting existing data
if anime != nil { // if anime != nil {
return anime // return anime
} // }
if err != nil { if err != nil {
if strings.Contains(err.Error(), "not found") { if strings.Contains(err.Error(), "not found") {
@ -62,7 +63,6 @@ func sync(data *kitsu.Anime) *arn.Anime {
anime.EpisodeCount = attr.EpisodeCount anime.EpisodeCount = attr.EpisodeCount
anime.EpisodeLength = attr.EpisodeLength anime.EpisodeLength = attr.EpisodeLength
anime.Status = attr.Status anime.Status = attr.Status
anime.Image.Extension = filepath.Ext(kitsu.FixImageURL(attr.PosterImage.Original))
// Status "unreleased" means the same as "upcoming" so we should normalize it // Status "unreleased" means the same as "upcoming" so we should normalize it
if anime.Status == "unreleased" { if anime.Status == "unreleased" {
@ -95,11 +95,12 @@ func sync(data *kitsu.Anime) *arn.Anime {
for _, mapping := range data.Mappings { for _, mapping := range data.Mappings {
switch mapping.Attributes.ExternalSite { switch mapping.Attributes.ExternalSite {
case "myanimelist/anime": case "myanimelist/anime":
anime.AddMapping("myanimelist/anime", mapping.Attributes.ExternalID, "") anime.SetMapping("myanimelist/anime", mapping.Attributes.ExternalID, "")
case "anidb": case "anidb":
anime.AddMapping("anidb/anime", mapping.Attributes.ExternalID, "") anime.SetMapping("anidb/anime", mapping.Attributes.ExternalID, "")
case "thetvdb", "thetvdb/series": case "thetvdb", "thetvdb/series":
anime.AddMapping("thetvdb/anime", mapping.Attributes.ExternalID, "") fmt.Println(mapping.Attributes.ExternalSite, mapping.Attributes.ExternalID)
anime.SetMapping("thetvdb/anime", mapping.Attributes.ExternalID, "")
case "thetvdb/season": case "thetvdb/season":
// Ignore // Ignore
default: default:
@ -107,6 +108,17 @@ func sync(data *kitsu.Anime) *arn.Anime {
} }
} }
return anime
// Download image
response, err := client.Get(attr.PosterImage.Original).End()
if err == nil && response.StatusCode() == http.StatusOK {
anime.SetImageBytes(response.Bytes())
} else {
color.Red("No image for [%s] %s (%d)", anime.ID, anime, response.StatusCode())
}
// Rating // Rating
if anime.Rating == nil { if anime.Rating == nil {
anime.Rating = &arn.AnimeRating{} anime.Rating = &arn.AnimeRating{}

View File

@ -33,7 +33,7 @@ func InvokeShellArgs() bool {
panic(errors.New("Anime ID is not the same")) panic(errors.New("Anime ID is not the same"))
} }
anime := sync(kitsuAnime) anime := importKitsuAnime(kitsuAnime)
if verbose { if verbose {
color.Cyan("Kitsu:") color.Cyan("Kitsu:")

View File

@ -10,14 +10,18 @@ import (
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/animenotifier/mal/parser" "github.com/animenotifier/mal/parser"
"github.com/fatih/color"
) )
func main() { func main() {
color.Yellow("Importing MAL anime")
defer arn.Node.Close() defer arn.Node.Close()
defer color.Green("Finished.")
// readFile("../mal-crawler/files/anime-31240.html") // readFile("../mal-download/files/anime-31240.html")
filepath.Walk("../mal-crawler/files", func(name string, info os.FileInfo, err error) error { filepath.Walk("../mal-download/files", func(name string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return err return err

View File

@ -116,5 +116,5 @@ func search(anime *arn.Anime, title string) {
} }
// This will start a goroutine that saves the anime // This will start a goroutine that saves the anime
anime.AddMapping("shoboi/anime", shoboi.TID, "") anime.SetMapping("shoboi/anime", shoboi.TID, "")
} }