Reduced MAL sync complexity
This commit is contained in:
parent
63c3ab894f
commit
fec35059ae
@ -55,36 +55,27 @@ func sync(anime *arn.Anime, malID string) {
|
|||||||
// Log title
|
// Log title
|
||||||
fmt.Printf("%s %s\n", color.CyanString(anime.Title.Canonical), malID)
|
fmt.Printf("%s %s\n", color.CyanString(anime.Title.Canonical), malID)
|
||||||
|
|
||||||
if len(anime.Genres) == 0 && len(malAnime.Genres) > 0 {
|
// Titles
|
||||||
fmt.Println("Genres:", malAnime.Genres)
|
syncTitles(anime, malAnime)
|
||||||
anime.Genres = malAnime.Genres
|
|
||||||
}
|
// Dates
|
||||||
|
syncDates(anime, malAnime)
|
||||||
if anime.EpisodeCount == 0 && malAnime.EpisodeCount != 0 {
|
|
||||||
fmt.Println("EpisodeCount:", malAnime.EpisodeCount)
|
// Episodes
|
||||||
anime.EpisodeCount = malAnime.EpisodeCount
|
syncEpisodes(anime, malAnime)
|
||||||
}
|
|
||||||
|
// Others
|
||||||
if anime.EpisodeLength == 0 && malAnime.EpisodeLength != 0 {
|
syncOthers(anime, malAnime)
|
||||||
fmt.Println("EpisodeLength:", malAnime.EpisodeLength)
|
|
||||||
anime.EpisodeLength = malAnime.EpisodeLength
|
// Characters
|
||||||
}
|
syncCharacters(anime, malAnime)
|
||||||
|
|
||||||
if anime.StartDate == "" && malAnime.StartDate != "" {
|
// Save in database
|
||||||
fmt.Println("StartDate:", malAnime.StartDate)
|
anime.Save()
|
||||||
anime.StartDate = malAnime.StartDate
|
|
||||||
}
|
|
||||||
|
|
||||||
if anime.EndDate == "" && malAnime.EndDate != "" {
|
|
||||||
fmt.Println("EndDate:", malAnime.EndDate)
|
|
||||||
anime.EndDate = malAnime.EndDate
|
|
||||||
}
|
|
||||||
|
|
||||||
if anime.Source == "" && malAnime.Source != "" {
|
|
||||||
fmt.Println("Source:", malAnime.Source)
|
|
||||||
anime.Source = malAnime.Source
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sync titles
|
||||||
|
func syncTitles(anime *arn.Anime, malAnime *mal.Anime) {
|
||||||
if anime.Title.Japanese == "" && malAnime.JapaneseTitle != "" {
|
if anime.Title.Japanese == "" && malAnime.JapaneseTitle != "" {
|
||||||
fmt.Println("JapaneseTitle:", malAnime.JapaneseTitle)
|
fmt.Println("JapaneseTitle:", malAnime.JapaneseTitle)
|
||||||
anime.Title.Japanese = malAnime.JapaneseTitle
|
anime.Title.Japanese = malAnime.JapaneseTitle
|
||||||
@ -94,8 +85,53 @@ func sync(anime *arn.Anime, malID string) {
|
|||||||
fmt.Println("EnglishTitle:", malAnime.EnglishTitle)
|
fmt.Println("EnglishTitle:", malAnime.EnglishTitle)
|
||||||
anime.Title.English = malAnime.EnglishTitle
|
anime.Title.English = malAnime.EnglishTitle
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync dates
|
||||||
|
func syncDates(anime *arn.Anime, malAnime *mal.Anime) {
|
||||||
|
if anime.StartDate == "" && malAnime.StartDate != "" {
|
||||||
|
fmt.Println("StartDate:", malAnime.StartDate)
|
||||||
|
anime.StartDate = malAnime.StartDate
|
||||||
|
}
|
||||||
|
|
||||||
|
if anime.EndDate == "" && malAnime.EndDate != "" {
|
||||||
|
fmt.Println("EndDate:", malAnime.EndDate)
|
||||||
|
anime.EndDate = malAnime.EndDate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync episodes
|
||||||
|
func syncEpisodes(anime *arn.Anime, malAnime *mal.Anime) {
|
||||||
|
if anime.EpisodeCount == 0 && malAnime.EpisodeCount != 0 {
|
||||||
|
fmt.Println("EpisodeCount:", malAnime.EpisodeCount)
|
||||||
|
anime.EpisodeCount = malAnime.EpisodeCount
|
||||||
|
}
|
||||||
|
|
||||||
|
if anime.EpisodeLength == 0 && malAnime.EpisodeLength != 0 {
|
||||||
|
fmt.Println("EpisodeLength:", malAnime.EpisodeLength)
|
||||||
|
anime.EpisodeLength = malAnime.EpisodeLength
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync others
|
||||||
|
func syncOthers(anime *arn.Anime, malAnime *mal.Anime) {
|
||||||
|
if len(anime.Genres) == 0 && len(malAnime.Genres) > 0 {
|
||||||
|
fmt.Println("Genres:", malAnime.Genres)
|
||||||
|
anime.Genres = malAnime.Genres
|
||||||
|
}
|
||||||
|
|
||||||
|
if anime.Source == "" && malAnime.Source != "" {
|
||||||
|
fmt.Println("Source:", malAnime.Source)
|
||||||
|
anime.Source = malAnime.Source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync image
|
||||||
|
func syncImage(anime *arn.Anime, malAnime *mal.Anime) {
|
||||||
|
if (anime.HasImage() && anime.Image.Width > imageWidthThreshold) || malAnime.Image == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!anime.HasImage() || anime.Image.Width <= imageWidthThreshold) && malAnime.Image != "" {
|
|
||||||
fmt.Println("Downloading image:", malAnime.Image)
|
fmt.Println("Downloading image:", malAnime.Image)
|
||||||
response, err := client.Get(malAnime.Image).End()
|
response, err := client.Get(malAnime.Image).End()
|
||||||
|
|
||||||
@ -106,13 +142,7 @@ func sync(anime *arn.Anime, malID string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Characters
|
// Sync characters
|
||||||
syncCharacters(anime, malAnime)
|
|
||||||
|
|
||||||
// Save in database
|
|
||||||
anime.Save()
|
|
||||||
}
|
|
||||||
|
|
||||||
func syncCharacters(anime *arn.Anime, malAnime *mal.Anime) {
|
func syncCharacters(anime *arn.Anime, malAnime *mal.Anime) {
|
||||||
// Check for existence of characters
|
// Check for existence of characters
|
||||||
animeCharacters := anime.Characters()
|
animeCharacters := anime.Characters()
|
||||||
|
Loading…
Reference in New Issue
Block a user