From dfa72d5df0ef9986225254babc7b7825bdcaa3ac Mon Sep 17 00:00:00 2001
From: Eduard Urbach <e.urbach@gmail.com>
Date: Sat, 1 Jul 2017 23:33:41 +0200
Subject: [PATCH] Improved importer

---
 .../import-old/import-old-matches.go          | 42 ++++++++-----------
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/patches/import-anilist/import-old/import-old-matches.go b/patches/import-anilist/import-old/import-old-matches.go
index d10288a3..de9f5629 100644
--- a/patches/import-anilist/import-old/import-old-matches.go
+++ b/patches/import-anilist/import-old/import-old-matches.go
@@ -11,26 +11,15 @@ import (
 
 // OldMatch ...
 type OldMatch struct {
-	ID            int     `json:"id"`
-	ProviderID    int     `json:"providerId"`
-	Title         string  `json:"title"`
-	ProviderTitle string  `json:"providerTitle"`
-	Similarity    float64 `json:"similarity"`
-	Edited        string  `json:"edited"`
-	EditedBy      string  `json:"editedBy"`
+	ID           int     `json:"id"`
+	ServiceID    int     `json:"providerId"`
+	Title        string  `json:"title"`
+	ServiceTitle string  `json:"providerTitle"`
+	Similarity   float64 `json:"similarity"`
+	Edited       string  `json:"edited"`
+	EditedBy     string  `json:"editedBy"`
 }
 
-// ProviderMatch ...
-type ProviderMatch struct {
-	AnimeID    string `json:"animeId"`
-	ProviderID string `json:"providerId"`
-	Edited     string `json:"edited"`
-	EditedBy   string `json:"editedBy"`
-}
-
-// AniListToAnime ...
-type AniListToAnime ProviderMatch
-
 func main() {
 	matches := []OldMatch{}
 	data, _ := ioutil.ReadFile("MatchKitsu.json")
@@ -43,9 +32,10 @@ func main() {
 		}
 
 		// New match type
-		newMatch := &ProviderMatch{
-			AnimeID:    strconv.Itoa(match.ProviderID),
-			ProviderID: strconv.Itoa(match.ID),
+		newMatch := &arn.AniListToAnime{
+			AnimeID:    strconv.Itoa(match.ServiceID),
+			ServiceID:  strconv.Itoa(match.ID),
+			Similarity: match.Similarity,
 			Edited:     match.Edited,
 			EditedBy:   match.EditedBy,
 		}
@@ -57,9 +47,13 @@ func main() {
 			continue
 		}
 
+		if anime.GetMapping("anilist/anime") != "" {
+			continue
+		}
+
 		anime.Mappings = append(anime.Mappings, &arn.Mapping{
 			Service:   "anilist/anime",
-			ServiceID: newMatch.ProviderID,
+			ServiceID: newMatch.ServiceID,
 			Created:   newMatch.Edited,
 			CreatedBy: newMatch.EditedBy,
 		})
@@ -67,13 +61,13 @@ func main() {
 		// Save
 		fmt.Println(anime.Title.Canonical)
 		arn.PanicOnError(anime.Save())
-		arn.PanicOnError(arn.DB.Set("AniListToAnime", newMatch.ProviderID, newMatch))
+		arn.PanicOnError(arn.DB.Set("AniListToAnime", newMatch.ServiceID, newMatch))
 	}
 }
 
 // AnilistToAnime
 /*
 AnimeID
-ProviderID
+ServiceID
 
 */