forked from LMS-Community/plugin-Qobuz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmartMix.pm
73 lines (49 loc) · 1.7 KB
/
SmartMix.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
65
66
67
68
69
70
71
72
73
package Plugins::Qobuz::SmartMix;
use Slim::Utils::Log;
use Slim::Utils::Prefs;
use Plugins::SmartMix::Services;
my $log = logger('plugin.qobuz');
my $prefs = preferences('plugin.qobuz');
sub getId {
my ($class, $client) = @_;
return unless $client;
return unless Slim::Utils::PluginManager->isEnabled('Plugins::Qobuz::Plugin');
return if preferences('plugin.smartmix')->get('disable_Qobuz');
return ( $prefs->get('username') && $prefs->get('password_md5_hash') ) ? 'Qobuz' : undef;
}
sub getUrl {
my $class = shift;
my ($id, $client) = @_;
# we can't handle the id - return a search handler instead
return sub {
$class->resolveUrl(@_);
} if $class->getId($client);
}
sub resolveUrl {
my ($class, $cb, $args) = @_;
Plugins::Qobuz::API->search(sub {
my $searchResult = shift;
if (!$searchResult) {
$cb->();
}
my $candidates = [];
my $searchArtist = $args->{artist};
for my $track ( @{$searchResult->{tracks}->{items}} ) {
next unless $track->{performer} && $track->{id} && $track->{title};
my $artist = '';
$artist = $track->{album}->{artist}->{name} if $track->{album} && $track->{album}->{artist};
$artist = $track->{performer}->{name} if $artist !~ /\Q$searchArtist\E/i;
next unless $artist;
next if $track->{released_at} > time || (!$track->{streamable} && !$prefs->get('playSamples'));
push @$candidates, {
title => $track->{title},
artist => $artist,
url => Plugins::Qobuz::ProtocolHandler->getUrl($track),
};
}
$cb->( Plugins::SmartMix::Services->getUrlFromCandidates($candidates, $args) );
}, $args->{title}, 'tracks', undef, 1);
}
# dealt with in Plugins::SmartMix::Services->getTrackIdFromUrl
sub urlToId {}
1;