Skip to content

Commit

Permalink
fix(arrs): deduplicate titles (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
s0up4200 authored Aug 24, 2024
1 parent f867a2a commit 81446c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
25 changes: 14 additions & 11 deletions internal/processor/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package processor

import (
"context"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -89,7 +90,7 @@ func (s Service) processRadarr(ctx context.Context, cfg *domain.ArrConfig, logge

logger.Debug().Msgf("found %d movies to process", len(movies))

var titles []string
titleSet := make(map[string]struct{})
var monitoredTitles int

for _, movie := range movies {
Expand Down Expand Up @@ -119,20 +120,22 @@ func (s Service) processRadarr(ctx context.Context, cfg *domain.ArrConfig, logge
monitoredTitles++

// Taking the international title and the original title and appending them to the titles array.
titlesMap := make(map[string]bool) // Initialize a map to keep track of unique titles.
t := m.Title
ot := m.OriginalTitle

for _, title := range []string{t, ot} {
if title != "" && !titlesMap[title] {
titlesMap[title] = true
titles = append(titles, processTitle(title, cfg.MatchRelease)...)
for _, title := range []string{m.Title, m.OriginalTitle} {
if title != "" {
for _, t := range processTitle(title, cfg.MatchRelease) {
titleSet[t] = struct{}{}
}
}
}
}

uniqueTitles := make([]string, 0, len(titleSet))
for title := range titleSet {
uniqueTitles = append(uniqueTitles, title)
}

logger.Debug().Msgf("from a total of %d movies we found %d monitored and created %d release titles", len(movies), monitoredTitles, len(titles))
sort.Strings(uniqueTitles)
logger.Debug().Msgf("from a total of %d movies we found %d monitored and created %d release titles", len(movies), monitoredTitles, len(uniqueTitles))

return titles, nil
return uniqueTitles, nil
}
23 changes: 17 additions & 6 deletions internal/processor/sonarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s Service) processSonarr(ctx context.Context, cfg *domain.ArrConfig, logge

logger.Debug().Msgf("found %d shows to process", len(shows))

var titles []string
titleSet := make(map[string]struct{})
var monitoredTitles int

for _, show := range shows {
Expand Down Expand Up @@ -129,17 +129,28 @@ func (s Service) processSonarr(ctx context.Context, cfg *domain.ArrConfig, logge
//titles = append(titles, rls.MustNormalize(s.Title))
//titles = append(titles, rls.MustClean(s.Title))

titles = append(titles, processTitle(s.Title, cfg.MatchRelease)...)
titles := processTitle(s.Title, cfg.MatchRelease)
for _, title := range titles {
titleSet[title] = struct{}{}
}

if !cfg.ExcludeAlternateTitles {
for _, title := range s.AlternateTitles {
titles = append(titles, processTitle(title.Title, cfg.MatchRelease)...)
altTitles := processTitle(title.Title, cfg.MatchRelease)
for _, altTitle := range altTitles {
titleSet[altTitle] = struct{}{}
}
}
}
}

sort.Strings(titles)
logger.Debug().Msgf("from a total of %d shows we found %d monitored and created %d release titles", len(shows), monitoredTitles, len(titles))
uniqueTitles := make([]string, 0, len(titleSet))
for title := range titleSet {
uniqueTitles = append(uniqueTitles, title)
}

sort.Strings(uniqueTitles)
logger.Debug().Msgf("from a total of %d shows we found %d monitored and created %d release titles", len(shows), monitoredTitles, len(uniqueTitles))

return titles, nil
return uniqueTitles, nil
}

0 comments on commit 81446c6

Please sign in to comment.