forked from doctorfree/RoonCommandLine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roon
executable file
·1713 lines (1681 loc) · 60.4 KB
/
roon
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
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# roon - frontend script to issue commands to Roon via the Python Roon API
#
# Copyright 2021-2022, Ronald Joe Record
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# shellcheck disable=SC1090,SC2001,SC2002,SC2016,SC2006,SC2086,SC2181,SC2129,SC2059,SC2076,SC2029,SC2207
#
# Edit these two settings if necessary
#
# Both of these should have been set correctly during
# installation of the RoonCommandLine package. Manual
# setting of these variables is uncommon and only necessary
# if the Python Roon API is installed on another system
#
# The IP address of the system on which the Python Roon API is installed
#
server="XX.X.X.XXX"
#
# The username with public key authorized SSH access to the system on
# which the Python Roon API is installed
#
user="SSH_USERNAME"
album=
artist=
composer=
comm=
albumlist=
artistlist=
artalbumlist=
arttracklist=
composerlist=
comalbumlist=
dest_zone=
from_zone=
exalbum=
exartist=
genrelist=
genartistlist=
genalbumlist=
playlistlist=
radiolist=
taglist=
playlist=
radio=
relative=
search=
setdefs=
showusage=1
showexamples=1
tag=
track=
volume=
zone=
zonegroup=
zonelist=
have_rich=$(type -p rich)
usage() {
[ "${showusage}" ] && {
if [ "${have_rich}" ]; then
rich "[bold]Usage:[/] [bold italic green]roon[/] [cyan]-A[/] [yellow]album[/] [cyan]-a[/] [yellow]artist[/] [cyan]-C[/] [yellow]composer[/] [cyan]-D[/] [yellow]destination zone[/]" --print
rich " [cyan]-F[/] [yellow]\[from zone][/] [cyan]-f[/] [yellow]\[on|onlog|off|status][/] [cyan]-g[/] [yellow]genre[/] [cyan]-G[/] [yellow]zone_group[/] [cyan]-i[/]" --print
rich " [cyan]-l[/] [yellow]\[albums|artists|artalbums|arttracks|composers|comalbums|[/]" --print
rich " [yellow]genres|genalbums|genartists|playlists|playtracks|tags|zones][/]" --print
rich " [cyan]-c[/] [yellow]\[group|ungroup|play|play_all|pause|pause_all|stop|stop_all|[/]" --print
rich " [yellow]next|previous|shuffle|repeat|mute|mute_all][/]" --print
rich " [cyan]-s[/] [yellow]search[/] [cyan]-p[/] [yellow]playlist[/] [cyan]-T[/] [yellow]track[/] [cyan]-t[/] [yellow]tag[/] [cyan]-z[/] [yellow]zone[/] [cyan]-L[/] [cyan]-S[/] [cyan]-r[/] [yellow]radio[/]" --print
rich " [cyan]-X[/] [yellow]ex_album[/] [cyan]-x[/] [yellow]ex_artist[/] [cyan]\[-EuU][/]" --print
rich "[bold]Where:[/]" --print
rich " [cyan]-A[/] [yellow]album[/] selects an album to play" --print
rich " [cyan]-a[/] [yellow]artist[/] selects an artist to list/play" --print
rich " [cyan]-C[/] [yellow]composer[/] selects a composer to play" --print
rich " [cyan]-D[/] [yellow]destination zone[/] specifies the zone to transfer current queue to" --print
rich " [cyan]-F[/] [yellow]from zone[/] specifies the zone to transfer from (default: last played)" --print
rich " [cyan]-g[/] [yellow]genre[/] selects a genre to list/play" --print
rich " [cyan]-i[/] displays zone information (combine with '[cyan]-z[/] [yellow]zone[/]' for extended" --print
rich " info on a specified zone, otherwise display info on all zones)" --print
rich " [cyan]-f[/] [yellow]\[on|onlog|off|status][/] enables/disables fading/logging in specified zone" --print
rich " '[yellow]on[/]' enables fading, '[yellow]onlog[/]' fading and logging, '[yellow]off[/]' disables fading" --print
rich " (combine with '[cyan]-z[/] [yellow]zone[/]' for 'fading' in that zone)" --print
rich " [cyan]-n[/] displays 'now playing' information for zones actively playing" --print
rich " [cyan]-N[/] displays 'now playing' information for all zones" --print
rich " (combine with '[cyan]-z[/] [yellow]zone[/]' for 'now playing' in only that zone)" --print
rich " [cyan]-p[/] [yellow]playlist[/] selects a playlist to play" --print
rich " [cyan]-G[/] [yellow]zone_group[/] specifies a zone grouping specified in roon_api.ini" --print
rich " [cyan]-L[/] setup roon to execute local commands rather than remote via SSH" --print
rich " [cyan]-S[/] Set Roon defaults in roon_api.ini" --print
rich " [cyan]-l[/] [yellow]\[albums|artists|artalbums|arttracks|composers|comalbums|[/]" --print
rich " [yellow]genres|genalbums|genartists|playlists|playtracks|tags|zones][/]" --print
rich " indicates list [italic]albums, artists, albums by artist,[/]" --print
rich " [italic]composers, albums by composers, genres, albums in genre,[/]" --print
rich " [italic]artists in genre, playlists, tags,[/] or Roon [italic]zones[/]" --print
rich " [cyan]-r[/] [yellow]radio[/] selects a live radio stream to play" --print
rich " [cyan]-s[/] [yellow]search[/] specifies a term to search for in the lists retrieved with [cyan]-l[/]" --print
rich " [cyan]-T[/] [yellow]track[/] specifies a track to play" --print
rich " [cyan]-t[/] [yellow]tag[/] selects an tag to play" --print
rich " [cyan]-z[/] [yellow]zone[/] selects the Roon Zone in which to play" --print
rich " [cyan]-c[/] [yellow]\[group|ungroup|play|play_all|pause|pause_all|playpause|[/]" --print
rich " [yellow]stop|stop_all|next|previous|shuffle|repeat|mute|mute_all][/]" --print
rich " issues the command in the selected zone" --print
rich " '[italic green]roon -c mute[/]' toggles the zone's muted or unmuted state" --print
rich " '[italic green]roon -c mute_all[/]' toggles all zones' muted or unmuted state" --print
rich " '[italic green]roon -c pause_all[/]' pauses playback in all zones" --print
rich " '[italic green]roon -c play_all[/]' begins playback in all zones" --print
rich " '[italic green]roon -c stop_all[/]' stops playback in all zones and releases devices" --print
rich " '[italic green]roon -c shuffle[/]' toggles the zone's shuffled or unshuffled setting" --print
rich " '[italic green]roon -c repeat[/]' toggles the zone's looping or non-looping setting" --print
rich " [cyan]-v[/] [yellow]volume[/] sets the volume level in the selected zone" --print
rich " The volume argument has the format [yellow]\[g:]\[r:]\[s:]num[/]" --print
rich " Where '[yellow]g[/]' indicates set volume for all zones in the group" --print
rich " '[yellow]r[/]' specifies use relative method volume setting" --print
rich " '[yellow]s[/]' specifies use relative_step method volume setting" --print
rich " '[yellow]num[/]' can be absolute, relative, and negative or positive" --print
rich " [cyan]-X[/] [yellow]ex_album[/] specifies a string to exclude from album/genre names" --print
rich " [cyan]-x[/] [yellow]ex_artist[/] specifies a string to exclude from artist/composer/playlist names" --print
rich " [cyan]-u[/] displays a full usage message with examples" --print
rich " [cyan]-U[/] displays a usage message without examples" --print
rich " [cyan]-E[/] displays examples with no usage message" --print
rich "Combine '[cyan]-a[/] [yellow]artist[/]' and '[cyan]-A[/] [yellow]album[/]' to play an album by a specified artist" --print
rich "Combine '[cyan]-a[/] [yellow]artist[/]' and '[cyan]-T[/] [yellow]track[/]' to play a track by a specified artist" --print
rich "Combine '[cyan]-a[/] [yellow]artist[/]' or '[cyan]-A[/] [yellow]album[/]' with '[cyan]-g[/] [yellow]genre[/]' to play an artist or album in a specified genre" --print
printf "\n"
rich "Special search term [bold italic magenta]__all__[/] matches all entries" --print
rich "Special name [bold italic green]default[/] plays the default setting in roon_api.ini" --print
printf "\n"
else
printf "\nUsage: roon -A album -a artist -C composer -D destination zone"
printf "\n\t-F [from zone] -f [on|onlog|off|status] -g genre -G zone_group -i"
printf "\n\t-l [albums|artists|artalbums|arttracks|composers|comalbums|"
printf "\n\t genres|genalbums|genartists|playlists|playtracks|tags|zones]"
printf "\n\t-c [group|ungroup|play|play_all|pause|pause_all|stop|stop_all|"
printf "\n\t next|previous|shuffle|repeat|mute|mute_all]"
printf "\n\t-s search -p playlist -T track -t tag -z zone -L -S -r radio"
printf "\n\t-X ex_album -x ex_artist [-EuU]"
printf "\nWhere:\n\t-A album selects an album to play"
printf "\n\t-a artist selects an artist to list/play"
printf "\n\t-C composer selects a composer to play"
printf "\n\t-D 'destination zone' specifies the zone to transfer current queue to"
printf "\n\t-F 'from zone' specifies the zone to transfer from (default: last played)"
printf "\n\t-g genre selects a genre to list/play"
printf "\n\t-i displays zone information (combine with '-z zone' for extended"
printf "\n\t\tinfo on a specified zone, otherwise display info on all zones)"
printf "\n\t-f [on|onlog|off|status] enables/disables fading/logging in specified zone"
printf "\n\t\t'on' enables fading, 'onlog' fading and logging, 'off' disables fading"
printf "\n\t\t(combine with '-z zone' for 'fading' in that zone)"
printf "\n\t-n displays 'now playing' information for zones actively playing"
printf "\n\t-N displays 'now playing' information for all zones"
printf "\n\t\t(combine with '-z zone' for 'now playing' in only that zone)"
printf "\n\t-p playlist selects a playlist to play"
printf "\n\t-G zone_group specifies a zone grouping specified in roon_api.ini"
printf "\n\t-L setup roon to execute local commands rather than remote via SSH"
printf "\n\t-S Set Roon defaults in roon_api.ini"
printf "\n\t-l [albums|artists|artalbums|arttracks|composers|comalbums|"
printf "\n\t genres|genalbums|genartists|playlists|playtracks|tags|zones]"
printf "\n\t indicates list albums, artists, albums by artist,"
printf "\n\t composers, albums by composers, genres, albums in genre,"
printf "\n\t artists in genre, playlists, tags, or Roon zones"
printf "\n\t-r radio selects a live radio stream to play"
printf "\n\t-s search specifies a term to search for in the lists retrieved with -l"
printf "\n\t-T track specifies a track to play"
printf "\n\t-t tag selects an tag to play"
printf "\n\t-z zone selects the Roon Zone in which to play"
printf "\n\t-c [group|ungroup|play|play_all|pause|pause_all|playpause|"
printf "\n\t stop|stop_all|next|previous|shuffle|repeat|mute|mute_all]"
printf "\n\t issues the command in the selected zone"
printf "\n\t 'mute' toggles the zone's muted or unmuted state"
printf "\n\t 'mute_all' toggles all zones' muted or unmuted state"
printf "\n\t 'pause_all' pauses playback in all zones"
printf "\n\t 'play_all' begins playback in all zones"
printf "\n\t 'stop_all' stops playback in all zones and releases devices"
printf "\n\t 'shuffle' toggles the zone's shuffled or unshuffled setting"
printf "\n\t 'repeat' toggles the zone's looping or non-looping setting"
printf "\n\t-v volume sets the volume level in the selected zone"
printf "\n\t\tThe volume argument has the format [g:][r:][s:]num"
printf "\n\t\tWhere 'g' indicates set volume for all zones in the group"
printf "\n\t\t'r' specifies use relative method volume setting"
printf "\n\t\t's' specifies use relative_step method volume setting"
printf "\n\t\t'num' can be absolute, relative, and negative or positive"
printf "\n\t-X ex_album specifies a string to exclude from album/genre names"
printf "\n\t-x ex_artist specifies a string to exclude from artist/composer/playlist names"
printf "\n\t-u displays a full usage message with examples"
printf "\n\t-U displays a usage message without examples"
printf "\n\t-E displays examples with no usage message"
printf "\nCombine '-a artist' and '-A album' to play an album by a specified artist"
printf "\nCombine '-a artist' and '-T track' to play a track by a specified artist"
printf "\nCombine '-a artist' or '-A album' with '-g genre' to play an artist or album in a specified genre\n"
printf "\nSpecial search term '__all__' matches all entries"
printf "\nSpecial name 'default' plays the default setting in roon_api.ini\n"
fi
}
[ "${showexamples}" ] && {
if [ "${have_rich}" ]; then
rich "[bold]Example invocations[/]" --print
rich " [magenta]Play artist:[/]" --print
rich " [bold italic green]roon -a \"Deep Purple\"[/]" --print
rich " [magenta]Play album by artist:[/]" --print
rich " [bold italic green]roon -a \"Deep Purple\" -A Burn[/]" --print
rich " [magenta]Play track by artist:[/]" --print
rich " [bold italic green]roon -a \"Aretha Franklin\" -T Think[/]" --print
rich " [magenta]Play artist in specified zone:[/]" --print
rich " [bold italic green]roon -a \"Jethro Tull\" -z \"Mac Pro DAC\"[/]" --print
rich " [magenta]Play genre:[/]" --print
rich " [bold italic green]roon -g Classical[/]" --print
rich " [magenta]Play default live radio:[/]" --print
rich " [bold italic green]roon -r default[/]" --print
rich " [magenta]Play playlist:[/]" --print
rich " [bold italic green]roon -p \"Bowie Favs\"[/]" --print
rich " [magenta]Play next track:[/]" --print
rich " [bold italic green]roon -c next[/]" --print
rich " [magenta]Stop play in specified zone:[/]" --print
rich " [bold italic green]roon -c stop -z Kitchen[/]" --print
rich " [magenta]Mute/Unmute a specified zone:[/]" --print
rich " [bold italic green]roon -c mute -z \"Mac Pro DAC\"[/]" --print
rich " [magenta]Mute/Unmute all zones:[/]" --print
rich " [bold italic green]roon -c mute_all[/]" --print
rich " [magenta]List all playlists containing the string 'Best':[/]" --print
rich " [bold italic green]roon -l playlists -s Best[/]" --print
rich " [magenta]List albums by artist:[/]" --print
rich " [bold italic green]roon -l artalbums -a \"Deep Purple\"[/]" --print
rich " [magenta]List artists containing the string 'Will' in the 'Country' genre:[/]" --print
rich " [bold italic green]roon -l genartists -a Will -g Country[/]" --print
rich " [magenta]List albums containing the string 'Magic' in the 'Rock' genre:[/]" --print
rich " [bold italic green]roon -l genalbums -A Magic -g Rock[/]" --print
rich " [magenta]Play artist containing the string 'Willie' in the 'Country' genre:[/]" --print
rich " [bold italic green]roon -a Willie -g Country[/]" --print
rich " [magenta]Play album containing the string 'Magic' in the 'Rock' genre:[/]" --print
rich " [bold italic green]roon -A Magic -g Rock[/]" --print
rich " [magenta]Group the zones listed in roon_api.ini Group_foobar:[/]" --print
rich " [bold italic green]roon -G foobar -c group[/]" --print
rich " [magenta]Set the volume level to 50 in the currently active zone[/]" --print
rich " [bold italic green]roon -v 50[/]" --print
rich " [magenta]Decrease the volume level by 10 in the currently active zone[/]" --print
rich " [bold italic green]roon -v r:-10[/]" --print
rich " [magenta]Set the volume level to 40 in all zones grouped with the zone named 'Mac Pro DAC'[/]" --print
rich " [bold italic green]roon -v g:40 -z 'Mac Pro DAC'[/]" --print
rich " [magenta]Increase the volume level by 20 in all zones grouped with the zone named 'Mac Pro DAC'[/]" --print
rich " [bold italic green]roon -v g:r:20 -z 'Mac Pro DAC'[/]" --print
rich " [magenta]Get info on all Roon zones[/]" --print
rich " [bold italic green]roon -i[/]" --print
rich " [magenta]Get extended info on Roon zone named 'Mac Pro DAC'[/]" --print
rich " [bold italic green]roon -i -z 'Mac Pro DAC'[/]" --print
rich " [magenta]Get now playing info on all zones regardless of state[/]" --print
rich " [bold italic green]roon -N[/]" --print
rich " [magenta]Get now playing info on all zones actively playing[/]" --print
rich " [bold italic green]roon -n[/]" --print
rich " [magenta]Get now playing info on Roon zone named 'Mac Pro DAC'[/]" --print
rich " [bold italic green]roon -n -z 'Mac Pro DAC'[/]" --print
rich " [magenta]Enable volume fading in default Roon zone[/]" --print
rich " [bold italic green]roon -f on[/]" --print
rich " [magenta]Disable volume fading in default Roon zone[/]" --print
rich " [bold italic green]roon -f off[/]" --print
rich " [bold]NOTE:[/] [italic]Use quotes to specify media names which contain spaces.[/]" --print
rich " For example, to [magenta]play the album 'Love Bomb':[/]" --print
rich " [bold italic green]roon -A \"Love Bomb\"[/]" --print
printf "\n"
else
printf "\nExample invocations"
printf "\n\tPlay artist:"
printf "\n\t\troon -a \"Deep Purple\""
printf "\n\tPlay album by artist:"
printf "\n\t\troon -a \"Deep Purple\" -A Burn"
printf "\n\tPlay track by artist:"
printf "\n\t\troon -a \"Aretha Franklin\" -T Think"
printf "\n\tPlay artist in specified zone:"
printf "\n\t\troon -a \"Jethro Tull\" -z \"Mac Pro DAC\""
printf "\n\tPlay genre:"
printf "\n\t\troon -g Classical"
printf "\n\tPlay default live radio:"
printf "\n\t\troon -r default"
printf "\n\tPlay playlist:"
printf "\n\t\troon -p \"Bowie Favs\""
printf "\n\tPlay next track:"
printf "\n\t\troon -c next"
printf "\n\tStop play in specified zone:"
printf "\n\t\troon -c stop -z Kitchen"
printf "\n\tMute/Unmute a specified zone:"
printf "\n\t\troon -c mute -z \"Mac Pro DAC\""
printf "\n\tMute/Unmute all zones:"
printf "\n\t\troon -c mute_all"
printf "\n\tList all playlists containing the string 'Best':"
printf "\n\t\troon -l playlists -s Best"
printf "\n\tList albums by artist:"
printf "\n\t\troon -l artalbums -a \"Deep Purple\""
printf "\n\tList artists containing the string 'Will' in the 'Country' genre:"
printf "\n\t\troon -l genartists -a Will -g Country"
printf "\n\tList albums containing the string 'Magic' in the 'Rock' genre:"
printf "\n\t\troon -l genalbums -A Magic -g Rock"
printf "\n\tPlay artist containing the string 'Willie' in the 'Country' genre:"
printf "\n\t\troon -a Willie -g Country"
printf "\n\tPlay album containing the string 'Magic' in the 'Rock' genre:"
printf "\n\t\troon -A Magic -g Rock"
printf "\n\tGroup the zones listed in roon_api.ini Group_foobar:"
printf "\n\t\troon -G foobar -c group"
printf "\n\tSet the volume level to 50 in the currently active zone"
printf "\n\t\troon -v 50"
printf "\n\tDecrease the volume level by 10 in the currently active zone"
printf "\n\t\troon -v r:-10"
printf "\n\tSet the volume level to 40 in all zones grouped with the zone named 'Mac Pro DAC'"
printf "\n\t\troon -v g:40 -z 'Mac Pro DAC'"
printf "\n\tIncrease the volume level by 20 in all zones grouped with the zone named 'Mac Pro DAC'"
printf "\n\t\troon -v g:r:20 -z 'Mac Pro DAC'"
printf "\n\tGet info on all Roon zones"
printf "\n\t\troon -i"
printf "\n\tGet extended info on Roon zone named 'Mac Pro DAC'"
printf "\n\t\troon -i -z 'Mac Pro DAC'"
printf "\n\tGet now playing info on all zones regardless of state"
printf "\n\t\troon -N"
printf "\n\tGet now playing info on all zones actively playing"
printf "\n\t\troon -n"
printf "\n\tGet now playing info on Roon zone named 'Mac Pro DAC'"
printf "\n\t\troon -n -z 'Mac Pro DAC'"
printf "\n\tEnable volume fading in default Roon zone"
printf "\n\t\troon -f on"
printf "\n\tDisable volume fading in default Roon zone"
printf "\n\t\troon -f off"
printf "\n\tNOTE: Use quotes to specify media names which contain spaces."
printf "\n\tFor example, to play the album 'Love Bomb':"
printf "\n\t\troon -A \"Love Bomb\"\n"
fi
}
exit 1
}
show_roon_menu=
[ "$1" ] || show_roon_menu=1
ROON=/usr/local/Roon
ROONAPI=${ROON}/api
ROONETC=${ROON}/etc
ROON_INI=${ROONETC}/roon_api.ini
ROONCONF=${ROONETC}/pyroonconf
LOCAL=false
BOLD=$(tput bold 2>/dev/null)
NORMAL=$(tput sgr0 2>/dev/null)
[ -f ${ROON}/venv/bin/activate ] && source ${ROON}/venv/bin/activate
[ -x ${ROON}/venv/bin/python ] && export PYTHON=${ROON}/venv/bin/python
[[ ":$PATH:" == *":/usr/local/bin:"* ]] || export PATH=${PATH}:/usr/local/bin
[[ ":$PATH:" == *":/usr/local/Roon/bin:"* ]] || {
export PATH=/usr/local/Roon/bin:${PATH}
}
[[ ":$PATH:" == *":/usr/local/Roon/venv/bin:"* ]] || {
export PATH=/usr/local/Roon/venv/bin:${PATH}
}
if [ -x /home/linuxbrew/.linuxbrew/bin/brew ]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
else
[ -x /usr/local/bin/brew ] && eval "$(/usr/local/bin/brew shellenv)"
fi
set_default_conf() {
if [ -w ${ROONETC} ]; then
echo "LOCAL=true" >${ROONCONF}
DEFZONE=$(grep ^DefaultZone ${ROON_INI} | awk -F '=' ' { print $2 } ')
# Remove leading and trailing spaces in DEFZONE
DEFZONE="$(echo -e "${DEFZONE}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
echo "ROON_ZONE=\"$DEFZONE\"" >>${ROONCONF}
else
echo "${ROONETC} is not writeable by this user."
echo "Correct permissions on ${ROONETC} and re-run this command."
echo "Exiting."
exit 1
fi
}
[ -f ${ROONCONF} ] || set_default_conf
bash -n ${ROONCONF} >/dev/null 2>&1
[ $? -eq 0 ] || {
echo "WARNING: Syntax errors in ${ROONCONF} have been detected."
echo "The following is the output of bash -n ${ROONCONF}"
echo ""
bash -n ${ROONCONF}
echo ""
while true; do
read -r -p "Revert to default settings and continue? (y/n) " answer
case ${answer} in
[Yy]*)
set_default_conf
break
;;
[Nn]*)
echo "Correct syntax errors in ${ROONCONF} and re-run this command."
echo "Exiting."
exit 1
;;
*)
echo "Please answer 'y' to repair configuration, or 'n' to exit."
;;
esac
done
}
[ -f ${ROONCONF} ] && . ${ROONCONF}
select_zone() {
${IFS+"false"} && unset oldifs || oldifs="$IFS"
IFS=$'\n'
if [ "${LOCAL}" == "true" ]; then
zones=$(${ROON}/bin/get_zones | sed -e 's/\, /\,/g')
else
zones=$(ssh $user@$server "bash -l -c \"${ROON}/bin/get_zones | sed -e 's/\, /\,/g'\"")
fi
zone_options=($(echo "${zones}" | awk -F "," ' { for(i=1;i<=NF;i++) printf "%s\n",$i }'))
${oldifs+"false"} && unset IFS || IFS="$oldifs"
zone_options+=("Defaults Menu" "Main Menu" "Quit (q)")
while true; do
[ "${have_rich}" ] && {
rich "[bold][cyan]Select Roon Zone[/cyan][/bold]" -p -a rounded -c -C
}
PS3="${BOLD}Please enter the Roon zone you wish to use (numeric or text): ${NORMAL}"
select opt in "${zone_options[@]}"; do
case "$opt,$REPLY" in
"Main Menu",* | *,"Main Menu")
main_menu
break 2
;;
"Quit"*,* | *,"Quit"* | "quit"*,* | *,"quit"* | "q",* | *,"q")
printf "\nExiting\n"
exit 0
;;
"Defaults Menu",* | *,"Defaults Menu")
list_defaults
break 2
;;
*,*)
if [[ " ${zone_options[*]} " =~ " ${opt} " ]]; then
echo "${BOLD}Executing Roon command to set default zone to: ${opt}${NORMAL}"
if [ "${LOCAL}" = true ]; then
${ROON}/bin/set_zone "${opt}"
else
ssh $user@$server "bash -l -c \"${ROON}/bin/set_zone ${opt}\""
fi
status=$?
[ ${status} -eq 0 ] || {
echo "Unable to set zone for zone = $opt"
}
break 2
else
printf "\n\nInvalid option: ${opt}"
printf "\n\tPlease enter either the exact text or numeric designation"
printf "\n\tfor one of the listed options below.\n\n"
break
fi
;;
esac
done
done
}
select_default() {
media="$1"
have_python3=$(type -p python3)
if [ "${have_python3}" ]; then
pycom="python3 ${ROONAPI}/set_default.py"
else
pycom="python ${ROONAPI}/set_default.py"
fi
case "${media}" in
"Set Default Album")
setdefcom="${pycom} -A"
listcom="list_albums"
medtype="Album"
;;
"Set Default Artist")
setdefcom="${pycom} -a"
listcom="list_artists"
medtype="Artist"
;;
"Set Default Composer")
setdefcom="${pycom} -c"
listcom="list_composers"
medtype="Composer"
;;
"Set Default Genre")
setdefcom="${pycom} -g"
listcom="list_genres"
medtype="Genre"
;;
"Set Default Playlist")
setdefcom="${pycom} -p"
listcom="list_playlists"
medtype="Playlist"
;;
"Set Default Radio")
setdefcom="${pycom} -r"
listcom="list_radio"
medtype="Radio"
;;
"Set Default Tag")
setdefcom="${pycom} -t"
listcom="list_tags"
medtype="Tag"
;;
*)
return 1
;;
esac
printf "\nRetrieving ${medtype}s in your Roon library ..."
${IFS+"false"} && unset oldifs || oldifs="$IFS"
IFS=$'\n'
if [ "${LOCAL}" = true ]; then
media_options=($(${listcom} __all__))
else
media_options=($(ssh $user@$server "bash -l -c \"${ROON}/bin/${listcom} __all__\""))
fi
DEFAULT=$(grep ^Default${medtype} ${ROON_INI} | awk -F '=' ' { print $2 } ')
# Remove leading and trailing spaces
DEFAULT="$(echo -e "${DEFAULT}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
printf " Done\n\n"
printf "Default${medtype} = ${DEFAULT}\n\n"
${oldifs+"false"} && unset IFS || IFS="$oldifs"
media_options+=("Set Defaults Menu" "Main Menu" "Quit (q)")
while true; do
[ "${have_rich}" ] && {
rich "[bold][cyan]RoonCommandLine Default ${medtype}[/cyan][/bold]" -p -a rounded -c -C
}
PS3="${BOLD}Please enter the ${medtype} you wish to set as default (numeric or text): ${NORMAL}"
select opt in "${media_options[@]}"; do
case "$opt,$REPLY" in
"Set Defaults Menu",* | *,"Set Defaults Menu")
break 2
;;
"Main Menu",* | *,"Main Menu")
main_menu
break 3
;;
"Quit"*,* | *,"Quit"* | "quit"*,* | *,"quit"* | "q",* | *,"q")
printf "\nExiting\n"
exit 0
;;
*,*)
echo "${BOLD}Setting Roon ${medtype} default to: ${opt}${NORMAL}"
if [ "${LOCAL}" = true ]; then
${setdefcom} "${opt}"
else
ssh $user@$server "bash -l -c \"${ROON}/bin/${setdefcom} ${opt}\""
fi
break 2
;;
esac
done
done
}
select_media() {
media="$1"
case "${media}" in
album)
playcom="play_album"
listcom="list_albums"
medtype="Album"
;;
artist)
playcom="play_artist"
listcom="list_artists"
medtype="Artist"
;;
composer)
playcom="play_composer"
listcom="list_composers"
medtype="Composer"
;;
genre)
playcom="play_genre"
listcom="list_genres"
medtype="Genre"
;;
playlist)
playcom="play_playlist"
listcom="list_playlists"
medtype="Playlist"
;;
station)
playcom="play_radio"
listcom="list_radio"
medtype="Radio"
;;
tag)
playcom="play_tag"
listcom="list_tags"
medtype="Tag"
;;
*)
return 1
;;
esac
printf "\nRetrieving ${media}s in your Roon library ..."
${IFS+"false"} && unset oldifs || oldifs="$IFS"
IFS=$'\n'
if [ "${LOCAL}" = true ]; then
media_options=($(${listcom} __all__))
else
media_options=($(ssh $user@$server "bash -l -c \"${ROON}/bin/${listcom} __all__\""))
fi
DEFAULT=$(grep ^Default${medtype} ${ROON_INI} | awk -F '=' ' { print $2 } ')
# Remove leading and trailing spaces
DEFAULT="$(echo -e "${DEFAULT}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
printf " Done\n\n"
printf "Default ${media}: ${DEFAULT}\n\n"
${oldifs+"false"} && unset IFS || IFS="$oldifs"
media_options+=("Main Menu" "Quit (q)")
while true; do
[ "${have_rich}" ] && {
rich "[bold][cyan]RoonCommandLine Play ${medtype}[/cyan][/bold]" -p -a rounded -c -C
}
PS3="${BOLD}Please enter the ${media} you wish to play (numeric or text): ${NORMAL}"
select opt in "${media_options[@]}"; do
case "$opt,$REPLY" in
"Main Menu",* | *,"Main Menu")
main_menu
break 2
;;
"Quit"*,* | *,"Quit"* | "quit"*,* | *,"quit"* | "q",* | *,"q")
printf "\nExiting\n"
exit 0
;;
*,*)
echo "${BOLD}Executing Roon command to play ${media}: ${opt}${NORMAL}"
if [ "${LOCAL}" = true ]; then
${playcom} "${opt}"
else
ssh $user@$server "bash -l -c \"${ROON}/bin/${playcom} ${opt}\""
fi
break 2
;;
esac
done
done
}
select_set_volume() {
volume_options=("Mute/Unmute Zone" "Mute/Unmute All Zones" "Set Volume to 10" "Set Volume to 20" "Set Volume to 30" "Set Volume to 40" "Set Volume to 50" "Set Volume to 60" "Set Volume to 70" "Set Volume to 80" "Set Volume to 90" "Set Volume to 100" "Increase Volume by 1" "Increase Volume by 5" "Increase Volume by 10" "Increase Volume by 20" "Increase Volume by 40" "Decrease Volume by 1" "Decrease Volume by 5" "Decrease Volume by 10" "Decrease Volume by 20" "Decrease Volume by 40" "Main Menu" "Quit (q)")
while true; do
[ "${have_rich}" ] && {
rich "[bold][cyan]RoonCommandLine Volume Control[/cyan][/bold]" -p -a rounded -c -C
}
printf "\n"
PS3="${BOLD}Please enter the volume adjustment you wish to make (numeric or text): ${NORMAL}"
select opt in "${volume_options[@]}"; do
case "$opt,$REPLY" in
"Set Volume to "*,* | *,"Set Volume to "*)
volume=$(echo $opt | awk ' { print $NF } ')
if [ "${LOCAL}" = true ]; then
set_volume -v ${volume} -g
else
ssh $user@$server "bash -l -c \"${ROON}/bin/set_volume -v ${volume} -g\""
fi
break
;;
"Increase Volume by "*,* | *,"Increase Volume by "*)
volume=$(echo $opt | awk ' { print $NF } ')
if [ "${LOCAL}" = true ]; then
set_volume -v ${volume} -g -r
else
ssh $user@$server "bash -l -c \"${ROON}/bin/set_volume -v ${volume} -g -r\""
fi
break
;;
"Decrease Volume by "*,* | *,"Decrease Volume by "*)
volume=$(echo $opt | awk ' { print $NF } ')
if [ "${LOCAL}" = true ]; then
set_volume -v -${volume} -g -r
else
ssh $user@$server "bash -l -c \"${ROON}/bin/set_volume -v -${volume} -g -r\""
fi
break
;;
"Mute/Unmute Zone",* | *,"Mute/Unmute Zone")
printf "\nExecuting Roon command to toggle mute audio ..."
if [ "${LOCAL}" = true ]; then
zone_command -c mute
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c mute\""
fi
printf " Done\n\n"
break
;;
"Mute/Unmute All Zones",* | *,"Mute/Unmute All Zones")
printf "\nExecuting Roon command to toggle mute in all zones ..."
if [ "${LOCAL}" = true ]; then
zone_command -c mute_all
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c mute_all\""
fi
printf " Done\n\n"
break
;;
"Main Menu",* | *,"Main Menu")
main_menu
break 2
;;
"Quit"*,* | *,"Quit"* | "quit"*,* | *,"quit"* | "q",* | *,"q")
printf "\nExiting\n"
exit 0
;;
esac
done
done
}
list_defaults() {
defaults_options=("Set Default Album" "Set Default Artist" "Set Default Composer" "Set Default Genre" "Set Default Playlist" "Set Default Radio" "Set Default Tag" "Set Default Zone" "Main Menu" "Quit (q)")
while true; do
for media in Album Artist Composer Genre Playlist Radio Tag; do
DEFAULT=$(grep ^Default${media} ${ROON_INI} | awk -F '=' ' { print $2 } ')
# Remove leading and trailing spaces
DEFAULT="$(echo -e "${DEFAULT}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
printf "\nDefault ${media}: ${DEFAULT}"
done
printf "\n\n"
[ "${have_rich}" ] && {
rich "[bold][cyan]RoonCommandLine Defaults Menu[/cyan][/bold]" -p -a rounded -c -C
}
PS3="${BOLD}Please enter the default you wish to set (numeric or text): ${NORMAL}"
select opt in "${defaults_options[@]}"; do
case "$opt,$REPLY" in
"Main Menu",* | *,"Main Menu")
main_menu
break 2
;;
"Quit"*,* | *,"Quit"* | "quit"*,* | *,"quit"* | "q",* | *,"q")
printf "\nExiting\n"
exit 0
;;
"Set Default Zone",* | *,"Set Default Zone")
[ -f ${ROONCONF} ] && . ${ROONCONF}
if [ "${LOCAL}" = true ]; then
if [ "${ROON_ZONE}" ]; then
echo ""
echo "Current Roon Zone is ${ROON_ZONE}"
else
echo ""
echo "No default Roon Zone is set in ${ROONCONF}"
fi
else
roon_zone=$(ssh $user@$server "bash -l -c \"grep ROON_ZONE ${ROONCONF}\"")
if [ "${roon_zone}" ]; then
echo ""
echo "Current Roon Zone is ${roon_zone}"
else
echo ""
echo "No default Roon Zone is set in ${ROONCONF}"
fi
fi
select_zone
break
;;
*,*)
select_default "${opt}"
break
;;
esac
done
done
}
main_menu() {
while true; do
[ "${have_rich}" ] && {
rich "[bold][cyan]RoonCommandLine Main Menu[/cyan][/bold]" -p -a rounded -c -C
}
PS3="${BOLD}Please enter your Roon command choice (numeric or text): ${NORMAL}"
options=("Get/Set Defaults" "Get/Set Zone" "Play" "Play All" "Pause" "Pause All" "Next Track" "Previous Track" "Stop" "Stop All" "Toggle Mute" "Toggle Mute All" "Toggle Repeat" "Toggle Shuffle" "List Albums" "List Artists" "List Composers" "List Genres" "List Playlists" "List Live Radio" "List Tags" "List Zones" "Select Album" "Select Artist" "Select Composer" "Select Genre" "Select Live Radio" "Select Playlist" "Select Tag" "Play Default Album" "Play Default Artist" "Play Default Composer" "Play Default Genre" "Play Default Radio" "Play Default Playlist" "Play Default Tag" "Fade Menu" "Volume" "Quit (q)")
select opt in "${options[@]}"; do
case "$opt,$REPLY" in
"Get/Set Defaults",* | *,"Get/Set Defaults")
list_defaults
break
;;
"Get/Set Zone",* | *,"Get/Set Zone")
[ -f ${ROONCONF} ] && . ${ROONCONF}
if [ "${LOCAL}" = true ]; then
if [ "${ROON_ZONE}" ]; then
echo ""
echo "Current Roon Zone is ${ROON_ZONE}"
else
echo ""
echo "No default Roon Zone is set in ${ROONCONF}"
fi
else
roon_zone=$(ssh $user@$server "bash -l -c \"grep ROON_ZONE ${ROONCONF}\"")
if [ "${roon_zone}" ]; then
echo ""
echo "Current Roon Zone is ${roon_zone}"
else
echo ""
echo "No default Roon Zone is set in ${ROONCONF}"
fi
fi
select_zone
break
;;
"Play",* | *,"Play")
printf "\nExecuting Roon command to play ..."
if [ "${LOCAL}" = true ]; then
zone_command -c play
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c play\""
fi
printf " Done\n\n"
break
;;
"Play All",* | *,"Play All")
printf "\nExecuting Roon command to play in all zones ..."
if [ "${LOCAL}" = true ]; then
zone_command -c play_all
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c play_all\""
fi
printf " Done\n\n"
break
;;
"Pause All",* | *,"Pause All")
printf "\nExecuting Roon command to pause play in all zones ..."
if [ "${LOCAL}" = true ]; then
zone_command -c pause_all
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c pause_all\""
fi
printf " Done\n\n"
break
;;
"Pause",* | *,"Pause")
printf "\nExecuting Roon command to pause play ..."
if [ "${LOCAL}" = true ]; then
zone_command -c pause
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c pause\""
fi
printf " Done\n\n"
break
;;
"Next Track",* | *,"Next Track")
printf "\nExecuting Roon command to play next track ..."
if [ "${LOCAL}" = true ]; then
zone_command -c next
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c next\""
fi
printf " Done\n\n"
break
;;
"Previous Track",* | *,"Previous Track")
printf "\nExecuting Roon command to play previous track ..."
if [ "${LOCAL}" = true ]; then
zone_command -c previous
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c previous\""
fi
printf " Done\n\n"
break
;;
"Stop",* | *,"Stop")
printf "\nExecuting Roon command to stop ..."
if [ "${LOCAL}" = true ]; then
zone_command -c stop
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c stop\""
fi
printf " Done\n\n"
break
;;
"Stop All",* | *,"Stop All")
printf "\nExecuting Roon command to stop in all zones ..."
if [ "${LOCAL}" = true ]; then
zone_command -c stop_all
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c stop_all\""
fi
printf " Done\n\n"
break
;;
"Fade Menu",* | *,"Fade Menu")
exec roon_fade -i
break
;;
"Toggle Mute",* | *,"Toggle Mute")
printf "\nExecuting Roon command to toggle mute audio ..."
if [ "${LOCAL}" = true ]; then
zone_command -c mute
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c mute\""
fi
printf " Done\n\n"
break
;;
"Toggle Mute All",* | *,"Toggle Mute All")
printf "\nExecuting Roon command to toggle mute in all zones ..."
if [ "${LOCAL}" = true ]; then
zone_command -c mute_all
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c mute_all\""
fi
printf " Done\n\n"
break
;;
"Toggle Repeat",* | *,"Toggle Repeat")
printf "\nExecuting Roon command to toggle repeat ..."
if [ "${LOCAL}" = true ]; then
zone_command -c repeat
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c repeat\""
fi
printf " Done\n\n"
break
;;
"Toggle Shuffle",* | *,"Toggle Shuffle")
printf "\nExecuting Roon command to toggle shuffle ..."
if [ "${LOCAL}" = true ]; then
zone_command -c shuffle
else
ssh $user@$server "bash -l -c \"${ROON}/bin/zone_command -c shuffle\""
fi
printf " Done\n\n"
break
;;
"List Albums",* | *,"List Albums")
if [ "${LOCAL}" = true ]; then
list_albums __all__ "${exalbum}"
else
ssh $user@$server "bash -l -c \"${ROON}/bin/list_albums __all__ ${exalbum}\""
fi
break
;;
"List Artists",* | *,"List Artists")
if [ "${LOCAL}" = true ]; then
list_artists __all__ "${exartist}"
else
ssh $user@$server "bash -l -c \"${ROON}/bin/list_artists __all__ ${exartist}\""
fi
break
;;
"List Composers",* | *,"List Composers")
if [ "${LOCAL}" = true ]; then
list_composers __all__ "$exartist"
else
ssh $user@$server "bash -l -c \"${ROON}/bin/list_composers __all__ $exartist\""
fi
break
;;
"List Genres",* | *,"List Genres")
if [ "${LOCAL}" = true ]; then
list_genres __all__ "$exalbum"
else
ssh $user@$server "bash -l -c \"${ROON}/bin/list_genres __all__ $exalbum\""
fi
break
;;
"List Playlists",* | *,"List Playlists")
if [ "${LOCAL}" = true ]; then
list_playlists __all__ "$exartist"
else
ssh $user@$server "bash -l -c \"${ROON}/bin/list_playlists __all__ $exartist\""
fi
break
;;
"List Live Radio",* | *,"List Live Radio")
if [ "${LOCAL}" = true ]; then
list_radio __all__
else
ssh $user@$server "bash -l -c \"${ROON}/bin/list_radio __all__\""
fi
break
;;
"List Tags",* | *,"List Tags")
if [ "${LOCAL}" = true ]; then
list_tags __all__
else
ssh $user@$server "bash -l -c \"${ROON}/bin/list_tags __all__\""
fi
break
;;
"List Zones",* | *,"List Zones")
if [ "${LOCAL}" = true ]; then
list_zones
else
ssh $user@$server "bash -l -c \"${ROON}/bin/list_zones\""
fi
break
;;
"Select Album",* | *,"Select Album")
select_media album
break