Index: Plugins/MusicMagic/Plugin.pm =================================================================== --- Plugins/MusicMagic/Plugin.pm (revision 3657) +++ Plugins/MusicMagic/Plugin.pm (working copy) @@ -383,6 +383,43 @@ return $mmsPath } +sub grabFilters { + + my @filters; + my %filterHash; + + $MMSport = Slim::Utils::Prefs::get('MMSport') unless $MMSport; + $MMSHost = Slim::Utils::Prefs::get('MMSHost') unless $MMSHost; + + $::d_musicmagic && msg("MusicMagic: get filters list\n"); + + my $http = Slim::Player::Protocols::HTTP->new({ + 'url' => "http://$MMSHost:$MMSport/api/filters", + 'create' => 0, + }); + + if ($http) { + @filters = split(/\n/, $http->content()); + $http->close(); + if ($::d_musicmagic) { + msg("MusicMagic: found filters:\n"); + use Data::Dumper; + print Dumper(\@filters); + } + } + + push @filters,"(none)"; + foreach my $filter ( @filters ) { + if ($filter eq "(none)") { + $filterHash{0} = $filter; + next + } + $filterHash{$filter} = $filter; + } + + return %filterHash; +} + sub exportFunction { my $playlist; @@ -766,7 +803,7 @@ if ($currentItem && $currentItem->musicmagic_mixable()) { # For the moment, skip straight to InstantMix mode. (See VarietyCombo) - $mix = getMix(Slim::Utils::Misc::pathFromFileURL($currentItem->{'url'}), 'song'); + $mix = getMix($client,Slim::Utils::Misc::pathFromFileURL($currentItem->{'url'}), 'song'); } # if we've picked an artist @@ -775,7 +812,7 @@ if ($currentItem && $currentItem->musicmagic_mixable()) { # For the moment, skip straight to InstantMix mode. (See VarietyCombo) - $mix = getMix($currentItem->name(), 'artist'); + $mix = getMix($client,$currentItem->name(), 'artist'); } # if we've picked an album @@ -799,7 +836,7 @@ Slim::Utils::Misc::pathFromFileURL($currentItem->{'url'}) : "$artists\@\@$album"; - $mix = getMix($key, 'album'); + $mix = getMix($client,$key, 'album'); } } else { @@ -807,7 +844,7 @@ if ($currentItem && $currentItem->musicmagic_mixable()) { # For the moment, skip straight to InstantMix mode. (See VarietyCombo) - $mix = getMix($currentItem->name(), 'genre'); + $mix = getMix($client,$currentItem->name(), 'genre'); } } @@ -875,6 +912,7 @@ } sub getMix { + my $client = shift; my $id = shift; my $for = shift; @@ -885,12 +923,18 @@ my @type = qw(tracks min mbytes); my %args = ( - size => Slim::Utils::Prefs::get('MMMSize'), # Set the size of the list (default 12) - sizetype => $type[Slim::Utils::Prefs::get('MMMMixType')], # (tracks|min|mb) Set the units for size (default tracks) - style => Slim::Utils::Prefs::get('MMMStyle'), # Set the style slider (default 20) - variety => Slim::Utils::Prefs::get('MMMVariety'), # Set the variety slider (default 0) + size => Slim::Utils::Prefs::clientGet($client,'MMMSize') || Slim::Utils::Prefs::get('MMMSize'), # Set the size of the list (default 12) + sizetype => $type[Slim::Utils::Prefs::clientGet($client,'MMMMixType') || Slim::Utils::Prefs::get('MMMMixType')], # (tracks|min|mb) Set the units for size (default tracks) + style => Slim::Utils::Prefs::clientGet($client,'MMMStyle') || Slim::Utils::Prefs::get('MMMStyle'), # Set the style slider (default 20) + variety => Slim::Utils::Prefs::clientGet($client,'MMMVariety') || Slim::Utils::Prefs::get('MMMVariety'), # Set the variety slider (default 0) ); + my $filter = Slim::Utils::Prefs::get('MMMFilter'); + if ($filter ne '0') { + $::d_musicmagic && msg("MusicMagic: filter $filter in use.\n"); + $args{filter} = $filter; + } + my $argString = join( '&', map { "$_=$args{$_}" } keys %args ); if ($for eq "song") { @@ -902,7 +946,7 @@ } elsif ($for eq "genre") { $mixArgs = "genre=$id"; } else { - $::d_musicmagic && msg("MusicMagic no valid type specified for mix"); + $::d_musicmagic && msg("MusicMagic: no valid type specified for mix\n"); return undef; } @@ -981,7 +1025,7 @@ if ($obj->musicmagic_mixable) { # For the moment, skip straight to InstantMix mode. (See VarietyCombo) - $mix = getMix(Slim::Utils::Misc::pathFromFileURL($obj->url), 'song'); + $mix = getMix($client,Slim::Utils::Misc::pathFromFileURL($obj->url), 'song'); } $params->{'src_mix'} = Slim::Music::Info::standardTitle(undef, $obj); @@ -994,7 +1038,7 @@ if ($obj && $obj->musicmagic_mixable()) { # For the moment, skip straight to InstantMix mode. (See VarietyCombo) - $mix = getMix($obj->name(), 'artist'); + $mix = getMix($client,$obj->name(), 'artist'); } } elsif (defined $album && $album ne "") { @@ -1013,7 +1057,7 @@ Slim::Utils::Misc::pathFromFileURL($trackObj->url) : join('@@', $artistObj->name, $obj->title); - $mix = getMix($key, 'album'); + $mix = getMix($client,$key, 'album'); } } @@ -1024,7 +1068,7 @@ if ($obj && $obj->musicmagic_mixable()) { # For the moment, skip straight to InstantMix mode. (See VarietyCombo) - $mix = getMix($obj->name, 'genre'); + $mix = getMix($client,$obj->name, 'genre'); } } else { @@ -1130,7 +1174,7 @@ }; sub setupCategory { - + my %setupCategory = ( 'title' => Slim::Utils::Strings::string('SETUP_MUSICMAGIC'), @@ -1139,7 +1183,7 @@ 'Groups' => { 'Default' => { - 'PrefOrder' => [qw(MMMSize MMMMixType MMMStyle MMMVariety musicmagicscaninterval MMSport)] + 'PrefOrder' => [qw(MMMSize MMMMixType MMMStyle MMMVariety MMMFilter musicmagicscaninterval MMSport)] # disable remote host access, its confusing and only works in specific cases # leave it here for hackers who really want to try it @@ -1177,6 +1221,12 @@ 'validateArgs' => [0,undef,1000], }, + ,'MMMFilter' => { + 'validate' => \&Slim::Web::Setup::validateInHash + ,'validateArgs' => [\&grabFilters] + ,'options' => {grabFilters()} + }, + 'MMMSize' => { 'validate' => \&Slim::Web::Setup::validateInt, 'validateArgs' => [1,undef,1] Index: strings.txt =================================================================== --- strings.txt (revision 3657) +++ strings.txt (working copy) @@ -2137,6 +2137,12 @@ EN Choose Mix Size ES Elegir tamaƱo de Mezcla +SETUP_MMMFILTER + EN MusicMagic Mix Filter + +SETUP_MMMFILTER_DESC + EN You can create named sets of filter conditions in MusicMagic and choose from the list here to apply those filters to MusicMagic Mixes in SlimServer. + SETUP_MMSHOST EN MusicMagic HTTP Host ES Host HTTP de MusicMagic