170 lines
4.5 KiB
Go
Raw Normal View History

2018-04-26 18:54:39 +00:00
package editor
import (
2019-05-27 09:08:42 +00:00
"github.com/akyoto/hash"
2018-04-26 18:54:39 +00:00
"github.com/animenotifier/mal"
2019-06-07 01:03:16 +00:00
"github.com/animenotifier/notify.moe/arn"
2018-04-26 18:54:39 +00:00
"github.com/animenotifier/notify.moe/utils"
"github.com/animenotifier/notify.moe/utils/animediff"
)
// diff titles
func diffTitles(anime *arn.Anime, malAnime *mal.Anime) []animediff.Difference {
var differences []animediff.Difference
// Canonical title
if anime.Title.Canonical != malAnime.Title {
2019-05-27 09:08:42 +00:00
hash := hash.String(malAnime.Title)
2018-04-26 18:54:39 +00:00
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "CanonicalTitle", hash) {
differences = append(differences, &animediff.CanonicalTitle{
TitleA: anime.Title.Canonical,
TitleB: malAnime.Title,
NumericHash: hash,
})
}
}
// Japanese title
if anime.Title.Japanese != malAnime.JapaneseTitle {
2019-05-27 09:08:42 +00:00
hash := hash.String(malAnime.JapaneseTitle)
2018-04-26 18:54:39 +00:00
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "JapaneseTitle", hash) {
differences = append(differences, &animediff.JapaneseTitle{
TitleA: anime.Title.Japanese,
TitleB: malAnime.JapaneseTitle,
NumericHash: hash,
})
}
}
// Romaji title
if anime.Title.Romaji != malAnime.Title {
2019-05-27 09:08:42 +00:00
hash := hash.String(malAnime.Title)
2018-04-26 18:54:39 +00:00
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "RomajiTitle", hash) {
differences = append(differences, &animediff.RomajiTitle{
TitleA: anime.Title.Romaji,
TitleB: malAnime.Title,
NumericHash: hash,
})
}
}
return differences
}
// diff dates
func diffDates(anime *arn.Anime, malAnime *mal.Anime) []animediff.Difference {
var differences []animediff.Difference
// Airing start date
if anime.StartDate != malAnime.StartDate && malAnime.StartDate != "" {
2019-05-27 09:08:42 +00:00
hash := hash.String(malAnime.StartDate)
2018-04-26 18:54:39 +00:00
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "StartDate", hash) {
differences = append(differences, &animediff.StartDate{
DateA: anime.StartDate,
DateB: malAnime.StartDate,
NumericHash: hash,
})
}
}
// Airing end date
if anime.EndDate != malAnime.EndDate && malAnime.EndDate != "" {
2019-05-27 09:08:42 +00:00
hash := hash.String(malAnime.EndDate)
2018-04-26 18:54:39 +00:00
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "EndDate", hash) {
differences = append(differences, &animediff.EndDate{
DateA: anime.EndDate,
DateB: malAnime.EndDate,
NumericHash: hash,
})
}
}
return differences
}
// diff episodes
func diffEpisodes(anime *arn.Anime, malAnime *mal.Anime) []animediff.Difference {
var differences []animediff.Difference
// EpisodeCount
if malAnime.EpisodeCount != 0 && anime.EpisodeCount != malAnime.EpisodeCount {
hash := uint64(malAnime.EpisodeCount)
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "EpisodeCount", hash) {
differences = append(differences, &animediff.EpisodeCount{
EpisodesA: anime.EpisodeCount,
EpisodesB: malAnime.EpisodeCount,
NumericHash: hash,
})
}
}
return differences
}
// diff status
func diffStatus(anime *arn.Anime, malAnime *mal.Anime) []animediff.Difference {
var differences []animediff.Difference
// Status
if anime.Status != malAnime.Status {
2019-05-27 09:08:42 +00:00
hash := hash.String(malAnime.Status)
2018-04-26 18:54:39 +00:00
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "Status", hash) {
differences = append(differences, &animediff.Status{
StatusA: anime.Status,
StatusB: malAnime.Status,
NumericHash: hash,
})
}
}
return differences
}
// diff synopsis
func diffSynopsis(anime *arn.Anime, malAnime *mal.Anime) []animediff.Difference {
var differences []animediff.Difference
// Synopsis
if len(anime.Summary) < 300 && len(anime.Summary)+50 < len(malAnime.Synopsis) {
2019-05-27 09:08:42 +00:00
hash := hash.String(malAnime.Synopsis)
2018-04-26 18:54:39 +00:00
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "Synopsis", hash) {
differences = append(differences, &animediff.Synopsis{
SynopsisA: anime.Summary,
SynopsisB: malAnime.Synopsis,
NumericHash: hash,
})
}
}
return differences
}
// diff genres
func diffGenres(anime *arn.Anime, malAnime *mal.Anime) []animediff.Difference {
var differences []animediff.Difference
// Compare genres
hashA := utils.HashStringsNoOrder(anime.Genres)
hashB := utils.HashStringsNoOrder(malAnime.Genres)
if hashA != hashB {
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "Genres", hashB) {
differences = append(differences, &animediff.Genres{
GenresA: anime.Genres,
GenresB: malAnime.Genres,
NumericHash: hashB,
})
}
}
return differences
}