MusicMagic: add genre exclusion filter for MusicIP mixes - #1612
Conversation
Lets users select one or more local library genres to exclude from MusicIP mix results, configurable globally and per-player. Since exclusion happens after MusicIP has already picked the mix, request extra tracks up front and trim back to the configured size so exclusions don't leave mixes short. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Jon Stahl <jonstahl@gmail.com>
michaelherger
left a comment
There was a problem hiding this comment.
Never mind my comment... Consider them informational. I'll fix that on my end. Thanks!
| my $selected = $params->{'pref_mix_genre_filter'}; | ||
| my @genres = ref $selected eq 'ARRAY' ? @$selected : (defined $selected ? ($selected) : ()); | ||
|
|
||
| $cprefs->set('mix_genre_filter', \@genres); |
There was a problem hiding this comment.
You could simplify this by setting $params->{'pref_mix_genre_filter'} to the list ref, then leave the storing to $class->SUPER::handler($client, $params). That way you wouldn't have to deal with $cprefs at all.
I'm going to push a small change which will make ClientSettings inherit from Settings. That way you will only have to implement this in Settings.pm.
|
|
||
| my $url = Slim::Utils::Misc::fileURLFromPath($songs[$j]); | ||
|
|
||
| if (%genreFilterHash && _trackHasExcludedGenre($url, \%genreFilterHash)) { |
There was a problem hiding this comment.
%genreFilterHash will always be truthy. What you really want to do here is to check whether it's empty or not: if (keys %genreFilterHash && ...). Or do the check first thing in _trackHasExcludedGenre().
|
|
||
| sub _trackHasExcludedGenre { | ||
| my ($url, $genreFilterHash) = @_; | ||
|
|
There was a problem hiding this comment.
return unless $url && keys %$genreFilterHash;
| ($prefs->client($client)->get('mix_genre_filter') || $prefs->get('mix_genre_filter')) : | ||
| $prefs->get('mix_genre_filter'); | ||
|
|
||
| my %genreFilterHash = map { lc($_) => 1 } @{ $genreFilter || [] }; |
There was a problem hiding this comment.
If you make this a hash ref right on, you won't have to reference it further down:
my $genreFilterHash = { map { lc($_) => 1 } @{ $genreFilter || [] } };|
|
||
| [% FOREACH genre = genre_list %] | ||
|
|
||
| <option [% IF prefs.pref_mix_genre_filter.item(genre) %]selected [% END %]value="[% genre | html %]">[% genre | html %]</option> |
There was a problem hiding this comment.
Did this work for you? prefs.pref_mix_genre_filter.item() would expect a numerical index value, rather than the genre name.
There was a problem hiding this comment.
Never mind - was caused by my own changes...
|
As mentioned before, I re-factored some of the plugin. Please let me know if you encounter any issue. Thanks! |
Summary
Why not the existing "Mix Filter" setting?
MusicMagic already has a "Mix Filter" option, but it doesn't cover this case:
/filtersAPI) — there's no way to build or edit one from within Lyrion, and it's one filter at a time, not an arbitrary combinable set of genres.?genre==Rock) that could in principle express a genre condition, but Power Search is an advanced MusicIP feature gated behind an active MusicIP registration/license key, so it's unavailable to a chunk of users and would fail silently for them.This feature instead reads genres directly from the local library (the same list you already browse/see in Lyrion), needs no MusicIP-side setup or paid registration, and supports selecting any number of genres to exclude.
Test plan
🤖 Generated with Claude Code