-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhnp_clementine.pl
1443 lines (1364 loc) · 55.1 KB
/
hnp_clementine.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
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
# Copyright (C) 2006-2015 Craciun Dan (C) 2010 John Aylward
#
# 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 Street, Fifth Floor, Boston, MA 02110-1301, USA
use URI::Escape;
HexChat::register("HNP Clementine", "1.0.1", "HexChat Now Playing Script for 2.x, based on HNP 2.0.1");
HexChat::hook_command("TOGGLE_ALBUM", call_toggle_album);
HexChat::hook_command("TOGGLE_YEAR", call_toggle_year);
HexChat::hook_command("TOGGLE_TRACK", call_toggle_track);
HexChat::hook_command("TOGGLE_LENGTH", call_toggle_length);
HexChat::hook_command("TOGGLE_BITRATE", call_toggle_bitrate);
HexChat::hook_command("TOGGLE_SIZE", call_toggle_size);
HexChat::hook_command("TOGGLE_SHOW_MENU", call_toggle_show_menu);
HexChat::hook_command("TOGGLE_SHOW_TEXT_STYLE", call_toggle_show_text_style);
HexChat::hook_command("TOGGLE_SHOW_TEXT_COLOR", call_toggle_show_text_color);
HexChat::hook_command("BROWSER1", call_browser1);
HexChat::hook_command("BROWSER2", call_browser2);
HexChat::hook_command("BROWSER3", call_browser3);
HexChat::hook_command("BROWSER4", call_browser4);
HexChat::hook_command("HNPMUTE", cmd_hnpmute);
HexChat::hook_command("HNPVOL1", cmd_hnpvol1);
HexChat::hook_command("HNPVOL2", cmd_hnpvol2);
HexChat::hook_command("HNPVOL3", cmd_hnpvol3);
HexChat::hook_command("HNPVOL4", cmd_hnpvol4);
HexChat::hook_command("HNPVOL5", cmd_hnpvol5);
HexChat::hook_command("HNPVOL6", cmd_hnpvol6);
HexChat::hook_command("HNPVOL7", cmd_hnpvol7);
HexChat::hook_command("HNPVOL8", cmd_hnpvol8);
HexChat::hook_command("HNPVOL9", cmd_hnpvol9);
HexChat::hook_command("HNPMAX", cmd_hnpmax);
HexChat::hook_command("HNPVOL", cmd_hnpvol);
HexChat::hook_command("HNPPLAY", cmd_hnpplay);
HexChat::hook_command("HNPPAUSE", cmd_hnppause);
HexChat::hook_command("HNPSTOP", cmd_hnpstop);
HexChat::hook_command("HNPPREV", cmd_hnpprev);
HexChat::hook_command("HNPNEXT", cmd_hnpnext);
HexChat::hook_command("HNPRUN", cmd_hnprun);
HexChat::hook_command("HNPQUIT", cmd_hnpquit);
HexChat::hook_command("HNP", cmd_hnp);
HexChat::hook_command("HNPS", cmd_hnps);
HexChat::hook_command("HNPSTATS", cmd_hnpstats);
HexChat::hook_command("HNPINFO", cmd_hnpinfo);
HexChat::hook_command("ALL_ON", cmd_all_on);
HexChat::hook_command("ALL_OFF", cmd_all_off);
HexChat::hook_command("HNPMODES", cmd_hnpmodes);
HexChat::hook_command("HNPHELP", cmd_hnphelp);
HexChat::hook_command("HNPABOUT", cmd_hnpabout);
HexChat::hook_command("HNPHOME", cmd_hnphome);
#HexChat::hook_command("HNPHOWTO", cmd_hnphowto);
#HexChat::hook_command("HNPFAQ", cmd_hnpfaq);
load_messages();
load_integrity();
load_menus();
sub configFile {
return HexChat::get_info("configdir") . "/hnp.conf";
}
sub load_messages {
HexChat::print("---");
HexChat::print("\cC02HNP:\cC01 HNP Clementine 1.0.1 by Antonio Prcela, based on HNP 2.0.1, loaded.");
HexChat::print("\cC02HNP:\cC01 HexChat Now Playing Script for 2.x is a Perl script that displays info about the currently playing track in and the music collection.");
HexChat::print("\cC02HNP:\cC01 Type /HNP to use and /HNPHELP for a full list of commands.");
HexChat::print("\cC02HNP:\cC01 For suggestions, feature requests and bug reports please contact me at github.com/precla.");
HexChat::print("---");
}
sub load_integrity {
if (integrity_check() == 1) {
$openval = open(CONF, ">" . configFile());
if ($openval == 1) {
print CONF "show_album=1\n";
print CONF "show_year=1\n";
print CONF "show_track=1\n";
print CONF "show_length=1\n";
print CONF "show_bitrate=1\n";
print CONF "show_size=1\n";
print CONF "show_menu=1\n";
print CONF "show_text_style=1\n";
print CONF "show_text_color=1\n";
print CONF "browser=firefox\n";
close(CONF);
HexChat::print("\cC02HNP:\cC01 Created the HNP configuration file (" . configFile() . ") with default values.");
return 0;
} else {
HexChat::print("\cC02HNP:\cC01 Could not read/create the HNP configuration file (" . configFile() . "). Please check disk space and file permissions.");
HexChat::print("\cC02HNP:\cC01 Without the HNP configuration file, the /HNP command cannot work.");
return 1;
}
} else {
return 0;
}
}
sub integrity_check {
$openval = open(CONF, configFile());
if ($openval == 1) {
$is_album = 0;
$is_year = 0;
$is_track = 0;
$is_length = 0;
$is_bitrate = 0;
$is_size = 0;
$is_menu = 0;
$is_browser = 0;
$is_text_style = 0;
$is_text_color = 0;
while (<CONF>) {
@array = split("=", $_);
$opt = $array[0];
$val = $array[1];
chomp($opt);
chomp($val);
if ($opt eq "show_album") { if ($is_album == 0) { $is_album = 1; } else { close(CONF); return 1; } }
if ($opt eq "show_year") { if ($is_year == 0) { $is_year = 1; } else { close(CONF); return 1; } }
if ($opt eq "show_track") { if ($is_track == 0) { $is_track = 1; } else { close(CONF); return 1; } }
if ($opt eq "show_length") { if ($is_length == 0) { $is_length = 1; } else { close(CONF); return 1; } }
if ($opt eq "show_bitrate") { if ($is_bitrate == 0) { $is_bitrate = 1; } else { close(CONF); return 1; } }
if ($opt eq "show_size") { if ($is_size == 0) { $is_size = 1; } else { close(CONF); return 1; } }
if ($opt eq "show_menu") { if ($is_menu == 0) { $is_menu = 1; } else { close(CONF); return 1; } }
if ($opt eq "show_text_style") { if ($is_text_style == 0) { $is_text_style = 1; } else { close(CONF); return 1; } }
if ($opt eq "show_text_color") { if ($is_text_color == 0) { $is_text_color = 1; } else { close(CONF); return 1; } }
if ($opt eq "browser") { if ($is_browser == 0) { $is_browser = 1; } else { close(CONF); return 1; } }
if ($opt ne "show_album" && $opt ne "show_year" && $opt ne "show_track" && $opt ne "show_length" &&
$opt ne "show_bitrate" && $opt ne "show_size" && $opt ne "show_menu" && $opt ne "show_text_style" &&
$opt ne "show_text_color" && $opt ne "browser") {
close(CONF); return 1;
}
if ($opt ne "browser" && $val != 0 && $val != 1) { close(CONF); return 1; }
if ($opt eq "browser") {
if ($val ne "firefox" && $val ne "epiphany" && $val ne "konqueror" && $val ne "opera") {
close(CONF); return 1;
}
}
}
if ($is_album == 1 && $is_year == 1 && $is_track == 1 && $is_length == 1 && $is_bitrate == 1 &&
$is_size == 1 && $is_menu == 1 && $is_text_style == 1 && $is_text_color == 1 && $is_browser == 1) {
close(CONF); return 0;
} else {
close(CONF); return 1;
}
} else {
return 1;
}
}
sub load_menus {
if (load_integrity() == 0) {
$openval = open(CONF, configFile());
while (<CONF>) {
@array = split("=", $_);
$opt = $array[0];
$val = $array[1];
chomp($opt);
chomp($val);
if ($opt eq "show_menu") {
if ($val == 1) {
HexChat::command("MENU DEL HNP");
HexChat::command("MENU -p6 ADD HNP");
HexChat::command ("MENU ADD \"HNP/Show\"");
HexChat::command("MENU ADD \"HNP/Show/Standard\" \"HNP\"");
HexChat::command("MENU ADD \"HNP/Show/Simple\" \"HNPS\"");
HexChat::command("MENU ADD \"HNP/Show/Stats\" \"HNPSTATS\"");
HexChat::command("MENU ADD \"HNP/Show/Info\" \"HNPINFO\"");
HexChat::command("MENU ADD \"HNP/-\"");
HexChat::command("MENU ADD \"HNP/Clementine\"");
HexChat::command("MENU ADD \"HNP/-\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume/Mute\" \"HNPMUTE\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume/10%\" \"HNPVOL1\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume/20%\" \"HNPVOL2\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume/30%\" \"HNPVOL3\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume/40%\" \"HNPVOL4\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume/50%\" \"HNPVOL5\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume/60%\" \"HNPVOL6\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume/70%\" \"HNPVOL7\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume/80%\" \"HNPVOL8\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume/90%\" \"HNPVOL9\"");
HexChat::command("MENU ADD \"HNP/Clementine/Volume/Max\" \"HNPMAX\"");
HexChat::command("MENU ADD \"HNP/Clementine/-\"");
HexChat::command("MENU ADD \"HNP/Clementine/Play\" \"HNPPLAY\"");
HexChat::command("MENU ADD \"HNP/Clementine/Pause\" \"HNPPAUSE\"");
HexChat::command("MENU ADD \"HNP/Clementine/Stop\" \"HNPSTOP\"");
HexChat::command("MENU ADD \"HNP/Clementine/-\"");
HexChat::command("MENU ADD \"HNP/Clementine/Prev\" \"HNPPREV\"");
HexChat::command("MENU ADD \"HNP/Clementine/Next\" \"HNPNEXT\"");
HexChat::command("MENU ADD \"HNP/Clementine/-\"");
HexChat::command("MENU ADD \"HNP/Clementine/Start\" \"HNPRUN\"");
HexChat::command("MENU ADD \"HNP/Clementine/Quit\" \"HNPQUIT\"");
HexChat::command("MENU ADD \"HNP/Toggle\"");
HexChat::command("MENU ADD \"HNP/Toggle/Album\" \"TOGGLE_ALBUM\"");
HexChat::command("MENU ADD \"HNP/Toggle/Year\" \"TOGGLE_YEAR\"");
HexChat::command("MENU ADD \"HNP/Toggle/Track\" \"TOGGLE_TRACK\"");
HexChat::command("MENU ADD \"HNP/Toggle/Length\" \"TOGGLE_LENGTH\"");
HexChat::command("MENU ADD \"HNP/Toggle/Bitrate\" \"TOGGLE_BITRATE\"");
HexChat::command("MENU ADD \"HNP/Toggle/Size\" \"TOGGLE_SIZE\"");
HexChat::command("MENU ADD \"HNP/Toggle/Text Color\" \"TOGGLE_SHOW_TEXT_COLOR\"");
HexChat::command("MENU ADD \"HNP/Toggle/Text Style\" \"TOGGLE_SHOW_TEXT_STYLE\"");
HexChat::command("MENU ADD \"HNP/Set\"");
HexChat::command("MENU ADD \"HNP/Set/All ON\" \"ALL_ON\"");
HexChat::command("MENU ADD \"HNP/Set/All OFF\" \"ALL_OFF\"");
HexChat::command("MENU ADD \"HNP/Set/-");
HexChat::command("MENU ADD \"HNP/Set/Help Browser\"");
HexChat::command("MENU ADD \"HNP/Set/Help Browser/Firefox\" \"BROWSER1\"");
HexChat::command("MENU ADD \"HNP/Set/Help Browser/Epiphany\" \"BROWSER2\"");
HexChat::command("MENU ADD \"HNP/Set/Help Browser/Konqueror\" \"BROWSER3\"");
HexChat::command("MENU ADD \"HNP/Set/Help Browser/Opera\" \"BROWSER4\"");
HexChat::command("MENU ADD \"HNP/View\"");
HexChat::command("MENU ADD \"HNP/View/Modes\" \"HNPMODES\"");
HexChat::command("MENU ADD \"HNP/View/-");
HexChat::command("MENU ADD \"HNP/View/Homepage\" \"HNPHOME\"");
#HexChat::command("MENU ADD \"HNP/View/HNP How-To\" \"HNPHOWTO\"");
#HexChat::command("MENU ADD \"HNP/View/HNP FAQ\" \"HNPFAQ\"");
HexChat::command("MENU ADD \"HNP/View/-");
HexChat::command("MENU ADD \"HNP/View/Help\" \"HNPHELP\"");
HexChat::command("MENU ADD \"HNP/-\"");
HexChat::command("MENU ADD \"HNP/About\" \"HNPABOUT\"");
}
}
}
close(CONF);
}
return 0;
}
sub call_toggle_album {
cmds_toggle("show_album");
}
sub call_toggle_year {
cmds_toggle("show_year");
}
sub call_toggle_track {
cmds_toggle("show_track");
}
sub call_toggle_length {
cmds_toggle("show_length");
}
sub call_toggle_bitrate {
cmds_toggle("show_bitrate");
}
sub call_toggle_size {
cmds_toggle("show_size");
}
sub call_toggle_show_menu {
cmds_toggle("show_menu");
}
sub call_toggle_show_text_color {
cmds_toggle("show_text_color");
}
sub call_toggle_show_text_style {
cmds_toggle("show_text_style");
}
sub call_browser1 {
cmd_browser("firefox");
}
sub call_browser2 {
cmd_browser("epiphany");
}
sub call_browser3 {
cmd_browser("konqueror");
}
sub call_browser4 {
cmd_browser("opera");
}
sub cmds_toggle {
$toggle_opt = $_[0];
if (load_integrity() == 0) {
$openval = open(CONF, configFile());
$i = 0;
while (<CONF>) {
@array = split("=", $_);
$opt = $array[0];
$val = $array[1];
chomp($opt);
chomp($val);
if ($toggle_opt eq $opt) {
if ($val == 1) {
$ison = 1;
} elsif ($val == 0) {
$ison = 0;
}
} else {
$hold[$i] = "$_";
$i = $i + 1;
}
}
close(CONF);
$openval = open(CONF, ">" . configFile());
if ($ison == 1) {
print CONF "$toggle_opt=0\n";
} elsif ($ison == 0) {
print CONF "$toggle_opt=1\n";
}
$total = $i;
$i = 0;
while ($i < $total) {
print CONF "$hold[$i]";
$i = $i + 1;
}
close(CONF);
}
if ($ison == 1) {
if ($toggle_opt eq "show_menu") {
HexChat::command("MENU DEL HNP");
}
HexChat::print("\cC02HNP:\cC01 \cB$toggle_opt\cB is now \cBOFF\cB.");
} elsif ($ison == 0) {
if ($toggle_opt eq "show_menu") {
load_menus();
}
HexChat::print("\cC02HNP:\cC01 \cB$toggle_opt\cB is now \cBON\cB.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpabout {
HexChat::command ("GUI MSGBOX \"HNP 2.0.1\n\nHexChat Now Playing Script for Clementine 2.x\n\n(C) 2006-2015 Craciun Dan\n(C) 2010 John Aylward\n\nhttp://www.tuxarena.com/intro/xnp.php\"");
return HexChat::EAT_ALL;
}
sub cmd_browser {
$browser_opt = $_[0];
if (browser_installed("$browser_opt") == 0) {
if (load_integrity() == 0) {
$openval = open(CONF, configFile());
$change = "false";
$i = 0;
while (<CONF>) {
@array = split("=", $_);
$opt = $array[0];
$val = $array[1];
chomp($opt);
chomp($val);
if ($opt eq "browser") {
if ($val ne "$browser_opt") {
$change = "true";
}
} else {
$hold[$i] = "$_";
$i = $i + 1;
$total = $i;
}
}
close(CONF);
if ($change eq "true") {
$i = 0;
$openval = open(CONF, ">" . configFile());
while ($i <= $total) {
print CONF "$hold[$i]";
$i = $i + 1;
}
print CONF "browser=$browser_opt\n";
close(CONF);
HexChat::print("\cC02HNP:\cC01 The help \cBbrowser\cB is now set to \cB$browser_opt\cB.");
} else {
HexChat::print("\cC02HNP:\cC01 The help \cBbrowser\cB is already set to \cB$browser_opt\cB.");
}
}
} else {
HexChat::print("\cC02HNP:\cC01 The \cB$browser_opt\cB browser is not installed. Install it or try another browser.");
return HexChat::EAT_ALL;
}
return HexChat::EAT_ALL;
}
sub isRunning {
$META = `qdbus org.mpris.MediaPlayer2`;
return $META =~ /\/.*/
}
sub isPlaying {
$META = `qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 Metadata`;
return $META =~ /title: (.*)/
}
sub cmd_hnpmute {
if (isRunning()) {
system("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 Mute");
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpplay {
if (isRunning()) {
if (!isPlaying()) {
system ("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 Play");
}
} else {
HexChat::print ("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnppause {
if (isPlaying()) {
system ("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 Pause");
} else {
HexChat::print ("\cC02HNP:\cC01 Clementine is not running or is already paused or stopped.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpstop {
if (isPlaying()) {
system ("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 Stop");
} else {
HexChat::print ("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpprev {
system ("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 Prev");
return HexChat::EAT_ALL;
}
sub cmd_hnpnext {
system ("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 Next");
return HexChat::EAT_ALL;
}
sub cmd_hnprun {
system ("amarok");
return HexChat::EAT_ALL;
}
sub cmd_hnpquit {
system ("qdbus org.mpris.MediaPlayer2 /amarok/MainWindow close");
return HexChat::EAT_ALL;
}
sub cmd_hnpmax {
if (isRunning()) {
system ("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 VolumeSet 100");
HexChat::print("\cC02HNP:\cC01 Clementine volume is now maximum.");
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpvol {
if (isRunning()) {
$val = $_[0][1];
if ($val ne "") {
system("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 VolumeSet $val");
HexChat::print("\cC02HNP:\cC01 Clementine volume is now $val%.");
} else {
HexChat::print("\cC02HNP:\cC01 Usage: /HNPVOL <VOLUME>");
}
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpvol1 {
if (isRunning()) {
system("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 VolumeSet 10");
HexChat::print("\cC02HNP:\cC01 Clementine volume is now 10%.");
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpvol2 {
if (isRunning()) {
system("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 VolumeSet 20");
HexChat::print("\cC02HNP:\cC01 Clementine volume is now 20%.");
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpvol3 {
if (isRunning()) {
system("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 VolumeSet 30");
HexChat::print("\cC02HNP:\cC01 Clementine volume is now 30%.");
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpvol4 {
if (isRunning()) {
system("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 VolumeSet 40");
HexChat::print("\cC02HNP:\cC01 Clementine volume is now 40%.");
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpvol5 {
if (isRunning()) {
system("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 VolumeSet 50");
HexChat::print("\cC02HNP:\cC01 Clementine volume is now 50%.");
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpvol6 {
if (isRunning()) {
system("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 VolumeSet 60");
HexChat::print("\cC02HNP:\cC01 Clementine volume is now 60%.");
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpvol7 {
if (isRunning()) {
system("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 VolumeSet 70");
HexChat::print("\cC02HNP:\cC01 Clementine volume is now 70%.");
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpvol8 {
if (isRunning()) {
system("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 VolumeSet 80");
HexChat::print("\cC02HNP:\cC01 Clementine volume is now 80%.");
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpvol9 {
if (isRunning()) {
system("qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 VolumeSet 90");
HexChat::print("\cC02HNP:\cC01 Clementine volume is now 90%.");
} else {
HexChat::print("\cC02HNP:\cC01 Clementine is not running.");
}
return HexChat::EAT_ALL;
}
sub bold {
my ($str) = @_;
return "\cB" . $str . "\cB";
}
sub underline {
my ($str) = @_;
return "\c_" . $str . "\c_";
}
sub color1 {
my ($str) = @_;
return "\cC02" . $str . "\cO";
}
sub color2 {
my ($str) = @_;
return "\cC03" . $str . "\cO";
}
sub cmd_hnp {
if (load_integrity() == 0) {
if (isPlaying()) {
$openval = open(CONF, configFile());
while (<CONF>) {
@array = split("=", $_);
$opt = $array[0];
$val = $array[1];
chomp($opt);
chomp($val);
if ($opt eq "show_album") { if ($val == 0) { $show_album = 0; } else { $show_album = 1; } }
if ($opt eq "show_year") { if ($val == 0) { $show_year = 0; } else { $show_year = 1; } }
if ($opt eq "show_track") { if ($val == 0) { $show_track = 0; } else { $show_track = 1; } }
if ($opt eq "show_length") { if ($val == 0) { $show_length = 0; } else { $show_length = 1; } }
if ($opt eq "show_bitrate") { if ($val == 0) { $show_bitrate = 0; } else { $show_bitrate = 1; } }
if ($opt eq "show_size") { if ($val == 0) { $show_size = 0; } else { $show_size = 1; } }
if ($opt eq "show_text_color") { if ($val == 0) { $show_text_color = 0; } else { $show_text_color = 1; } }
if ($opt eq "show_text_style") { if ($val == 0) { $show_text_style = 0; } else { $show_text_style = 1; } }
}
close(CONF);
$QDBUS_POSITION = `qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 Position`;
$META = `qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 Metadata`;
$tmp_title = ( $META =~ /title: (.*)/ ? $1 : "" );
$tmp_artist = ( $META =~ /artist: (.*)/ ? $1 : "" );
chomp($tmp_title);
chomp($tmp_artist);
if ($tmp_title eq "" && $tmp_artist eq "") {
$tmp_filename = filename();
$artist = "";
$title = "$tmp_filename";
if ($show_text_style) {
$title = bold($title);
}
if ($show_text_color) {
$title = color1($title);
}
$title .= " ";
} else {
if ($tmp_title eq "") {
$title = "";
$artist = "by $artist ";
} else {
if ($tmp_artist eq "") {
$artist = "";
} else {
$title = $tmp_title;
$artist = $tmp_artist;
if ($show_text_style) {
$title = underline($title);
$artist = bold($artist);
}
if ($show_text_color) {
$title = color1($title);
$artist = color1($artist);
}
$title .= " ";
$artist = "by $artist ";
}
}
}
if ($show_album == 1) {
$tmp_album = ( $META =~ /album: (.*)/ ? $1 : "" );
chomp($tmp_album);
if ($tmp_album ne "") {
$album = $tmp_album;
if ($show_text_style) {
$album = underline($album);
}
if ($show_text_color) {
$album = color1($album);
}
$album = "from $album ";
} else {
$album = "";
}
} else {
$album = "";
}
if ($show_year == 1) {
$tmp_year = ( $META =~ /year: (\d{2,4})/ ? $1 : "" );
chomp($tmp_year);
if ($tmp_year != 0) {
$year = $tmp_year;
if ($show_text_style) {
$year = bold($year);
}
if ($show_text_color) {
$year = color2($year);
}
$year = "[$year] ";
} else {
$year = "";
}
} else {
$year = "";
}
if ($show_track == 1) {
$tmp_track = ( $META =~ /tracknumber: (\d*)/ ? $1 : "" );
chomp($tmp_track);
if ($tmp_track != 0) {
$track = $tmp_track;
if ($show_text_style) {
$track = bold($track);
}
if ($show_text_color) {
$track = color2($track);
}
$track = "[Track: $track] ";
} else {
$track = "";
}
} else {
$track = "";
}
if ($show_length == 1) {
$tmp_length = ( $META =~ /length: (\d*)/ ? $1 : "" );
chop($tmp_length);
if ($tmp_length ne "") {
use integer;
$tmp_length = $tmp_length / 100;
$seconds = sprintf("%02d", ($tmp_length / 1000) % 60);
$minutes = sprintf("%02d", ($tmp_length / 60000) % 60);
$hours = $tmp_length / 3600000;
if ($hours > 0) {
$duration = "$hours:$minutes:$seconds";
} else {
$duration = "$minutes:$seconds";
}
if ($show_text_style) {
$duration = bold($duration);
}
if ($show_text_color) {
$duration = color2($duration);
}
}
$tmp_duration = ( $QDBUS_POSITION =~ /(\d*)/ ? $1 : "" );
chop($tmp_duration);
if ($tmp_duration ne "") {
use integer;
$tmp_duration = $tmp_duration / 100;
$seconds = sprintf("%02d", ($tmp_duration / 1000) % 60);
$minutes = sprintf("%02d", ($tmp_duration / 60000) % 60);
$hours = $tmp_duration / 3600000;
if ($hours > 0) {
$position = "$hours:$minutes:$seconds";
} else {
$position = "$minutes:$seconds";
}
if ($show_text_style) {
$position = bold($position);
}
if ($show_text_color) {
$position = color2($position);
}
}
if ($position ne "" && $duration ne "") {
$length = "[$position / $duration] ";
} elsif ($position == "" && $duration ne "") {
$length = "[Duration: $duration] ";
} elsif ($position ne "" && $duration == "") {
$tmp_url = ( $META =~ /url: (.*)/ ? $1 : "" );
chomp($tmp_album);
$length = "[$tmp_url @ $position] ";
} else {
$length = "";
}
} else {
$length = "";
}
if ($show_bitrate == 1) {
$tmp_bitrate = ( $META =~ /bitrate: (.*)/ ? $1 : "" );
chomp($tmp_bitrate);
if ($tmp_bitrate ne "") {
$bitrate = $tmp_bitrate;
if ($show_text_style) {
$bitrate = bold($bitrate);
}
if ($show_text_color) {
$bitrate = color2($bitrate);
}
$bitrate = "[$bitrate kbps] ";
} else {
$bitrate = "";
}
} else {
$bitrate = "";
}
if ($show_size == 1) {
$size = filesize();
if ($size > 1) {
if ($show_text_style) {
$size = bold($size);
}
if ($show_text_color) {
$size = color2($size);
}
$size = "[Size: $size] ";
} else {
$size = "";
}
} else {
$size = "";
}
$line_HNP = "is listening to: $title$artist$album$year$track$length$bitrate$size";
chomp($line_HNP);
HexChat::command("ME $line_HNP");
} else {
HexChat::print("\cC02HNP:\cO Clementine is either stopped or paused.");
}
}
return HexChat::EAT_ALL;
}
sub cmd_hnps {
if (isPlaying()) {
$META = `qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 Metadata`;
$title = ( $META =~ /title: (.*)/ ? $1 : "(No Title)" );
$line_HNPs = "\cBRocks\cB with: \c_$title\c_";
HexChat::command("ME $line_HNPs");
} else {
HexChat::print("\cC02HNP:\cO Clementine is either stopped or paused.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpstats {
if (isPlaying()) {
HexChat::print("Not supported in Clementine 2.x at this time");
#$totalAlbums = `dcop Clementine collection totalAlbums`;
#$totalArtists = `dcop Clementine collection totalArtists`;
#$totalCompilations = `dcop Clementine collection totalCompilations`;
#$totalGenres = `dcop Clementine collection totalGenres`;
#$totalTracks = `dcop Clementine collection totalTracks`;
#chomp($totalAlbums);
#chomp($totalArtists);
#chomp($totalCompilations);
#chomp($totalGenres);
#chomp($totalTracks);
#$line_HNPstats = "\cOClementine Collection: [Tracks: \cC03$totalTracks\cO] [Artists: \cC03$totalArtists\cO] [Albums: \cC03$totalAlbums\cO] [Compilations: \cC03$totalCompilations\cO] [Genres: \cC03$totalGenres\cO] ";
#HexChat::command("SAY $line_HNPstats");
} else {
HexChat::print("\cC02HNP:\cO Clementine is not running or is paused.");
}
return HexChat::EAT_ALL;
}
sub cmd_hnpinfo {
if (isRunning()) {
#$totalAlbums = `dcop Clementine collection totalAlbums`;
#$totalArtists = `dcop Clementine collection totalArtists`;
#$totalCompilations = `dcop Clementine collection totalCompilations`;
#$totalGenres = `dcop Clementine collection totalGenres`;
#$totalTracks = `dcop Clementine collection totalTracks`;
#chomp($totalAlbums);
#chomp($totalArtists);
#chomp($totalCompilations);
#chomp($totalGenres);
#chomp($totalTracks);
if (isPlaying()) {
$META = `qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 Metadata`;
$tmp_title = ( $META =~ /title: (.*)/ ? $1 : "" );
$tmp_artist = ( $META =~ /artist: (.*)/ ? $1 : "" );
chomp($tmp_title);
chomp($tmp_artist);
if ($tmp_title eq "" && $tmp_artist eq "") {
$tmp_filename = filename();
$artist = "\cC02(No Title Field)\cO";
$title = "\cC02$tmp_filename\cO ";
} else {
if ($tmp_title eq "") {
$title = "\cC02(No Title Field\cO) ";
$artist = "\cC02$tmp_artist\cO";
} else {
if ($tmp_artist eq "") {
$title = "\cC02$tmp_title\cO";
$artist = "\cC02(No Artist Field)";
} else {
$title = "\cC02$tmp_title\cO";
$artist = "\cC02$tmp_artist\cO";
}
}
}
$tmp_album = ( $META =~ /album: (.*)/ ? $1 : "" );
chomp($tmp_album);
if ($tmp_album ne "") {
$album = "\cC02$tmp_album\cO";
} else {
$album = "\cC02(No Album Field)\cO";
}
$tmp_year = ( $META =~ /year: (.*)/ ? $1 : "" );
chomp($tmp_year);
if ($tmp_year != 0) {
$year = "\cC03$tmp_year\cO";
} else {
$year = "\cC03(No Year Field)\cO";
}
$tmp_track = ( $META =~ /tracknumber: (.*)/ ? $1 : "" );
chomp($tmp_track);
if ($tmp_track != 0) {
$track = "\cC03$tmp_track\cO";
} else {
$track = "\cC03(No Track Field)\cO";
}
$tmp_length = ( $META =~ /mtime: (.*)/ ? $1 : "" );
chop($tmp_length);
if ($tmp_length ne "") {
use integer;
$minutes = $tmp_length / 6000;
if ($minutes < 10) {
$minutes = "0" . $minutes;
}
$seconds = ($tmp_length / 100) % 60;
if ($seconds < 10) {
$seconds = "0" . $seconds;
}
$length = "\cC03$minutes:$seconds\cO";
} else {
$length = "\cC03(No Length Field)\cO";
}
$tmp_bitrate = ( $META =~ /audio-bitrate: (.*)/ ? $1 : "" );
chomp($tmp_bitrate);
if ($tmp_bitrate ne "") {
$bitrate = "\cC03$tmp_bitrate\cO";
} else {
$bitrate = "\cC03(No Bitrate Field)\cO";
}
$tmp_size = filesize();
$size = "\cC03$tmp_size\cO";
HexChat::print("---");
HexChat::print("\cC02HNP:\cO \cBRocks!\cB");
HexChat::print("\cC02HNP:\cO Title: \cC02$title");
HexChat::print("\cC02HNP:\cO Artist: \cC02$artist");
HexChat::print("\cC02HNP:\cO Album: \cC02$album");
HexChat::print("\cC02HNP:\cO Year: \cC03$year");
HexChat::print("\cC02HNP:\cO Track: \cC03$track");
HexChat::print("\cC02HNP:\cO Length: \cC03$length");
HexChat::print("\cC02HNP:\cO Bitrate: \cC03$bitrate");
HexChat::print("\cC02HNP:\cO Size: \cC03$size");
#HexChat::print("\cC02HNP:\cO \cBClementine Collection:\cB");
#HexChat::print("\cC02HNP:\cO Tracks: \cC03$totalTracks");
#HexChat::print("\cC02HNP:\cO Artists: \cC03$totalArtists");
#HexChat::print("\cC02HNP:\cO Albums: \cC03$totalAlbums");
#HexChat::print("\cC02HNP:\cO Compilations: \cC03$totalCompilations");
#HexChat::print("\cC02HNP:\cO Genres: \cC03$totalGenres");
HexChat::print("---");
} else {
HexChat::print("---");
HexChat::print("\cC02HNP:\cO Clementine is either stopped or paused.");
#HexChat::print("\cC02HNP:\cO \cBClementine Collection:\cB");
#HexChat::print("\cC02HNP:\cO Tracks: \cC03$totalTracks");
#HexChat::print("\cC02HNP:\cO Artists: \cC03$totalArtists");
#HexChat::print("\cC02HNP:\cO Albums: \cC03$totalAlbums");
#HexChat::print("\cC02HNP:\cO Compilations: \cC03$totalCompilations");
#HexChat::print("\cC02HNP:\cO Genres: \cC03$totalGenres");
HexChat::print("---");
}
} else {
HexChat::print("---");
HexChat::print("\cC02HNP:\cO Clementine is not running.");
HexChat::print("---");
}
return HexChat::EAT_ALL;
}
sub cmd_all_on {
if (load_integrity() == 0) {
$openval = open(CONF, configFile());
$allon = 1;
while (<CONF>) {
@array = split("=", $_);
$opt = $array[0];
$val = $array[1];
chomp($val);
if ($opt ne "browser" && $opt ne "show_menu" && $val == 0) {
$allon = 0;
}
if ($opt eq "show_menu" && $val == 0) {
$menu = 0;
}
if ($opt eq "show_menu" && $val == 1) {
$menu = 1;
}
if ($opt eq "browser") {
$browser = $val;
}
}
close(CONF);
if ($allon == 0) {
$openval = open(CONF, ">" . configFile());