-
Notifications
You must be signed in to change notification settings - Fork 4
/
Settings.pm
62 lines (46 loc) · 1.53 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
package Plugins::RadioParadise::Settings;
use strict;
use base qw(Slim::Web::Settings);
use Slim::Utils::Prefs;
use Slim::Utils::Log;
use Plugins::RadioParadise::Favorites;
use Plugins::RadioParadise::Stations;
my $prefs = preferences('plugin.radioparadise');
sub name {
return Slim::Web::HTTP::CSRF->protectName('PLUGIN_RADIO_PARADISE');
}
sub page {
return Slim::Web::HTTP::CSRF->protectURI('plugins/RadioParadise/settings.html');
}
sub prefs {
return ($prefs, qw(showInRadioMenu replayGain));
}
sub handler {
my ($class, $client, $params, $callback, @args) = @_;
if ( grep /^delete_creds$/, keys %$params ) {
Plugins::RadioParadise::Favorites->signOut();
Plugins::RadioParadise::Stations->init();
}
if ($params->{'saveSettings'} && $params->{'rp_username'} && $params->{'rp_password'}) {
Plugins::RadioParadise::Favorites->signIn($params->{'rp_username'}, $params->{'rp_password'}, sub {
Plugins::RadioParadise::Stations->init();
$callback->( $client, $params, $class->SUPER::handler($client, $params), @args );
});
return;
}
return $class->SUPER::handler($client, $params);
}
sub beforeRender {
my ($class, $params, $client) = @_;
if (my $expires = Plugins::RadioParadise::Favorites->isSignedIn()) {
$params->{rp_valid_thru} = Slim::Utils::DateTime::shortDateF($expires);
Slim::Networking::Async::HTTP->cookie_jar->scan(sub {
my (undef, $name, $value, undef, $domain) = @_;
if ($domain =~ /\bradioparadise\.com/ && lc($name) eq 'c_username') {
$params->{rp_username} = $value;
}
});
}
}
1;
__END__