Skip to content

Commit

Permalink
Merge pull request #47 from tphoney/music_playlist_fix
Browse files Browse the repository at this point in the history
(fix) improve music playlist matching
  • Loading branch information
tphoney committed Jun 21, 2024
2 parents f1482fa + 156f141 commit 185243f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tphoney/plex-lookup

go 1.22
go 1.22.1

require (
github.com/michiwend/gomusicbrainz v0.0.0-20181012083520-6c07e13dd396
Expand Down
8 changes: 7 additions & 1 deletion plex/plex.go
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,13 @@ func extractArtistsFromPlaylist(xmlString string) (playlistItems []types.PlexMus
RatingKey: container.Track[i].GrandparentRatingKey,
Albums: []types.PlexMusicAlbum{album},
}
} else if !slices.Contains(artists[container.Track[i].GrandparentTitle].Albums, album) {
}
// get the ratingKeys from the albums
albumkeys := []string{}
for j := range artists[container.Track[i].GrandparentTitle].Albums {
albumkeys = append(albumkeys, artists[container.Track[i].GrandparentTitle].Albums[j].RatingKey)
}
if !slices.Contains(albumkeys, album.RatingKey) {
foundArtist.Albums = append(artists[container.Track[i].GrandparentTitle].Albums, album) //nolint:gocritic
// replace the artist in the map with the updated artist
artists[container.Track[i].GrandparentTitle] = foundArtist
Expand Down
5 changes: 5 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func CompareAlbumTitles(title1, title2 string) bool {
r = regexp.MustCompile(`\{(.*?)\}`)
title1 = r.ReplaceAllString(title1, "")
title2 = r.ReplaceAllString(title2, "")
// remove plurals ' and ’
r = regexp.MustCompile(`[',’]`)
title1 = r.ReplaceAllString(title1, "")
title2 = r.ReplaceAllString(title2, "")
title1 = r.ReplaceAllString(title1, "")
// strip whitespace
title1 = strings.TrimSpace(title1)
title2 = strings.TrimSpace(title2)
Expand Down
5 changes: 5 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ func Test_albumTitlesMatch(t *testing.T) {
title2: "test album",
want: true,
},
{
title1: "paula's",
title2: "paula’s",
want: true,
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("title1=%s, title2=%s", tt.title1, tt.title2), func(t *testing.T) {
Expand Down

0 comments on commit 185243f

Please sign in to comment.