-
Notifications
You must be signed in to change notification settings - Fork 9
/
LastMix.pm
64 lines (44 loc) · 1.33 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::TIDAL::LastMix;
use strict;
use base qw(Plugins::LastMix::Services::Base);
use Slim::Utils::Log;
my $log = logger('plugin.tidal');
sub isEnabled {
my ($class, $client) = @_;
return unless $client;
return unless Slim::Utils::PluginManager->isEnabled('Plugins::TIDAL::Plugin');
require Plugins::TIDAL::API;
return Plugins::TIDAL::API::->getSomeUserId() ? 'TIDAL' : undef;
}
sub lookup {
my ($class, $client, $cb, $args) = @_;
$class->client($client) if $client;
$class->cb($cb) if $cb;
$class->args($args) if $args;
Plugins::TIDAL::Plugin::getAPIHandler($client)->search(sub {
my $tracks = shift;
if (!$tracks) {
$class->cb->();
}
my $candidates = [];
my $searchArtist = $class->args->{artist};
my $ct = Plugins::TIDAL::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 => "tidal://$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 => 'tracks',
search => $args->{title},
limit => 20,
});
}
sub protocol { 'tidal' }
1;