Added tool to fix duplicate TVDB mappings

This commit is contained in:
Eduard Urbach 2018-03-23 04:37:58 +01:00
parent be44f7e37c
commit 3bc3a2f892
2 changed files with 55 additions and 3 deletions

View File

@ -11,16 +11,16 @@ func DuplicateMappings(ctx *aero.Context) string {
ctx, ctx,
"Anime with duplicate mappings", "Anime with duplicate mappings",
func(anime *arn.Anime) bool { func(anime *arn.Anime) bool {
all := map[string]bool{} existing := map[string]bool{}
for _, mapping := range anime.Mappings { for _, mapping := range anime.Mappings {
_, exists := all[mapping.Service] _, exists := existing[mapping.Service]
if exists { if exists {
return true return true
} }
all[mapping.Service] = true existing[mapping.Service] = true
} }
return false return false

View File

@ -0,0 +1,52 @@
package main
import (
"fmt"
"strings"
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
func main() {
defer arn.Node.Close()
for anime := range arn.StreamAnime() {
existing := map[string]string{}
for index, mapping := range anime.Mappings {
if mapping.Service != "thetvdb/anime" {
continue
}
serviceID, exists := existing[mapping.Service]
if exists {
fmt.Println("duplicate:", color.YellowString(mapping.ServiceID), "of", color.YellowString(serviceID))
slashPos := strings.Index(serviceID, "/")
if slashPos != -1 {
serviceID = serviceID[:slashPos]
}
slashPos = strings.Index(mapping.ServiceID, "/")
if slashPos != -1 {
mapping.ServiceID = mapping.ServiceID[:slashPos]
}
if serviceID == mapping.ServiceID {
// Remove duplicate
anime.Mappings = append(anime.Mappings[:index], anime.Mappings[index+1:]...)
anime.Save()
break
}
}
existing[mapping.Service] = mapping.ServiceID
}
}
color.Green("Finished.")
}