-
Notifications
You must be signed in to change notification settings - Fork 24
/
LastMix.pm
64 lines (43 loc) · 1.31 KB
/
LastMix.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package Plugins::Spotty::LastMix;
use strict;
use base qw(Plugins::LastMix::Services::Base);
use Slim::Utils::Prefs;
use Plugins::Spotty::Plugin;
my $prefs = preferences('plugin.spotty');
sub isEnabled {
my ($class, $client) = @_;
return unless $client;
return unless Slim::Utils::PluginManager->isEnabled('Plugins::Spotty::Plugin');
return Plugins::Spotty::AccountHelper->getCredentials($client) ? 'Spotty' : undef;
}
sub lookup {
my ($class, $client, $cb, $args) = @_;
$class->client($client) if $client;
$class->cb($cb) if $cb;
$class->args($args) if $args;
Plugins::Spotty::Plugin->getAPIHandler($client)->search(sub {
my $searchResult = shift;
if (!$searchResult) {
$class->cb->();
}
my $candidates = [];
my $searchArtist = $class->args->{artist};
for my $track ( @$searchResult ) {
next unless $track->{artists} && ref $track->{artists} && $track->{uri} && $track->{name};
# might want to investigate them all?
my $artist = $track->{artists}->[0]->{name} || next;
push @$candidates, {
title => $track->{name},
artist => $artist,
url => $track->{uri},
};
}
$class->cb->( $class->extractTrack($candidates) );
},{
query => sprintf("artist:%s track:%s", $args->{artist}, $args->{title}),
type => 'track',
limit => 5,
});
}
sub protocol { 'spotify' }
1;