-
Notifications
You must be signed in to change notification settings - Fork 235
/
spotify.pl
687 lines (585 loc) · 22.9 KB
/
spotify.pl
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
# spotify.pl - lookup spotify resources
#
# Copyright (c) 2009-2014 Örjan Persson <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
use strict;
use vars qw($VERSION %IRSSI);
$VERSION = '1.1';
%IRSSI = (
authors => 'Örjan Persson',
name => 'spotify',
description => 'Lookup spotify uris',
license => 'GPLv2',
url => 'https://github.com/op/irssi-spotify'
);
use Irssi;
use Encode;
use HTTP::Request::Common;
use HTTP::Request;
use JSON;
use LWP::UserAgent;
use POSIX;
use URI;
sub cmd_spotify_help {
Irssi::print(<<'EOF', MSGLEVEL_CLIENTCRAP);
SPOTIFY [-a | auto] [-l | lookup] [...]
-a, auto: see SPOTIFY AUTO
-l, lookup: see SPOTIFY LOOKUP
Lookup spotify uris to get information on tracks, albums, artists and
playlists. You can configure it to do automatic lookup when someone sends it in
a channel or privately.
Playlist requests require authentication. Get credentials from
https://developer.spotify.com.
/SET spotify_client_id <string>
/SET spotify_client_secret <string>
Output format is customizable.
/SET spotify_header_format <string>
Header message above lookup result. Available variables:
%%uri requested uri
/SET spotify_album_format <string>
Format for album results. Available variables:
%%name name of the album
%%artist album artists
%%year year the album was released
%%popularity album popularity
%%territories territories the album is available in
/SET spotify_artist_format <string>
Format for artist results. Available variables:
%%name name of the artist
%%popularity artist popularity
/SET spotify_track_format <string>
Format for track results. Available variables:
%%name name of the track
%%album name of the album
%%artist track artists
%%popularity track popularity
/SET spotify_playlist_format <string>
Format for playlist results. Available variables:
%%name name of the playlist
%%owner name of the owner
See /SPOTIFY <section> help for more information.
EOF
}
sub cmd_spotify_help_lookup {
Irssi::print(<<'EOF', MSGLEVEL_CLIENTCRAP);
SPOTIFY LOOKUP [-p | public] <resource>
-p, public: return result to current window
-h, help: show this help
Lookup the given resource and return the result. If the public
argument is given, the result is returned to the current window.
EOF
}
sub cmd_spotify_help_auto {
Irssi::print(<<'EOF', MSGLEVEL_CLIENTCRAP);
SPOTIFY AUTO [-p | public] [-i | info] [-e | enable] [-d | disable] [-w | whitelist] [-b | blacklist]
-p, public: see SPOTIFY AUTO PUBLIC
-i, info: display current settings for SPOTIFY AUTO
-e, enable: enable automatic lookup
-d, disable: disable automatic lookup
Configure automatic features. The public section is for
automatic return results in the window the Spotify resource
was sent in.
Info will display settings for all automatic features and
you can use enable or disable to turn automatic functions
on or off.
EOF
}
sub cmd_spotify_help_auto_public {
Irssi::print(<<'EOF', MSGLEVEL_CLIENTCRAP);
SPOTIFY AUTO PUBLIC [OPTION...]
-a, add: add nick or channel to auto list
-d, del: delete nick or channel from auto list
-n, nick: use command on nick list
-c, channel: use command on channel list
-i, info: display current settings for SPOTIFY AUTO
-w, whitelist: treaten list as a whitelist
-b, blacklist: treaten list as a blacklist
Add a nick or channel to search from when matching
Configure automatic features. The public section is for
automatic return results in the window the Spotify resource
was sent in.
Info will display settings for all automatic features and
you can use enable or disable to turn automatic functions
on or off.
You can also set if you want the list of nicks and channels
to be interpretted as a whitelist or blacklist.
EOF
}
sub cmd_help {
my ($args, $server, $window) = @_;
if ($args =~ /^spotify\s*$/) {
cmd_spotify_help();
} elsif ($args =~ /^spotify lookup\s*$/i) {
cmd_spotify_help_lookup();
} elsif ($args =~ /^spotify auto\s*$/i) {
cmd_spotify_help_auto();
} elsif ($args =~ /^spotify auto public\s*$/i) {
cmd_spotify_help_auto_public();
}
}
sub cmd_spotify_lookup {
my ($args, $server, $window) = @_;
my @argv = split(/ /, $args);
my $public = 0;
# Simple parse arguments (debian still has an old version of irssi..)
my $i;
for ($i = 0; $i <= $#argv; $i++) {
if ($argv[$i] eq '-p' || $argv[$i] eq 'public') { $public = 1; }
elsif ($argv[$i] eq '-h' || $argv[$i] eq 'help') {
return Irssi::command_runsub('spotify lookup', $args, $server, $window);
}
else { last; }
}
# Treat the rest as data argument
my $data = join(' ', @argv[$i..$#argv]);
# Make sure we actually have a window reference and check if we can write
if ($public) {
if (!$window) {
Irssi::active_win()->print("Must be run run in a valid window (CHANNEL|QUERY)");
return;
}
} else {
$window = Irssi::active_win();
}
# Dispatch the work to be done
my @worker_args = ($data, 1);
my @output_args = ($server->{tag}, $window->{name}, $public ? $window->{name} : 0);
dispatch(\&spotify_lookup, \@worker_args, \@output_args);
}
sub cmd_spotify_auto {
my ($args, $server, $window) = @_;
if ($args eq 'info' || $args eq '-i') {
my $lookup = Irssi::settings_get_str('spotify_automatic_lookup');
my $lookup_public = Irssi::settings_get_str('spotify_automatic_lookup_public');
my $lookup_public_blacklist = Irssi::settings_get_str('spotify_automatic_lookup_public_blacklist');
my $lookup_public_channels = Irssi::settings_get_str('spotify_automatic_lookup_public_channels');
my $lookup_public_nicks = Irssi::settings_get_str('spotify_automatic_lookup_public_nicks');
my $policy = $lookup_public_blacklist eq 'yes' ? 'disable' : 'enable';
Irssi::print(<<"EOF", MSGLEVEL_CLIENTCRAP);
Spotify automatic settings:
automatic lookup: %_${lookup}%_
automatic lookup to public: %_${lookup_public}%_
interpret list of channels and nicks as blacklist: %_${lookup_public_blacklist}%_
${policy} lookup for channels: %_${lookup_public_channels}%_
${policy} lookup for nicks: %_${lookup_public_nicks}%_
EOF
} elsif ($args eq 'enable' || $args eq '-e') {
Irssi::settings_set_bool('spotify_automatic_lookup', 1);
cmd_spotify_auto('info', $server, $window);
} elsif ($args eq 'disable' || $args eq '-d') {
Irssi::settings_set_bool('spotify_automatic_lookup', 0);
cmd_spotify_auto('info', $server, $window);
} else {
Irssi::command_runsub('spotify auto', $args, $server, $window);
}
}
sub cmd_spotify_auto_public {
my ($args, $server, $window) = @_;
if ($args eq 'info' || $args eq '-i') {
cmd_spotify_auto('info', $server, $window);
} elsif ($args eq 'whitelist' || $args eq '-w') {
Irssi::settings_set_bool('spotify_automatic_lookup_public_blacklist', 0);
cmd_spotify_auto('info', $server, $window);
} elsif ($args eq 'blacklist' || $args eq '-b') {
Irssi::settings_set_bool('spotify_automatic_lookup_public_blacklist', 1);
cmd_spotify_auto('info', $server, $window);
} elsif ($args eq 'enable' || $args eq '-e') {
Irssi::settings_set_bool('spotify_automatic_lookup_public', 1);
cmd_spotify_auto('info', $server, $window);
} elsif ($args eq 'disable' || $args eq '-d') {
Irssi::settings_set_bool('spotify_automatic_lookup_public', 0);
cmd_spotify_auto('info', $server, $window);
} else {
Irssi::command_runsub('spotify auto public', $args, $server, $window);
}
}
sub cmd_spotify_auto_public_add {
my ($args, $server, $window) = @_;
my @argv = split(/ /, $args);
my $type = shift(@argv);
if ($type eq 'channel' || $type eq '-c') {
$type = 'channel';
} elsif ($type eq 'nick' || $type eq '-n') {
$type = 'nick';
} else {
return Irssi::command_runsub('spotify auto public add', $args, $server, $window);
}
my @array = settings_get_array("spotify_automatic_lookup_public_${type}s");
foreach my $arg (@argv) {
push(@array, $arg);
}
settings_set_array("spotify_automatic_lookup_public_${type}s", @array);
cmd_spotify_auto('info', $server, $window);
}
sub cmd_spotify_auto_public_del {
my ($args, $server, $window) = @_;
my @argv = split(/ /, $args);
my $type = shift(@argv);
if ($type eq 'channel' || $type eq '-c') {
$type = 'channel';
} elsif ($type eq 'nick' || $type eq '-n') {
$type = 'nick';
} else {
return Irssi::command_runsub('spotify auto public del', $args, $server, $window);
}
my @array = settings_get_array("spotify_automatic_lookup_public_${type}s");
foreach my $arg (@argv) {
for (my $i = 0; $i <= $#array; $i++) {
if ($array[$i] eq $arg) {
splice(@array, $i, 1);
last;
}
}
}
settings_set_array("spotify_automatic_lookup_public_${type}s", @array);
cmd_spotify_auto('info', $server, $window);
}
sub event_message_topic {
my ($server, $channel, $topic, $nick, $address) = @_;
if ($server->{nick} ne $nick) {
event_message($server, $topic, $nick, $address, $channel);
}
}
sub event_message {
my ($server, $text, $nick, $address, $target) = @_;
if (!Irssi::settings_get_bool('spotify_automatic_lookup')) {
return;
}
# Retrieve window object and decide wether to do lookup public or not
my ($window, $public);
if (!$server->ischannel($target)) {
$window = Irssi::window_item_find($nick);
$public = public_lookup_permitted($nick);
$target = $nick;
} else {
$window = Irssi::window_item_find($target);
$public = public_lookup_permitted($nick, $target);
}
# Dispatch a lookup for each matching uri
my @output_args = ($server->{tag}, $window->{name}, $public ? $target : 0);
while ($text =~ m{(https?://(play|open)\.spotify\.com/|spotify:)[^\s<>\[\]()?]+}g) {
my @worker_args = ($&, 0);
dispatch(\&spotify_lookup, \@worker_args, \@output_args);
}
}
sub dispatch {
my $action = shift;
my @writer_args = @{$_[0]};
my @reader_args = @{$_[1]};
# Create communication between child and main process
my ($reader, $writer);
pipe($reader, $writer);
# Create child process
my $pid = fork();
if ($pid > 0) {
# Main process, close writer and add child pid to waiting list
close($writer);
Irssi::pidwait_add($pid);
# Add reader and input pipe tag to arguments and pass it to
# dispatch_reader when finished
my $input_tag;
unshift(@reader_args, $pid);
unshift(@reader_args, \$input_tag);
unshift(@reader_args, $reader);
# Wait for child to finish and send result to input_reader
$input_tag = Irssi::input_add(fileno($reader), INPUT_READ,
'input_reader', \@reader_args);
} elsif ($pid == 0) {
# Child process, close reader and do the work to be done
close($reader);
my $rc = $action->($writer, \@writer_args) || 0;
close($writer);
POSIX::_exit($rc);
} else {
# Fork error, something nasty must have happened
Irssi::print('spotify: failed to fork(), aborting $cmd.', MSGLEVEL_CLIENTCRAP);
close($reader);
close($writer);
}
}
sub input_reader {
my ($reader, $input_tag, $pid, $server, $window, $target) = @{$_[0]};
my @data = <$reader>;
# Cleanup before doing anything else
close($reader);
Irssi::input_remove($$input_tag);
# Get exit code from child and force non-public output on error
while (waitpid($pid, POSIX::WNOHANG) == 0) {
sleep 1;
}
my $rc = POSIX::WEXITSTATUS($?);
if ($rc) { $target = 0; }
# Find output window
$server = Irssi::server_find_tag($server);
$window = $server ? $server->window_item_find($window) : undef;
if (!defined($window)) {
$window = Irssi::active_win();
}
# Handle result from child
foreach my $line (@data) {
chomp($line);
if ($target) {
# Remove any trace of colors (could probably break things)
$line =~ s/%[krgybmpcwn:|#_]//ig;
$window->command("/NOTICE $target " . $line);
}
else { $window->print($line); }
}
}
sub spotify_lookup {
my $writer = shift;
my ($uri, $manual) = @{$_[0]};
# Remove any leading whitespace and trailing whitespace and dots
$uri =~ s/^\s+//g;
$uri =~ s/[\s\.]+$//g;
# Unify how we look at the path, removing leading / to match how path looks
# for URIs with : where the path never starts with a :.
my $u = URI->new($uri)->path;
$u =~ s/^\///;
my @parts = split /[\/:]/, $u;
my $path;
my $auth;
if ($parts[0] =~ /^(track|album|artist)$/ && @parts == 2) {
$path = "v1/$parts[0]\s/$parts[1]";
} elsif ($parts[0] eq 'user' && @parts == 2) {
$path = "v1/users/$parts[1]";
} elsif ($parts[0] eq 'user' && @parts == 4 && $parts[2] == 'playlist') {
$path = "v1/users/$parts[1]/playlists/$parts[3]";
$auth = 1;
} else {
print($writer "spotify: unsupported URI: $uri");
return 1;
}
my $ua = new LWP::UserAgent(
agent => "spotify.pl/$VERSION",
timeout => 10
);
$ua->env_proxy();
# Fetch access token when needed. The token could be cached and re-used where
# possible. Since we're in a forked process, it's not trivial and probably
# not worth the effort.
my $token;
if ($auth) {
my $request = POST 'https://accounts.spotify.com/api/token', [
grant_type => 'client_credentials',
client_id => Irssi::settings_get_str('spotify_client_id'),
client_secret => Irssi::settings_get_str('spotify_client_secret')
];
my $response = $ua->request($request);
my $content_type = $response->header('Content-Type');
if (index($content_type, 'application/json') == -1) {
my $body = substr $response->decoded_content(), 0, 128;
print($writer "Unsupported content type: $content_type (" . $response->code . "): $body");
return 1;
}
my $result = from_json($response->decoded_content(), {utf8 => 1});
if (defined $result->{error}) {
my $error = $result->{error_description} || $result->{error};
print($writer "Authorization failed: $error (" . $response->code . ")");
return 1;
}
$token = $result->{access_token};
}
my $request = GET 'https://api.spotify.com/' . $path;
if ($token) {
$request->header('Authorization' => 'Bearer ' . $token);
}
my $response = $ua->request($request);
my $content_type = $response->header('Content-Type');
if (index($content_type, 'application/json') == -1) {
my $body = substr $response->decoded_content(), 0, 128;
print($writer "Unsupported content type: $content_type (" . $response->code . "): $body");
return 1;
}
my $result = from_json($response->decoded_content(), {utf8 => 1});
if (defined $result->{error}) {
print($writer "Lookup failed: $result->{error}->{message} (" . $response->code . ")");
return 1;
}
my $message = undef;
my %data;
if ($result->{type} eq 'track') {
$data{'name'} = $result->{name};
$data{'artist'} = artists_str($result->{artists});
$data{'album'} = $result->{album}->{name};
$data{'popularity'} = popularity_str($result->{popularity});
$message = Irssi::settings_get_str('spotify_track_format');
$message =~ s/%(name|artist|album|popularity)/$data{$1}/ge;
} elsif ($result->{type} eq 'album') {
$data{'name'} = $result->{name};
$data{'artist'} = artists_str($result->{artists});
$data{'year'} = substr $result->{release_date}, 0, 4;
$data{'popularity'} = popularity_str($result->{popularity});
$data{'territories'} = join ', ', $result->{available_markets};
$message = Irssi::settings_get_str('spotify_album_format');
$message =~ s/%(name|artist|year|popularity|territories)/$data{$1}/ge;
} elsif ($result->{type} eq 'artist') {
$data{'name'} = $result->{name};
$data{'popularity'} = popularity_str($result->{popularity});
$message = Irssi::settings_get_str('spotify_artist_format');
$message =~ s/%(name|popularity)/$data{$1}/ge;
} elsif ($result->{type} eq 'user') {
$data{'user'} = $result->{id};
$message = Irssi::settings_get_str('spotify_user_format');
$message =~ s/%(user)/$data{$1}/ge;
} elsif ($result->{type} eq 'playlist') {
$data{'name'} = $result->{name};
$data{'owner'} = $result->{owner}->{id};
$message = Irssi::settings_get_str('spotify_playlist_format');
$message =~ s/%(name|owner)/$data{$1}/ge;
} else {
print($writer "spotify: unhandled result type: " . $result->{type});
return 1;
}
my $charset = Irssi::settings_get_str('term_charset');
if ($charset =~ /^utf-8/i) {
binmode $writer, ':utf8';
} else {
Encode::from_to($message, "utf-8", Irssi::settings_get_str('term_charset'));
}
# Only write header for manual lookups
if ($manual) {
my $header = Irssi::settings_get_str('spotify_header_format');
$header =~ s/%uri/$uri/ge;
if ($header ne "") { print($writer $header . "\n"); }
}
print($writer $message);
return 0;
}
sub artists_str {
my $artists = shift;
my @names;
foreach my $artist(@{$artists}) {
push(@names, $artist->{name});
}
return join ', ', @names;
}
sub popularity_str {
my $popularity = shift;
my $str = '';
for (my $i = 0; $i < 100; $i += 20) {
if ($i <= $popularity) {
$str .= '*';
} else {
$str .= '-';
}
}
return $str;
}
sub settings_get_array {
my $key = shift;
my $value = Irssi::settings_get_str($key);
return split(/[ :;,]/, $value);
}
sub settings_set_array {
my ($key, @value) = @_;
my $str = join(' ', @value);
Irssi::settings_set_str($key, $str);
}
sub public_lookup_permitted {
my ($nick, $channel) = @_;
if (!Irssi::settings_get_bool('spotify_automatic_lookup_public')) {
return 0;
}
# Default lookup policy can either be deny or allow, and matching will
# invert the default result. If this is True, the policy list will be used
# as a blacklist. If this is False, the policy list is a whitelist.
my $blacklist = Irssi::settings_get_bool('spotify_automatic_lookup_public_blacklist');
sub in_array {
my ($type, $target) = @_;
my @array = settings_get_array("spotify_automatic_lookup_public_${type}s");
foreach my $item (@array) {
if ($item eq $target) { return 1; }
}
return 0;
}
if (defined($channel) && in_array('channel', $channel)) {
return $blacklist ? 0 : 1;
}
if (defined($nick) && in_array('nick', $nick)) {
return $blacklist ? 0 : 1;
}
return $blacklist ? 1 : 0;
}
### Signals
Irssi::signal_add_last('message public', 'event_message');
Irssi::signal_add_last('message private', 'event_message');
Irssi::signal_add_last('message topic', 'event_message_topic');
### Commands
Irssi::command_bind('spotify' => sub {
my ($args, $server, $window) = @_;
$args =~ s/\s+$//g;
Irssi::command_runsub('spotify', $args, $server, $window);
});
Irssi::command_bind('spotify help', \&cmd_spotify_help);
Irssi::command_bind('help', \&cmd_help);
Irssi::command_bind('spotify lookup', \&cmd_spotify_lookup);
Irssi::command_bind('spotify -l', \&cmd_spotify_lookup);
Irssi::command_bind('spotify lookup help', \&cmd_spotify_help_lookup);
Irssi::command_bind('spotify lookup -h', \&cmd_spotify_help_lookup);
Irssi::command_bind('spotify lookup public', \&cmd_spotify_lookup);
Irssi::command_bind('spotify lookup -p', \&cmd_spotify_lookup);
Irssi::command_bind('spotify auto', \&cmd_spotify_auto);
Irssi::command_bind('spotify -a', \&cmd_spotify_auto);
Irssi::command_bind('spotify auto help', \&cmd_spotify_help_auto);
Irssi::command_bind('spotify auto -h', \&cmd_spotify_help_auto);
Irssi::command_bind('spotify auto info', \&cmd_spotify_auto_info);
Irssi::command_bind('spotify auto -i', \&cmd_spotify_auto);
Irssi::command_bind('spotify auto enable', \&cmd_spotify_auto);
Irssi::command_bind('spotify auto -e', \&cmd_spotify_auto);
Irssi::command_bind('spotify auto disable', \&cmd_spotify_auto);
Irssi::command_bind('spotify auto -d', \&cmd_spotify_auto);
Irssi::command_bind('spotify auto public', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto -p', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto public help', \&cmd_spotify_help_auto_public);
Irssi::command_bind('spotify auto public -h', \&cmd_spotify_help_auto_public);
Irssi::command_bind('spotify auto public info', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto public -i', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto public enable', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto public -e', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto public disable', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto public -d', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto public whitelist', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto public -w', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto public blacklist', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto public -b', \&cmd_spotify_auto_public);
Irssi::command_bind('spotify auto public add', \&cmd_spotify_auto_public_add);
Irssi::command_bind('spotify auto public -a', \&cmd_spotify_auto_public_add);
Irssi::command_bind('spotify auto public add nick', \&cmd_spotify_auto_public_add);
Irssi::command_bind('spotify auto public add -n', \&cmd_spotify_auto_public_add);
Irssi::command_bind('spotify auto public add channel', \&cmd_spotify_auto_public_add);
Irssi::command_bind('spotify auto public add -c', \&cmd_spotify_auto_public_add);
Irssi::command_bind('spotify auto public del', \&cmd_spotify_auto_public_del);
Irssi::command_bind('spotify auto public -d', \&cmd_spotify_auto_public_del);
Irssi::command_bind('spotify auto public del nick', \&cmd_spotify_auto_public_del);
Irssi::command_bind('spotify auto public del -n', \&cmd_spotify_auto_public_del);
Irssi::command_bind('spotify auto public del channel', \&cmd_spotify_auto_public_del);
Irssi::command_bind('spotify auto public del -c', \&cmd_spotify_auto_public_del);
### Settings
Irssi::settings_add_bool('spotify', 'spotify_automatic_lookup', 1);
Irssi::settings_add_bool('spotify', 'spotify_automatic_lookup_public', 0);
Irssi::settings_add_bool('spotify', 'spotify_automatic_lookup_public_blacklist', 0);
Irssi::settings_add_str('spotify', 'spotify_client_id', '');
Irssi::settings_add_str('spotify', 'spotify_client_secret', '');
Irssi::settings_add_str('spotify', 'spotify_header_format', 'Lookup result for %_%uri%_:');
Irssi::settings_add_str('spotify', 'spotify_track_format', '%_%name%_ by %_%artist%_ (from %album) [%_%popularity%_]');
Irssi::settings_add_str('spotify', 'spotify_album_format', '%_%name%_ by %_%artist%_ (%year) [%_%popularity%_]');
Irssi::settings_add_str('spotify', 'spotify_artist_format', '%_%name%_ [%_%popularity%_]');
Irssi::settings_add_str('spotify', 'spotify_playlist_format', '%_%name%_ by %_%owner%_');
Irssi::settings_add_str('spotify', 'spotify_user_format', 'Username: %_%user%_');
Irssi::settings_add_str('spotify', 'spotify_automatic_lookup_public_channels', '');
Irssi::settings_add_str('spotify', 'spotify_automatic_lookup_public_nicks', '');