Added image parser

This commit is contained in:
Eduard Urbach 2018-04-17 15:28:57 +02:00
parent 0a0cbf6467
commit 03d8414551

View File

@ -3,11 +3,14 @@ package main
import ( import (
"fmt" "fmt"
"github.com/aerogo/http/client"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/animenotifier/mal" "github.com/animenotifier/mal"
"github.com/fatih/color" "github.com/fatih/color"
) )
const malImageLargeWidth = 285
var ( var (
malDB = arn.Node.Namespace("mal").RegisterTypes((*mal.Anime)(nil)) malDB = arn.Node.Namespace("mal").RegisterTypes((*mal.Anime)(nil))
characterFinder = arn.NewCharacterFinder("myanimelist/character") characterFinder = arn.NewCharacterFinder("myanimelist/character")
@ -92,6 +95,17 @@ func sync(anime *arn.Anime, malID string) {
anime.Title.English = malAnime.EnglishTitle anime.Title.English = malAnime.EnglishTitle
} }
if (!anime.HasImage() || anime.Image.Width < malImageLargeWidth) && malAnime.Image != "" {
fmt.Println("Downloading image:", malAnime.Image)
response, err := client.Get(malAnime.Image).End()
if err == nil && response.StatusCode() == 200 {
anime.SetImageBytes(response.Bytes())
} else {
color.Red("Error downloading image")
}
}
// Check for existence of characters // Check for existence of characters
animeCharacters := anime.Characters() animeCharacters := anime.Characters()
modifiedCharacters := false modifiedCharacters := false