Skip to content

Commit

Permalink
Add support for "Global Search".
Browse files Browse the repository at this point in the history
Fix sort order of the "Top Hits" results.
  • Loading branch information
michaelherger committed Feb 28, 2024
1 parent 7bd85bf commit fc2b213
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
75 changes: 47 additions & 28 deletions Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ sub initPlugin {
Slim::Player::ProtocolHandlers->registerHandler('tidal', 'Plugins::TIDAL::ProtocolHandler');
Slim::Music::Import->addImporter('Plugins::TIDAL::Importer', { use => 1 });

Slim::Menu::GlobalSearch->registerInfoProvider( tidalSearch => (
func => \&searchMenu
) );

$class->SUPER::initPlugin(
feed => \&handleFeed,
tag => 'tidal',
Expand Down Expand Up @@ -139,32 +143,16 @@ sub handleFeed {
},{
name => cstring($client, 'SEARCH'),
image => 'html/images/search.png',
type => 'outline',
items => [{
name => cstring($client, 'EVERYTHING'),
type => 'search',
url => \&searchEverything,
},{
name => cstring($client, 'PLAYLISTS'),
type => 'search',
url => \&search,
passthrough => [ { type => 'playlists' } ],
},{
name => cstring($client, 'ARTISTS'),
type => 'search',
url => \&search,
passthrough => [ { type => 'artists' } ],
},{
name => cstring($client, 'ALBUMS'),
type => 'search',
url => \&search,
passthrough => [ { type => 'albums' } ],
},{
name => cstring($client, 'SONGS'),
type => 'search',
url => \&search,
passthrough => [ { type => 'tracks' } ],
}]
type => 'search',
url => sub {
my ($client, $cb, $params) = @_;
my $menu = searchMenu($client, {
search => lc($params->{search})
});
$cb->({
items => $menu->{items}
});
},
},{
name => cstring($client, 'GENRES'),
image => 'html/images/genres.png',
Expand Down Expand Up @@ -218,6 +206,37 @@ sub selectAccount {
$cb->({ items => $items });
}

sub searchMenu {
my ( $client, $tags ) = @_;

my $searchParam = { query => $tags->{search} };

return {
name => cstring($client, 'PLUGIN_TIDAL_NAME'),
items => [{
name => cstring($client, 'EVERYTHING'),
url => \&searchEverything,
passthrough => [ $searchParam ],
},{
name => cstring($client, 'PLAYLISTS'),
url => \&search,
passthrough => [ { %$searchParam, type => 'playlists' } ],
},{
name => cstring($client, 'ARTISTS'),
url => \&search,
passthrough => [ { %$searchParam, type => 'artists' } ],
},{
name => cstring($client, 'ALBUMS'),
url => \&search,
passthrough => [ { %$searchParam, type => 'albums' } ],
},{
name => cstring($client, 'SONGS'),
url => \&search,
passthrough => [ { %$searchParam, type => 'tracks' } ],
}]
};
}

sub getFavoritePlaylists {
my ( $client, $cb, $args, $params ) = @_;

Expand Down Expand Up @@ -448,8 +467,8 @@ sub searchEverything {
push @$items, $item if $item;
}

foreach my $key (sort keys %$result) {
next if $key =~ /videos/ || !$result->{$key}->{totalNumberOfItems};
foreach my $key ("topHit", "playlists", "artists", "albums", "tracks") {
next unless $result->{$key} && $result->{$key}->{totalNumberOfItems};

my $entries = $key ne 'tracks' ?
$result->{$key}->{items} :
Expand Down
2 changes: 1 addition & 1 deletion install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<description>PLUGIN_TIDAL_DESC</description>
<creator>philippe_44, Michael Herger</creator>
<id>16da8158-263f-4347-8125-184372ea5610</id>
<version>0.6.3</version>
<version>0.7.0</version>
<module>Plugins::TIDAL::Plugin</module>
<importmodule>Plugins::TIDAL::Importer</importmodule>
<optionsURL>plugins/TIDAL/settings.html</optionsURL>
Expand Down

0 comments on commit fc2b213

Please sign in to comment.