diff --git a/patches/delete-anilist-mappings/delete-custom-anime.go b/patches/delete-anilist-mappings/delete-custom-anime.go new file mode 100644 index 00000000..1160d3f8 --- /dev/null +++ b/patches/delete-anilist-mappings/delete-custom-anime.go @@ -0,0 +1,15 @@ +package main + +import ( + "github.com/animenotifier/arn" +) + +func main() { + for anime := range arn.MustStreamAnime() { + providerID := anime.GetMapping("anilist/anime") + _, err := arn.DB.Delete("AniListToAnime", providerID) + arn.PanicOnError(err) + anime.RemoveMapping("anilist/anime", providerID) + arn.PanicOnError(anime.Save()) + } +} diff --git a/patches/import-anilist/import-old/import-old-matches.go b/patches/import-anilist/import-old/import-old-matches.go new file mode 100644 index 00000000..d10288a3 --- /dev/null +++ b/patches/import-anilist/import-old/import-old-matches.go @@ -0,0 +1,79 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "strconv" + + "github.com/animenotifier/arn" +) + +// 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"` +} + +// 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") + json.Unmarshal(data, &matches) + + for _, match := range matches { + // Custom anime in 3.0 + if match.ID >= 1000000 { + continue + } + + // New match type + newMatch := &ProviderMatch{ + AnimeID: strconv.Itoa(match.ProviderID), + ProviderID: strconv.Itoa(match.ID), + Edited: match.Edited, + EditedBy: match.EditedBy, + } + + // Get anime + anime, err := arn.GetAnime(newMatch.AnimeID) + + if err != nil { + continue + } + + anime.Mappings = append(anime.Mappings, &arn.Mapping{ + Service: "anilist/anime", + ServiceID: newMatch.ProviderID, + Created: newMatch.Edited, + CreatedBy: newMatch.EditedBy, + }) + + // Save + fmt.Println(anime.Title.Canonical) + arn.PanicOnError(anime.Save()) + arn.PanicOnError(arn.DB.Set("AniListToAnime", newMatch.ProviderID, newMatch)) + } +} + +// AnilistToAnime +/* +AnimeID +ProviderID + +*/