-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSettings.pm
72 lines (55 loc) · 2.05 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
package Plugins::TIDAL::Settings;
use strict;
use base qw(Slim::Web::Settings);
use JSON::XS::VersionOneAndTwo;
use HTTP::Status qw(RC_MOVED_TEMPORARILY);
use Slim::Utils::Prefs;
use Plugins::TIDAL::Settings::Auth;
my $prefs = preferences('plugin.tidal');
my $log = Slim::Utils::Log::logger('plugin.tidal');
sub name { Slim::Web::HTTP::CSRF->protectName('PLUGIN_TIDAL_NAME') }
sub page { Slim::Web::HTTP::CSRF->protectURI('plugins/TIDAL/settings.html') }
sub prefs { return ($prefs, qw(quality countryCode)) }
sub handler {
my ($class, $client, $params, $callback, $httpClient, $response) = @_;
if ($params->{addAccount}) {
$response->code(RC_MOVED_TEMPORARILY);
$response->header('Location' => 'auth.html');
return Slim::Web::HTTP::filltemplatefile($class->page, $params);
}
if ( my ($deleteAccount) = map { /delete_(.*)/; $1 } grep /^delete_/, keys %$params ) {
my $accounts = $prefs->get('accounts') || {};
delete $accounts->{$deleteAccount};
$prefs->set('accounts', $accounts);
}
if ($params->{saveSettings}) {
my $dontImportAccounts = $prefs->get('dontImportAccounts') || {};
my $explicitAlbumHandling = $prefs->get('explicitAlbumHandling') || {};
foreach my $prefName (keys %$params) {
if ($prefName =~ /^pref_dontimport_(.*)/) {
$dontImportAccounts->{$1} = $params->{$prefName};
}
elsif ($prefName =~ /^pref_explicit_(.*)/) {
$explicitAlbumHandling->{$1} = $params->{$prefName} || 0;
}
}
$prefs->set('dontImportAccounts', $dontImportAccounts);
$prefs->set('explicitAlbumHandling', $explicitAlbumHandling);
}
return $class->SUPER::handler($client, $params);
}
sub beforeRender {
my ($class, $params) = @_;
my $accounts = $prefs->get('accounts') || {};
$params->{credentials} = [ sort {
$a->{name} cmp $b->{name}
} map {
{
name => Plugins::TIDAL::API->getHumanReadableName($_),
id => $_->{userId},
}
} values %$accounts] if scalar keys %$accounts;
$params->{dontImportAccounts} = $prefs->get('dontImportAccounts') || {};
$params->{explicitAlbumHandling} = $prefs->get('explicitAlbumHandling') || {};
}
1;