Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(arrs): deduplicate titles #91

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading