-
Notifications
You must be signed in to change notification settings - Fork 8
/
LastMix.pm
64 lines (44 loc) · 1.34 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::Deezer::LastMix;
use strict;
use base qw(Plugins::LastMix::Services::Base);
use Slim::Utils::Log;
my $log = logger('plugin.deezer');
sub isEnabled {
my ($class, $client) = @_;
return unless $client;
return unless Slim::Utils::PluginManager->isEnabled('Plugins::Deezer::Plugin');
require Plugins::Deezer::API;
return Plugins::Deezer::API::->getSomeUserId() ? 'Deezer' : undef;
}
sub lookup {
my ($class, $client, $cb, $args) = @_;
$class->client($client) if $client;
$class->cb($cb) if $cb;
$class->args($args) if $args;
Plugins::Deezer::Plugin::getAPIHandler($client)->search(sub {
my $tracks = shift;
if (!$tracks) {
$class->cb->();
}
my $candidates = [];
my $searchArtist = $class->args->{artist};
my $ct = Plugins::Deezer::API::getFormat();
for my $track ( @$tracks ) {
next unless $track->{artist} && $track->{id} && $track->{title} && $track->{artist}->{name};
push @$candidates, {
title => $track->{title},
artist => $track->{artist}->{name},
url => "deezer://$track->{id}.$ct",
};
}
my $track = $class->extractTrack($candidates);
main::INFOLOG && $log->is_info && $track && $log->info("Found $track for: $args->{title} - $args->{artist}");
$class->cb->($track);
}, {
type => 'track',
search => $args->{title},
limit => 20,
});
}
sub protocol { 'deezer' }
1;