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

Commit 74abe8e

Browse files
authored
fix(lidarr): Monitored artists and albums (#69)
* fix(lidarr): Monitored artists and albums * fix(title): trim title if matchRelease=true * fix(lidarr): Remove logging of unmonitored artists
1 parent 7a4740b commit 74abe8e

File tree

2 files changed

+55
-66
lines changed

2 files changed

+55
-66
lines changed

internal/processor/lidarr.go

+53-66
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,45 @@ func (s Service) lidarr(ctx context.Context, cfg *domain.ArrConfig, dryRun bool,
2020

2121
l.Debug().Msgf("gathering titles...")
2222

23-
titles, err := s.processLidarr(ctx, cfg, &l)
23+
titles, artists, err := s.processLidarr(ctx, cfg, &l)
2424
if err != nil {
2525
return err
2626
}
2727

2828
l.Debug().Msgf("got %v filter titles", len(titles))
2929

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+
}
3135

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+
}
3350

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}
3657
}
3758

3859
for _, filterID := range cfg.Filters {
39-
4060
l.Debug().Msgf("updating filter: %v", filterID)
4161

42-
f := autobrr.UpdateFilter{Albums: joinedTitles}
43-
44-
if cfg.MatchRelease {
45-
f = autobrr.UpdateFilter{MatchReleases: joinedTitles}
46-
}
47-
4862
if !dryRun {
4963
if err := brr.UpdateFilterByID(ctx, filterID, f); err != nil {
5064
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,
5367
}
5468

5569
l.Debug().Msgf("successfully updated filter: %v", filterID)
56-
5770
}
5871

5972
return nil
6073
}
6174

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) {
6376
c := starr.New(cfg.Apikey, cfg.Host, 60*time.Second)
6477

6578
if cfg.BasicAuth != nil {
@@ -73,69 +86,43 @@ func (s Service) processLidarr(ctx context.Context, cfg *domain.ArrConfig, logge
7386

7487
r := lidarr.New(c)
7588

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-
8789
albums, err := r.GetAlbumContext(ctx, "")
8890
if err != nil {
89-
return nil, err
91+
return nil, nil, err
9092
}
9193

92-
logger.Debug().Msgf("found %d releases to process", len(albums))
93-
9494
var titles []string
95-
var monitoredTitles int
95+
var artists []string
96+
seenArtists := make(map[string]struct{})
9697

9798
for _, album := range albums {
98-
m := album
99+
if !album.Monitored {
100+
continue // Skip unmonitored albums
101+
}
99102

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
103108
}
104109

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+
}
136123
}
137124

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))
139126

140-
return titles, nil
127+
return titles, artists, nil
141128
}

internal/processor/title.go

+2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ func NewTitleSlice() *Titles {
7979
}
8080

8181
func (ts *Titles) Add(title string, matchRelease bool) {
82+
8283
if matchRelease {
84+
title = strings.Trim(title, "?")
8385
title = fmt.Sprintf("*%v*", title)
8486
}
8587

0 commit comments

Comments
 (0)