-
Notifications
You must be signed in to change notification settings - Fork 16
/
Settings.pm
95 lines (71 loc) · 2.45 KB
/
Settings.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package Plugins::Qobuz::Settings;
use strict;
use Digest::MD5 qw(md5_hex);
use base qw(Slim::Web::Settings);
use Slim::Utils::Prefs;
use Slim::Utils::Log;
my $log = logger('plugin.qobuz');
my $prefs = preferences('plugin.qobuz');
sub name {
return Slim::Web::HTTP::CSRF->protectName('PLUGIN_QOBUZ');
}
sub page {
return Slim::Web::HTTP::CSRF->protectURI('plugins/Qobuz/settings/basic.html');
}
sub prefs {
return ($prefs, 'filterSearchResults', 'playSamples', 'showComposerWithArtist', 'labelHiResAlbums', 'dontImportPurchases',
'appendVersionToTitle', 'sortFavsAlphabetically', 'sortArtistAlbums', 'showYearWithAlbum', 'useClassicalEnhancements',
'classicalGenres', 'workPlaylistPosition', 'parentalWarning', 'showDiscs', 'preferredFormat', 'groupReleases', 'importWorks');
}
sub handler {
my ($class, $client, $params, $callback, @args) = @_;
# keep track of the user agent for request using the web token
$prefs->set('useragent', $params->{userAgent}) if $params->{userAgent};
my ($deleteId) = map {
/^delete_(.*)/
} grep {
/^delete_.*/
} keys %$params;
my $accounts = $prefs->get('accounts');
if ( $deleteId ) {
delete $accounts->{$deleteId};
$prefs->set('accounts', $accounts);
}
elsif ( $params->{add_account} || $params->{saveSettings} ) {
$params->{'pref_filterSearchResults'} ||= 0;
$params->{'pref_playSamples'} ||= 0;
$params->{'pref_dontImportPurchases'} ||= 0;
foreach my $k (keys %$params) {
next if $k !~ /pref_dontimport_(.*)/;
my $id = $1;
my $account = $accounts->{$id} || next;
if ($params->{$k}) {
$account->{dontimport} = 1;
}
else {
delete $account->{dontimport};
}
}
if ($params->{'username'} && $params->{'password'}) {
my $username = $params->{'username'};
my $password = md5_hex($params->{'password'});
Plugins::Qobuz::API->login($username, $password, sub {
my $token = shift;
if (!$token) {
$params->{'warning'} = Slim::Utils::Strings::string('PLUGIN_QOBUZ_AUTH_FAILED');
}
my $body = $class->SUPER::handler($client, $params);
$callback->( $client, $params, $body, @args );
});
return;
}
}
$class->SUPER::handler($client, $params);
}
sub beforeRender {
my ($class, $params, $client) = @_;
$params->{accounts} = Plugins::Qobuz::API::Common->getAccountList();
$params->{canImporter} = Plugins::Qobuz::Plugin::CAN_IMPORTER;
}
1;
__END__