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) improve music playlist matching #47

Merged
merged 1 commit into from
Jun 21, 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
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
Loading