Skip to content

Commit

Permalink
include artist for metacritic lists (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
s0up4200 authored May 1, 2023
1 parent 4f68c20 commit 0c85bc7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
28 changes: 21 additions & 7 deletions internal/processor/metacritic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ func (s Service) metacritic(ctx context.Context, cfg *domain.ListConfig, dryRun
return fmt.Errorf(errMsg)
}

var titles []string

green := color.New(color.FgGreen).SprintFunc()
l.Debug().Msgf("fetching titles from %s", green(cfg.URL))

Expand Down Expand Up @@ -74,8 +72,22 @@ func (s Service) metacritic(ctx context.Context, cfg *domain.ListConfig, dryRun
return err
}

var titles []string
var artists []string

for _, album := range data.Albums {
titles = append(titles, album.Title)
artists = append(artists, album.Artist)
}

// Deduplicate artists
uniqueArtists := []string{}
seenArtists := map[string]struct{}{}
for _, artist := range artists {
if _, ok := seenArtists[artist]; !ok {
uniqueArtists = append(uniqueArtists, artist)
seenArtists[artist] = struct{}{}
}
}

for _, filterID := range cfg.Filters {
Expand All @@ -86,6 +98,12 @@ func (s Service) metacritic(ctx context.Context, cfg *domain.ListConfig, dryRun
filterTitles = append(filterTitles, processTitle(title, cfg.MatchRelease)...)
}

filterArtists := []string{}
for _, artist := range uniqueArtists {
filterArtists = append(filterArtists, processTitle(artist, cfg.MatchRelease)...)
}

joinedArtists := strings.Join(filterArtists, ",")
joinedTitles := strings.Join(filterTitles, ",")

l.Trace().Msgf("%s", joinedTitles)
Expand All @@ -95,11 +113,7 @@ func (s Service) metacritic(ctx context.Context, cfg *domain.ListConfig, dryRun
return nil
}

f := autobrr.UpdateFilter{Albums: joinedTitles}

if cfg.MatchRelease {
f = autobrr.UpdateFilter{MatchReleases: joinedTitles}
}
f := autobrr.UpdateFilter{Albums: joinedTitles, Artists: joinedArtists}

if !dryRun {
if err := brr.UpdateFilterByID(ctx, filterID, f); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/autobrr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,6 @@ type Filter struct {
type UpdateFilter struct {
Shows string `json:"shows"`
Albums string `json:"albums"`
Artists string `json:"artists"`
MatchReleases string `json:"match_releases,omitempty"`
}

0 comments on commit 0c85bc7

Please sign in to comment.