2018-03-09 03:03:31 +00:00
|
|
|
package editor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
|
2018-03-09 04:12:22 +00:00
|
|
|
"github.com/animenotifier/notify.moe/utils/animediff"
|
|
|
|
|
2018-03-09 03:03:31 +00:00
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
"github.com/animenotifier/mal"
|
|
|
|
"github.com/animenotifier/notify.moe/components"
|
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
|
|
|
)
|
|
|
|
|
2018-03-09 23:25:37 +00:00
|
|
|
const maxCompareMALEntries = 15
|
2018-03-09 03:03:31 +00:00
|
|
|
|
|
|
|
// CompareMAL ...
|
|
|
|
func CompareMAL(ctx *aero.Context) string {
|
|
|
|
user := utils.GetUser(ctx)
|
2018-03-23 00:43:45 +00:00
|
|
|
year := ctx.Get("year")
|
2018-03-10 09:15:05 +00:00
|
|
|
status := ctx.Get("status")
|
2018-04-13 15:55:52 +00:00
|
|
|
season := ctx.Get("season")
|
2018-03-23 00:43:45 +00:00
|
|
|
typ := ctx.Get("type")
|
|
|
|
|
|
|
|
if year == "any" {
|
|
|
|
year = ""
|
|
|
|
}
|
|
|
|
|
2018-04-13 15:55:52 +00:00
|
|
|
if season == "any" {
|
|
|
|
season = ""
|
|
|
|
}
|
|
|
|
|
2018-03-23 00:43:45 +00:00
|
|
|
if status == "any" {
|
|
|
|
status = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if typ == "any" {
|
|
|
|
typ = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
settings := user.Settings()
|
|
|
|
settings.Editor.Filter.Year = year
|
2018-04-13 15:55:52 +00:00
|
|
|
settings.Editor.Filter.Season = season
|
2018-03-23 00:43:45 +00:00
|
|
|
settings.Editor.Filter.Status = status
|
|
|
|
settings.Editor.Filter.Type = typ
|
|
|
|
settings.Save()
|
2018-03-09 03:03:31 +00:00
|
|
|
|
|
|
|
animes := arn.FilterAnime(func(anime *arn.Anime) bool {
|
2018-03-23 00:43:45 +00:00
|
|
|
if year != "" && (len(anime.StartDate) < 4 || anime.StartDate[:4] != year) {
|
2018-03-10 09:15:05 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-03-23 00:43:45 +00:00
|
|
|
if status != "" && anime.Status != status {
|
2018-03-09 03:03:31 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-04-13 15:55:52 +00:00
|
|
|
if season != "" && anime.Season() != season {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-03-23 00:43:45 +00:00
|
|
|
if typ != "" && anime.Type != typ {
|
2018-03-09 03:03:31 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return anime.GetMapping("myanimelist/anime") != ""
|
|
|
|
})
|
|
|
|
|
|
|
|
sort.Slice(animes, func(i, j int) bool {
|
|
|
|
a := animes[i]
|
|
|
|
b := animes[j]
|
|
|
|
|
|
|
|
aPop := a.Popularity.Total()
|
|
|
|
bPop := b.Popularity.Total()
|
|
|
|
|
|
|
|
if aPop == bPop {
|
|
|
|
return a.Title.Canonical < b.Title.Canonical
|
|
|
|
}
|
|
|
|
|
|
|
|
return aPop > bPop
|
|
|
|
})
|
|
|
|
|
2018-04-25 23:46:26 +00:00
|
|
|
comparisons := compare(animes)
|
|
|
|
|
|
|
|
return ctx.HTML(components.CompareMAL(comparisons, year, status, typ, "/editor/mal/diff/anime", user))
|
|
|
|
}
|
|
|
|
|
|
|
|
// compare builds the comparisons to MAL anime entries.
|
|
|
|
func compare(animes []*arn.Anime) []*utils.MALComparison {
|
2018-03-09 03:03:31 +00:00
|
|
|
comparisons := []*utils.MALComparison{}
|
|
|
|
malAnimeCollection := arn.MAL.Collection("Anime")
|
|
|
|
|
|
|
|
for _, anime := range animes {
|
|
|
|
malID := anime.GetMapping("myanimelist/anime")
|
|
|
|
obj, err := malAnimeCollection.Get(malID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
malAnime := obj.(*mal.Anime)
|
2018-03-09 04:12:22 +00:00
|
|
|
var differences []animediff.Difference
|
2018-03-09 03:03:31 +00:00
|
|
|
|
2018-03-09 04:26:34 +00:00
|
|
|
// Canonical title
|
2018-03-09 03:58:36 +00:00
|
|
|
if anime.Title.Canonical != malAnime.Title {
|
2018-03-09 12:42:45 +00:00
|
|
|
hash := utils.HashString(malAnime.Title)
|
|
|
|
|
|
|
|
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "CanonicalTitle", hash) {
|
|
|
|
differences = append(differences, &animediff.CanonicalTitle{
|
2018-03-09 13:48:00 +00:00
|
|
|
TitleA: anime.Title.Canonical,
|
|
|
|
TitleB: malAnime.Title,
|
|
|
|
NumericHash: hash,
|
2018-03-09 12:42:45 +00:00
|
|
|
})
|
|
|
|
}
|
2018-03-09 03:58:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 04:26:34 +00:00
|
|
|
// Japanese title
|
2018-03-09 04:12:22 +00:00
|
|
|
if anime.Title.Japanese != malAnime.JapaneseTitle {
|
2018-03-09 12:42:45 +00:00
|
|
|
hash := utils.HashString(malAnime.JapaneseTitle)
|
|
|
|
|
|
|
|
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "JapaneseTitle", hash) {
|
|
|
|
differences = append(differences, &animediff.JapaneseTitle{
|
2018-03-09 13:48:00 +00:00
|
|
|
TitleA: anime.Title.Japanese,
|
|
|
|
TitleB: malAnime.JapaneseTitle,
|
|
|
|
NumericHash: hash,
|
2018-03-09 12:42:45 +00:00
|
|
|
})
|
|
|
|
}
|
2018-03-09 03:03:31 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 23:25:37 +00:00
|
|
|
// Romaji title
|
|
|
|
if anime.Title.Romaji != malAnime.Title {
|
|
|
|
hash := utils.HashString(malAnime.Title)
|
|
|
|
|
|
|
|
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "RomajiTitle", hash) {
|
|
|
|
differences = append(differences, &animediff.RomajiTitle{
|
|
|
|
TitleA: anime.Title.Romaji,
|
|
|
|
TitleB: malAnime.Title,
|
|
|
|
NumericHash: hash,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Airing start date
|
2018-03-10 09:15:05 +00:00
|
|
|
if anime.StartDate != malAnime.StartDate && malAnime.StartDate != "" {
|
2018-03-09 23:25:37 +00:00
|
|
|
hash := utils.HashString(malAnime.StartDate)
|
|
|
|
|
|
|
|
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 != "" {
|
|
|
|
hash := utils.HashString(malAnime.EndDate)
|
|
|
|
|
|
|
|
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "EndDate", hash) {
|
|
|
|
differences = append(differences, &animediff.EndDate{
|
|
|
|
DateA: anime.EndDate,
|
|
|
|
DateB: malAnime.EndDate,
|
|
|
|
NumericHash: hash,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status
|
|
|
|
if anime.Status != malAnime.Status {
|
|
|
|
hash := utils.HashString(malAnime.Status)
|
|
|
|
|
|
|
|
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "Status", hash) {
|
|
|
|
differences = append(differences, &animediff.Status{
|
|
|
|
StatusA: anime.Status,
|
|
|
|
StatusB: malAnime.Status,
|
|
|
|
NumericHash: hash,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// EpisodeCount
|
2018-03-27 05:38:10 +00:00
|
|
|
if malAnime.EpisodeCount != 0 && anime.EpisodeCount != malAnime.EpisodeCount {
|
2018-03-09 23:25:37 +00:00
|
|
|
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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-09 04:26:34 +00:00
|
|
|
// Synopsis
|
2018-03-10 09:58:46 +00:00
|
|
|
if len(anime.Summary) < 300 && len(anime.Summary)+50 < len(malAnime.Synopsis) {
|
2018-03-09 12:42:45 +00:00
|
|
|
hash := utils.HashString(malAnime.Synopsis)
|
|
|
|
|
|
|
|
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "Synopsis", hash) {
|
|
|
|
differences = append(differences, &animediff.Synopsis{
|
2018-03-09 13:48:00 +00:00
|
|
|
SynopsisA: anime.Summary,
|
|
|
|
SynopsisB: malAnime.Synopsis,
|
|
|
|
NumericHash: hash,
|
2018-03-09 12:42:45 +00:00
|
|
|
})
|
|
|
|
}
|
2018-03-09 04:26:34 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 04:12:22 +00:00
|
|
|
// Compare genres
|
|
|
|
hashA := utils.HashStringsNoOrder(anime.Genres)
|
|
|
|
hashB := utils.HashStringsNoOrder(malAnime.Genres)
|
2018-03-09 03:03:31 +00:00
|
|
|
|
2018-03-09 04:12:22 +00:00
|
|
|
if hashA != hashB {
|
2018-03-09 12:42:45 +00:00
|
|
|
if !arn.IsAnimeDifferenceIgnored(anime.ID, "mal", malAnime.ID, "Genres", hashB) {
|
|
|
|
differences = append(differences, &animediff.Genres{
|
2018-03-09 13:48:00 +00:00
|
|
|
GenresA: anime.Genres,
|
|
|
|
GenresB: malAnime.Genres,
|
|
|
|
NumericHash: hashB,
|
2018-03-09 12:42:45 +00:00
|
|
|
})
|
|
|
|
}
|
2018-03-09 03:03:31 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 03:58:36 +00:00
|
|
|
// Add if there were any differences
|
2018-03-09 03:03:31 +00:00
|
|
|
if len(differences) > 0 {
|
|
|
|
comparisons = append(comparisons, &utils.MALComparison{
|
|
|
|
Anime: anime,
|
|
|
|
MALAnime: malAnime,
|
|
|
|
Differences: differences,
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(comparisons) >= maxCompareMALEntries {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 23:46:26 +00:00
|
|
|
return comparisons
|
2018-03-09 03:03:31 +00:00
|
|
|
}
|