Skip to content
This repository was archived by the owner on Dec 26, 2024. It is now read-only.

Commit 81446c6

Browse files
authored
fix(arrs): deduplicate titles (#91)
1 parent f867a2a commit 81446c6

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

internal/processor/radarr.go

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package processor
22

33
import (
44
"context"
5+
"sort"
56
"strings"
67
"time"
78

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

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

92-
var titles []string
93+
titleSet := make(map[string]struct{})
9394
var monitoredTitles int
9495

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

121122
// Taking the international title and the original title and appending them to the titles array.
122-
titlesMap := make(map[string]bool) // Initialize a map to keep track of unique titles.
123-
t := m.Title
124-
ot := m.OriginalTitle
125-
126-
for _, title := range []string{t, ot} {
127-
if title != "" && !titlesMap[title] {
128-
titlesMap[title] = true
129-
titles = append(titles, processTitle(title, cfg.MatchRelease)...)
123+
for _, title := range []string{m.Title, m.OriginalTitle} {
124+
if title != "" {
125+
for _, t := range processTitle(title, cfg.MatchRelease) {
126+
titleSet[t] = struct{}{}
127+
}
130128
}
131129
}
130+
}
132131

132+
uniqueTitles := make([]string, 0, len(titleSet))
133+
for title := range titleSet {
134+
uniqueTitles = append(uniqueTitles, title)
133135
}
134136

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

137-
return titles, nil
140+
return uniqueTitles, nil
138141
}

internal/processor/sonarr.go

+17-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (s Service) processSonarr(ctx context.Context, cfg *domain.ArrConfig, logge
9797

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

100-
var titles []string
100+
titleSet := make(map[string]struct{})
101101
var monitoredTitles int
102102

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

132-
titles = append(titles, processTitle(s.Title, cfg.MatchRelease)...)
132+
titles := processTitle(s.Title, cfg.MatchRelease)
133+
for _, title := range titles {
134+
titleSet[title] = struct{}{}
135+
}
133136

134137
if !cfg.ExcludeAlternateTitles {
135138
for _, title := range s.AlternateTitles {
136-
titles = append(titles, processTitle(title.Title, cfg.MatchRelease)...)
139+
altTitles := processTitle(title.Title, cfg.MatchRelease)
140+
for _, altTitle := range altTitles {
141+
titleSet[altTitle] = struct{}{}
142+
}
137143
}
138144
}
139145
}
140146

141-
sort.Strings(titles)
142-
logger.Debug().Msgf("from a total of %d shows we found %d monitored and created %d release titles", len(shows), monitoredTitles, len(titles))
147+
uniqueTitles := make([]string, 0, len(titleSet))
148+
for title := range titleSet {
149+
uniqueTitles = append(uniqueTitles, title)
150+
}
151+
152+
sort.Strings(uniqueTitles)
153+
logger.Debug().Msgf("from a total of %d shows we found %d monitored and created %d release titles", len(shows), monitoredTitles, len(uniqueTitles))
143154

144-
return titles, nil
155+
return uniqueTitles, nil
145156
}

0 commit comments

Comments
 (0)