-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAPI.pm
72 lines (57 loc) · 1.72 KB
/
API.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
package Plugins::MusicArtistInfo::API;
use strict;
use URI::Escape qw(uri_escape_utf8);
use Slim::Utils::Cache;
use Slim::Utils::Log;
use Slim::Utils::Prefs;
use constant ARTISTIMAGESEARCH_URL => 'https://mai-api.nixda.ch/artist/%s/picture';
# use constant ARTISTIMAGESEARCH_URL => 'http://localhost:8787/artist/%s/picture';
my $cache = Slim::Utils::Cache->new();
my $log = logger('plugin.musicartistinfo');
my $prefs = preferences('plugin.musicartistinfo');
my $xMAICfgString = _initXMAICfgString();
if (!main::SCANNER) {
$prefs->setChange(\&_initXMAICfgString,
'browseArtistPictures',
'lookupArtistPictures',
'lookupAlbumArtistPicturesOnly',
'artistImageFolder',
'saveMissingArtistPicturePlaceholder'
);
}
sub getArtistPhoto {
my ( $class, $client, $cb, $args ) = @_;
my $query = '?mbid=' . $args->{mbid} if $args->{mbid};
Plugins::MusicArtistInfo::Common->call(
sprintf(ARTISTIMAGESEARCH_URL, uri_escape_utf8($args->{artist})) . $query,
sub {
my ($result) = @_;
my $photo;
if ($result && ref $result && (my $url = $result->{picture})) {
$photo = {
url => $url,
};
}
main::INFOLOG && $log->is_info && $log->info(Data::Dump::dump($photo));
$cb->($photo);
},{
cache => 1,
expires => 86400 * 30, # force caching
headers => {
'x-mai-cfg' => $xMAICfgString,
},
# ignoreError => [404],
}
);
}
sub _initXMAICfgString {
return $xMAICfgString = sprintf('sc:%s,ba:%s,la:%s,ma:%s,ac:%s,ph:%s',
main::SCANNER ? 1 : 0,
$prefs->get('browseArtistPictures') ? 1 : 0,
$prefs->get('lookupArtistPictures') ? 1 : 0,
$prefs->get('lookupAlbumArtistPicturesOnly') ? 1 : 0,
$prefs->get('artistImageFolder') ? 1 : 0,
$prefs->get('saveMissingArtistPicturePlaceholder') ? 1 : 0,
);
}
1;