Added tool to fix duplicate TVDB mappings
This commit is contained in:
parent
be44f7e37c
commit
3bc3a2f892
@ -11,16 +11,16 @@ func DuplicateMappings(ctx *aero.Context) string {
|
||||
ctx,
|
||||
"Anime with duplicate mappings",
|
||||
func(anime *arn.Anime) bool {
|
||||
all := map[string]bool{}
|
||||
existing := map[string]bool{}
|
||||
|
||||
for _, mapping := range anime.Mappings {
|
||||
_, exists := all[mapping.Service]
|
||||
_, exists := existing[mapping.Service]
|
||||
|
||||
if exists {
|
||||
return true
|
||||
}
|
||||
|
||||
all[mapping.Service] = true
|
||||
existing[mapping.Service] = true
|
||||
}
|
||||
|
||||
return false
|
52
patches/fix-tvdb-duplicates/fix-tvdb-duplicates.go
Normal file
52
patches/fix-tvdb-duplicates/fix-tvdb-duplicates.go
Normal 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.")
|
||||
}
|
Loading…
Reference in New Issue
Block a user