@@ -20,31 +20,45 @@ func (s Service) lidarr(ctx context.Context, cfg *domain.ArrConfig, dryRun bool,
20
20
21
21
l .Debug ().Msgf ("gathering titles..." )
22
22
23
- titles , err := s .processLidarr (ctx , cfg , & l )
23
+ titles , artists , err := s .processLidarr (ctx , cfg , & l )
24
24
if err != nil {
25
25
return err
26
26
}
27
27
28
28
l .Debug ().Msgf ("got %v filter titles" , len (titles ))
29
29
30
- joinedTitles := strings .Join (titles , "," )
30
+ // Process titles
31
+ var processedTitles []string
32
+ for _ , title := range titles {
33
+ processedTitles = append (processedTitles , processTitle (title , cfg .MatchRelease )... )
34
+ }
31
35
32
- l .Trace ().Msgf ("%v" , joinedTitles )
36
+ // Update filter based on MatchRelease
37
+ var f autobrr.UpdateFilter
38
+ if cfg .MatchRelease {
39
+ joinedTitles := strings .Join (processedTitles , "," )
40
+ if len (joinedTitles ) == 0 {
41
+ return nil
42
+ }
43
+ f = autobrr.UpdateFilter {MatchReleases : joinedTitles }
44
+ } else {
45
+ // Process artists only if MatchRelease is false
46
+ var processedArtists []string
47
+ for _ , artist := range artists {
48
+ processedArtists = append (processedArtists , processTitle (artist , cfg .MatchRelease )... )
49
+ }
33
50
34
- if len (joinedTitles ) == 0 {
35
- return nil
51
+ joinedTitles := strings .Join (processedTitles , "," )
52
+ joinedArtists := strings .Join (processedArtists , "," )
53
+ if len (joinedTitles ) == 0 && len (joinedArtists ) == 0 {
54
+ return nil
55
+ }
56
+ f = autobrr.UpdateFilter {Albums : joinedTitles , Artists : joinedArtists }
36
57
}
37
58
38
59
for _ , filterID := range cfg .Filters {
39
-
40
60
l .Debug ().Msgf ("updating filter: %v" , filterID )
41
61
42
- f := autobrr.UpdateFilter {Albums : joinedTitles }
43
-
44
- if cfg .MatchRelease {
45
- f = autobrr.UpdateFilter {MatchReleases : joinedTitles }
46
- }
47
-
48
62
if ! dryRun {
49
63
if err := brr .UpdateFilterByID (ctx , filterID , f ); err != nil {
50
64
l .Error ().Err (err ).Msgf ("error updating filter: %v" , filterID )
@@ -53,13 +67,12 @@ func (s Service) lidarr(ctx context.Context, cfg *domain.ArrConfig, dryRun bool,
53
67
}
54
68
55
69
l .Debug ().Msgf ("successfully updated filter: %v" , filterID )
56
-
57
70
}
58
71
59
72
return nil
60
73
}
61
74
62
- func (s Service ) processLidarr (ctx context.Context , cfg * domain.ArrConfig , logger * zerolog.Logger ) ([]string , error ) {
75
+ func (s Service ) processLidarr (ctx context.Context , cfg * domain.ArrConfig , logger * zerolog.Logger ) ([]string , [] string , error ) {
63
76
c := starr .New (cfg .Apikey , cfg .Host , 60 * time .Second )
64
77
65
78
if cfg .BasicAuth != nil {
@@ -73,69 +86,43 @@ func (s Service) processLidarr(ctx context.Context, cfg *domain.ArrConfig, logge
73
86
74
87
r := lidarr .New (c )
75
88
76
- // TAGS NOT SUPPORTED FOR ALBUMS APPARENTLY
77
- //
78
- // var tags []*starr.Tag
79
- // if len(cfg.TagsExclude) > 0 || len(cfg.TagsInclude) > 0 {
80
- // t, err := r.GetTagsContext(ctx)
81
- // if err != nil {
82
- // logger.Debug().Msg("could not get tags")
83
- // }
84
- // tags = t
85
- // }
86
-
87
89
albums , err := r .GetAlbumContext (ctx , "" )
88
90
if err != nil {
89
- return nil , err
91
+ return nil , nil , err
90
92
}
91
93
92
- logger .Debug ().Msgf ("found %d releases to process" , len (albums ))
93
-
94
94
var titles []string
95
- var monitoredTitles int
95
+ var artists []string
96
+ seenArtists := make (map [string ]struct {})
96
97
97
98
for _ , album := range albums {
98
- m := album
99
+ if ! album .Monitored {
100
+ continue // Skip unmonitored albums
101
+ }
99
102
100
- // only want monitored
101
- if ! m .Monitored {
102
- continue
103
+ // Fetch the artist details
104
+ artist , err := r .GetArtistByIDContext (ctx , album .ArtistID )
105
+ if err != nil {
106
+ logger .Error ().Err (err ).Msgf ("Error fetching artist details for album: %v" , album .Title )
107
+ continue // Skip this album if there's an error fetching the artist
103
108
}
104
109
105
- // TAGS NOT SUPPORTED FOR ALBUMS APPARENTLY
106
- //
107
- // if len(cfg.TagsInclude) > 0 {
108
- // if len(s.Tags) == 0 {
109
- // continue
110
- // }
111
- // if !containsTag(tags, s.Tags, cfg.TagsInclude) {
112
- // continue
113
- // }
114
- // }
115
- //
116
- // if len(cfg.TagsExclude) > 0 {
117
- // if containsTag(tags, s.Tags, cfg.TagsExclude) {
118
- // continue
119
- // }
120
- // }
121
-
122
- // increment monitored titles
123
- monitoredTitles ++
124
-
125
- //titles = append(titles, rls.MustNormalize(m.Title))
126
- //titles = append(titles, rls.MustNormalize(m.OriginalTitle))
127
- //titles = append(titles, rls.MustClean(m.Title))
128
-
129
- titles = append (titles , processTitle (m .Title , cfg .MatchRelease )... )
130
-
131
- // titles = append(titles, processTitle(m.OriginalTitle)...)
132
-
133
- //for _, title := range m.AlternateTitles {
134
- // titles = append(titles, processTitle(title.Title)...)
135
- //}
110
+ if artist .Monitored {
111
+ processedTitles := processTitle (album .Title , cfg .MatchRelease )
112
+ titles = append (titles , processedTitles ... )
113
+
114
+ // Debug logging
115
+ logger .Debug ().Msgf ("Processing artist: %s" , artist .ArtistName )
116
+
117
+ if _ , exists := seenArtists [artist .ArtistName ]; ! exists {
118
+ artists = append (artists , artist .ArtistName )
119
+ seenArtists [artist .ArtistName ] = struct {}{}
120
+ logger .Debug ().Msgf ("Added artist: %s" , artist .ArtistName ) // Log when an artist is added
121
+ }
122
+ }
136
123
}
137
124
138
- logger .Debug ().Msgf ("from a total of %d releases we found %d monitored and created %d release titles " , len (albums ), monitoredTitles , len (titles ))
125
+ logger .Debug ().Msgf ("Processed %d monitored albums with monitored artists, created %d titles, found %d unique artists " , len (titles ), len ( titles ) , len (artists ))
139
126
140
- return titles , nil
127
+ return titles , artists , nil
141
128
}
0 commit comments