This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
curplay.pl
229 lines (189 loc) · 8.09 KB
/
curplay.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
#!/usr/bin/perl
use strict;
use Xchat qw( :all );
my $version = "1.0.21";
my $settings = `cat ~/.asaconf`; # TODO: Find better way to do this. I know there is one, but i'm lazy -- cj1
Xchat::register("Clarjon1 and Kevin147's annoying Song Announcer",$version,"Amarok/clemntine xchat info");
# Checks to see if user has set the player in the settings file.
#if not, default to Amarok
my ($player) = ($settings =~ /player-dbus: (.*)/ ? $1 : "org.mpris.amarok" );
#tells xchat to pass curplay onto it
IRC::add_command_handler("curplay", "cmd_amacurplay");
sub cmd_amacurplay {
if(!$_[0]){
announce();
}
elsif($_[0] eq "next"){
playnext();
}
elsif($_[0] eq "prev"){
playprev();
}
elsif($_[0] eq "play"){
if($player eq "org.mpris.amarok"){ playpause();}
elsif($player eq "org.mpris.clementine"){clemplay();}
}
elsif($_[0] eq "pause"){
playpause();
}
elsif($_[0] eq "stop"){
playstop();
}
elsif($_[0] eq "exit"){
playexit();
}
elsif($_[0] eq "start"){
playstart();
}
elsif($_[0] eq "version"){
playversion();
}
elsif($_[0] eq "boring"){
playboring();
}
elsif($_[0] eq "reload"){
reload();
}
else{
IRC::print("usage: /curplay [boring|next|prev|play|pause|stop|exit|start|reload|version]");
}
return Xchat::EAT_ALL;
}
sub reload{
$settings = `cat ~/.asaconf`;
($player) = ($settings =~ /player-dbus: (.*)/ ? $1 : "org.mpris.amarok" );
IRC::print("Settings reloaded.");
}
sub playboring{
my $META = `qdbus $player /Player GetMetadata`;
my $META2 = "volume: " . `qdbus $player /Player VolumeGet`;
my $META3 = "getcurrenttrack: " . `qdbus $player /TrackList GetCurrentTrack`;
my $RANGE = 15;
my ($ARTIST) = ( $META =~ /artist: (.*)/ ? $1 : "-" );
my ($TITLE) = ( $META =~ /title: (.*)/ ? $1 : "not playing" );
my ($ALBUM) = ( $META =~ /album: (.*)/ ? $1 : "-" );
my ($VOLUME) = ( $META2 =~ /volume: (.*)/ ? $1 : "-" );
my ($BITRATE) = ( $META =~ /audio-bitrate: (.*)/ ? $1 : "-" );
my ($SAMPLERATE) = ( $META =~ /audio-samplerate: (.*)/ ? $1 : "-" );
my ($GETTRACK) = ( $META3 =~ /getcurrenttrack: (.*)/ ? $1 : "-" );
my ($time_total_secs) = ( $META =~ /mtime: (.+)/ ? $1 : "--" );
$time_total_secs /= 1000;
my $time_played_secs = `qdbus $player /Player PositionGet`;
$time_played_secs /= 1000;
my $time_remaining_secs = $time_total_secs - $time_played_secs;
# Zeiten in richtige Minutenangabe umwandeln
my @time_total = (0, $time_total_secs % 60);
$time_total[0] = ($time_total_secs - $time_total[1]) / 60;
my @time_played = (0, $time_played_secs % 60);
$time_played[0] = ($time_played_secs - $time_played[1]) / 60;
my @time_remaining = (0, $time_remaining_secs % 60);
$time_remaining[0] = ($time_remaining_secs - $time_remaining[1]) / 60;
# Text bauen und ausgeben
# Gesamtzeit
# my $text = 'Total time of track is '.$time_total[0].':';
# if ($time_total[1] < 10) { $text .= '0'; }
# $text .= $time_total[1];
# Gespielte Zeit
my $text = ''.roundit($time_played[0]).':';
if ($time_played[1] < 10) { $text .= '0'; }
$text .= $time_played[1];
# Verbleibende Zeit
#$text .= ' /'.roundit($time_remaining[0]).':';
$text .= ' /'.roundit($time_total[0]).':';
if ($time_total[1] < 10) { $text .= '0'; }
$text .= $time_total[1].'';
IRC::command("/me is currently listening to [['$TITLE']] by [['$ARTIST']] from the album [['$ALBUM']] at [['$VOLUME%']] Volume, at position [['".$text."']], bitrate [['$BITRATE']], samplerate [['$SAMPLERATE']] And, Playlist Track Number: [['$GETTRACK']] ASAocd");
sub roundit{
my $number =shift;
return int($number + .5 * ($number <=> 0));
}
}
sub announce{
my $META = `qdbus $player /Player GetMetadata`;
my $META2 = "volume: " . `qdbus $player /Player VolumeGet`;
my $META3 = "getcurrenttrack: " . `qdbus $player /TrackList GetCurrentTrack`;
my $RANGE = 15;
my $RAND1 = int(rand($RANGE));
my $RAND2 = int(rand($RANGE));
my $RAND3 = int(rand($RANGE));
my ($ARTIST) = ( $META =~ /artist: (.*)/ ? $1 : "-" );
my ($TITLE) = ( $META =~ /title: (.*)/ ? $1 : "not playing" );
my ($ALBUM) = ( $META =~ /album: (.*)/ ? $1 : "-" );
my ($VOLUME) = ( $META2 =~ /volume: (.*)/ ? $1 : "-" );
my ($BITRATE) = ( $META =~ /audio-bitrate: (.*)/ ? $1 : "-" );
my ($SAMPLERATE) = ( $META =~ /audio-samplerate: (.*)/ ? $1 : "-" );
my ($GETTRACK) = ( $META3 =~ /getcurrenttrack: (.*)/ ? $1 : "-" );
my ($time_total_secs) = ( $META =~ /mtime: (.+)/ ? $1 : "--" );
$time_total_secs /= 1000;
my $time_played_secs = `qdbus $player /Player PositionGet`;
$time_played_secs /= 1000;
my $time_remaining_secs = $time_total_secs - $time_played_secs;
# Zeiten in richtige Minutenangabe umwandeln
my @time_total = (0, $time_total_secs % 60);
$time_total[0] = ($time_total_secs - $time_total[1]) / 60;
my @time_played = (0, $time_played_secs % 60);
$time_played[0] = ($time_played_secs - $time_played[1]) / 60;
my @time_remaining = (0, $time_remaining_secs % 60);
$time_remaining[0] = ($time_remaining_secs - $time_remaining[1]) / 60;
# Text bauen und ausgeben
# Gesamtzeit
# my $text = 'Total time of track is '.$time_total[0].':';
# if ($time_total[1] < 10) { $text .= '0'; }
# $text .= $time_total[1];
# Gespielte Zeit
my $text = ''.roundit($time_played[0]).':';
if ($time_played[1] < 10) { $text .= '0'; }
$text .= $time_played[1];
# Verbleibende Zeit
#$text .= ' /'.roundit($time_remaining[0]).':';
$text .= ' /'.roundit($time_total[0]).':';
if ($time_total[1] < 10) { $text .= '0'; }
$text .= $time_total[1].'';
IRC::command("/me \002\003".$RAND1."is currently listening to \003".$RAND2."[[\003".$RAND3."'$TITLE'\003".$RAND2."]] \003".$RAND1."by \003".$RAND2."[[\003".$RAND3."'$ARTIST'\003".$RAND2."]] \003".$RAND1."from the album \003".$RAND2."[[\003".$RAND3."'$ALBUM'\003".$RAND2."]] \003".$RAND1."at \003".$RAND2."[[\003".$RAND3."'$VOLUME%'\003".$RAND2."]]\003".$RAND1." Volume, at position \003".$RAND2."[[\003".$RAND3."'".$text."\003".$RAND2."']]\003".$RAND1.", bitrate \003".$RAND2."[[\003".$RAND3."'$BITRATE'\003".$RAND2."]] \003".$RAND1."samplerate \003".$RAND2."[[\003".$RAND3."'$SAMPLERATE'\003".$RAND2."]] \003".$RAND1."And, Playlist Track Number \003".$RAND2."[[\003".$RAND3."'$GETTRACK'\003".$RAND2."]] ASAocd");
sub roundit{
my $number =shift;
return int($number + .5 * ($number <=> 0));
}
}
sub playnext {
IRC::print("Playing Next Song");
system('qdbus '.$player.' /Player Next');
}
sub playprev {
IRC::print("Playing Previous Song");
system('qdbus '.$player.' /Player Prev');
}
sub clemplay {
IRC::print("Playing Song");
system('qdbus '.$player.' /Player Play');
}
sub playpause {
IRC::print("Playing/Pausing Song");
if($player eq "org.mpris.amarok"){ system("qdbus org.mpris.amarok /Player PlayPause");}
elsif($player eq "org.mpris.clementine"){system("qdbus org.mpris.clementine /Player Pause");}
}
sub playstop {
IRC::print("Stopping Song");
system('qdbus '.$player.' /Player Stop');
}
sub playexit {
IRC::print("Stopping Player");
if($player eq "org.mpris.clementine"){ IRC::print("This doesn't work for clementine yet");}
system('qdbus '.$player.' /MainApplication quit');
}
sub playstart {
my $RANGE = 15;
my $RAND1 = int(rand($RANGE));
my $RAND2 = int(rand($RANGE));
my $RAND3 = int(rand($RANGE));
IRC::command("/me \003".$RAND1."is now \003".$RAND2."Starting \003".$RAND3."The Music! ");
if($player eq "org.mpris.amarok"){ system("amarok &");}
elsif($player eq "org.mpris.clementine"){system("clementine &");}
}
sub playversion {
my $RANGE = 15;
my $RAND1 = int(rand($RANGE));
my $RAND2 = int(rand($RANGE));
my $RAND3 = int(rand($RANGE));
IRC::command("/me \003".$RAND1."is using \003".$RAND2."the homegrown \003".$RAND3."Clarjon1 and Kevin147's \003".$RAND1."Annoying \003".$RAND2."Song\003".$RAND3." Announcer on-chat-display (ASAocd) \003".$RAND2."VERSION\003".$RAND1." ".$version."!! Hosted on Github ( https://github.com/clarjon1/Annoying-Song-Announcer ) ");
}