Roadmap
Attachment 'irssi_audacious_v1.0.4.pl'
Download 1 use strict;
2 use vars qw($VERSION %IRSSI);
3 # Audacious Irssi Script v1.0.4
4 #
5 # Change Log:
6 # v1.0.4:
7 # - Added Repeat on/off capability
8 # - Added Shuffle on/off capability
9 # - Fixed script output handling for audacious version in case audacious isn't running
10 # - If encountered a problem with audacious version, try changing `audacious --version` to `audtool -v`
11 # v1.0.3:
12 # - Added Playlist functionality
13 # - Added Song details (Bitrate/Frequency/Length/Volume)
14 # - Current song notice with song details (Optional)
15 # v1.0.2:
16 # - The script now handles warning support if you got audacious not running
17 # - Added track number, current time elapse and total track time
18 # - Added Stop functionality
19 # v1.0.1:
20 # - Added ability to autonotify the channel after skipping a song (optional)
21 # - Added Skip/Play/Pause/Resume calls
22 #
23 # How To Use?
24 # Copy your script into ~/.irssi/scripts/ directory
25 # Load your script with /script load audacious in your Irssi Client
26 # Type '/audacious help' in any channel for script commands
27 # For autoload insert your script into ~/.irssi/scripts/autorun/ directory
28 # Even better would be if you placed them in ~/.irssi/scripts/ and created symlinks in autorun directory
29 #
30 use Irssi;
31 $VERSION = '1.0.4';
32 %IRSSI = (
33 authors => "Dani Soufi",
34 contact => "IRC: FreeNode Network, #Ubuntu-LB",
35 name => "Audacious Irssi Script",
36 description => "Displays Current Song".
37 "Skips/Plays/Pauses/Stops/Resumes/Shuffles/Repeats Songs".
38 "Displays Script/Player's Current Version".
39 "Current Song Details",
40 license => "Public Domain",
41 );
42
43 sub cmd_song {
44 my ($data, $server, $witem) = @_;
45 # Get current song information.
46 # If you want song details to be displayed
47 # directly with the current song:
48 # - Uncomment lines: 50/51/56/57/60
49 # -* Comment line 59 (Important)
50 if ($witem && ($witem->{type} eq "CHANNEL")) {
51 if (`ps -C audacious` =~ /audacious/) {
52 my $position = `audtool --playlist-position`;
53 my $song = `audtool --current-song`;
54 my $current = `audtool --current-song-output-length`;
55 my $total = `audtool --current-song-length`;
56 # my $bitrate = `audtool --current-song-bitrate-kbps`; #line 50
57 # my $frequency = `audtool --current-song-frequency-khz`; #line 51
58 chomp($song);
59 chomp($position);
60 chomp($current);
61 chomp($total);
62 # chomp($bitrate); #line 56
63 # chomp($frequency); #line 57
64
65 $witem->command("/me is listening to: #$position | $song ($current/$total)"); #line 59
66 # $witem->command("/me is listening to: #$position | $song ($current/$total) [$bitrate kbps/$frequency khz]"); #line 60
67 }
68 else {
69 $witem->print("Audacious is not currently running.");
70 }
71 return 1;
72 }
73 }
74
75 sub cmd_next {
76 my ($data, $server, $witem) = @_;
77 # Skip to the next track.
78 if ($witem && ($witem->{type} eq "CHANNEL")) {
79 if (`ps -C audacious` =~ /audacious/) {
80 my $next = `audtool --playlist-advance`;
81 # Uncomment those lines if you want the script to
82 # automatically notify the channel to what song you have skipped
83 # my $position = `audtool --playlist-position`;
84 # my $song = `audtool --current-song`;
85 # chomp($position);
86 # chomp($song);
87
88 $witem->print("Skipped to next track.");
89 # $witem->command("/me has skipped to: #$position $song");
90 }
91 else {
92 $witem->print("Can't skip to next track. Check your Audacious.");
93 }
94 return 1;
95 }
96 }
97
98 sub cmd_previous {
99 my ($data, $server, $witem) = @_;
100 # Skip to the previous track.
101 if ($witem && ($witem->{type} eq "CHANNEL")) {
102 if (`ps -C audacious` =~ /audacious/) {
103 my $reverse = `audtool --playlist-reverse`;
104 # Uncomment those lines if you want the script to
105 # automatically notify the channel to what song you have skipped
106 # my $position = `audtool --playlist-position`;
107 # my $song = `audtool --current-song`;
108 # chomp($position);
109 # chomp($song);
110
111 $witem->print("Skipped to previous track.");
112 # $witem->command("/me has skipped to: #$position $song");
113 }
114 else {
115 $witem->print("Can't skip to next track. Check your Audacious.");
116 }
117 return 1;
118 }
119 }
120
121 sub cmd_play {
122 my ($data, $server, $witem) = @_;
123 # Start playback.
124 if ($witem && ($witem->{type} eq "CHANNEL")) {
125 if (`ps -C audacious` =~ /audacious/) {
126 my $play = `audtool --playback-play`;
127
128 $witem->print("Started playback.");
129 }
130 else {
131 $witem->print("Playback can't be performed now.");
132 }
133 return 1;
134 }
135 }
136
137 sub cmd_pause {
138 my ($data, $server, $witem) = @_;
139 # Pause playback.
140 if ($witem && ($witem->{type} eq "CHANNEL")) {
141 if (`ps -C audacious` =~ /audacious/) {
142 my $pause = `audtool --playback-pause`;
143
144 $witem->print("Paused playback.");
145 }
146 else {
147 $witem->print("Pause can be only performed when Audacious is running.");
148 }
149 return 1;
150 }
151 }
152
153 sub cmd_stop {
154 my ($data, $server, $witem) = @_;
155 # Pause playback.
156 if ($witem && ($witem->{type} eq "CHANNEL")) {
157 if (`ps -C audacious` =~ /audacious/) {
158 my $stop = `audtool --playback-stop`;
159
160 $witem->print("Stopped playback.");
161 }
162 else {
163 $witem->print("This way you can't start Audacious.");
164 }
165 return 1;
166 }
167 }
168
169 sub cmd_playlist {
170 my ($data, $server, $witem) = @_;
171 # Displays entire playlist loaded.
172 if (`ps -C audacious` =~ /audacious/) {
173 my $display = `audtool --playlist-display`;
174 chomp($display);
175
176 Irssi::print("$display");
177 }
178 else {
179 $witem->print("Start your player first.");
180 }
181 return 1;
182 }
183
184 sub cmd_shuffle {
185 my ($data, $server, $witem) = @_;
186 # Turns shuffle on/off
187 if ($witem && ($witem->{type} eq "CHANNEL")) {
188 if (`ps -C audacious` =~ /audacious/) {
189 my $shuffle = `audtool --playlist-shuffle-toggle`;
190 my $shuffle_status = `audtool --playlist-shuffle-status`;
191 chomp($shuffle);
192 chomp($shuffle_status);
193
194 if ($shuffle eq "on") {
195 $witem->print("Shuffle is now $shuffle_status");
196 }
197 else {
198 $witem->print("Shuffle is now $shuffle_status");
199 }
200 }
201 else {
202 $witem->print("Can't perform this action.");
203 }
204 return 1;
205 }
206 }
207
208 sub cmd_repeat {
209 my ($data, $server, $witem) = @_;
210 # Turns repeat on/off
211 if ($witem && ($witem->{type} eq "CHANNEL")) {
212 if (`ps -C audacious` =~ /audacious/) {
213 my $repeat = `audtool --playlist-repeat-toggle`;
214 my $repeat_status = `audtool --playlist-repeat-status`;
215 chomp($repeat);
216 chomp($repeat_status);
217
218 if ($repeat eq "on") {
219 $witem->print("Repeat is now $repeat_status");
220 }
221 else {
222 $witem->print("Repeat is now $repeat_status");
223 }
224 }
225 else {
226 $witem->print("Can't perform this action.");
227 }
228 return 1;
229 }
230 }
231
232 sub cmd_details {
233 my ($data, $server, $witem) = @_;
234 # Displays current song's details.
235 if ($witem && ($witem->{type} eq "CHANNEL")) {
236 if (`ps -C audacious` =~ /audacious/) {
237 my $bitrate = `audtool --current-song-bitrate-kbps`;
238 my $frequency = `audtool --current-song-frequency-khz`;
239 my $length = `audtool --current-song-length`;
240 my $volume = `audtool --get-volume`;
241 chomp($bitrate);
242 chomp($frequency);
243 chomp($length);
244 chomp($volume);
245
246 $witem->print("Current song details: rate: $bitrate kbps - freq: $frequency khz - l: $length min - vol: $volume");
247 }
248 else {
249 $witem->print("Your player doesn't seem to be running");
250 }
251 return 1;
252 }
253 }
254
255 sub cmd_version {
256 my ($data, $server, $witem) = @_;
257 # Displays version information to the channel.
258 # For those who have problems with this
259 # try changing `audacious --version` to `audtool -v`
260 if ($witem && ($witem->{type} eq "CHANNEL")) {
261 if (`ps -C audacious` =~ /audacious/) {
262 my $audacious_version = `audacious --version`;
263 chop $audacious_version;
264
265 $witem->command("/me is running: Audacious Irssi Script v$VERSION with ".$audacious_version);
266 }
267 else {
268 $witem->command("/me is running: Audacious Irssi Script v$VERSION");
269 }
270 return 1;
271 }
272 }
273
274 sub cmd_help {
275 my ($data, $server) = @_;
276 # Displays usage screen.
277 Irssi::print("* /audacious song - Display the current song playing to a channel.");
278 Irssi::print("* /audacious next - Start playback.");
279 Irssi::print("* /audacious previous - Start playback.");
280 Irssi::print("* /audacious play - Start playback.");
281 Irssi::print("* /audacious pause - Pause playback.");
282 Irssi::print("* /audacious stop - Stop playback.");
283 Irssi::print("* /audacious playlist - Displays entire playlist.");
284 Irssi::print("* /audacious shuffle - Turns shuffle on/off.");
285 Irssi::print("* /audacious repeat - Turns repeat on/off.");
286 Irssi::print("* /audacious details - Displays current song's details");
287 Irssi::print("* /audacious about - Displays version of the script and audacious in the channel.");
288 }
289
290 sub cmd_audacious {
291 my ($data, $server, $witem) = @_;
292 if ($data =~ m/^[(song)|(next)|(previous)|(play)|(pause)|(stop)|(help)|(playlist)|(shuffle)|(repeat)|(details)|(about)]/i) {
293 Irssi::command_runsub('audacious', $data, $server, $witem);
294 }
295 else {
296 Irssi::print("Use /audacious <option> or check /help audacious for the complete list");
297 }
298 }
299
300 Irssi::command_bind ('audacious song', 'cmd_song');
301 Irssi::command_bind ('audacious next', 'cmd_next');
302 Irssi::command_bind ('audacious previous', 'cmd_previous');
303 Irssi::command_bind ('audacious play', 'cmd_play');
304 Irssi::command_bind ('audacious pause', 'cmd_pause');
305 Irssi::command_bind ('audacious stop', 'cmd_stop');
306 Irssi::command_bind ('audacious help', 'cmd_help');
307 Irssi::command_bind ('audacious playlist', 'cmd_playlist');
308 Irssi::command_bind ('audacious shuffle', 'cmd_shuffle');
309 Irssi::command_bind ('audacious repeat', 'cmd_repeat');
310 Irssi::command_bind ('audacious details', 'cmd_details');
311 Irssi::command_bind ('audacious about', 'cmd_version');
312 Irssi::command_bind ('audacious', 'cmd_audacious');
313
314 Irssi::print("Audacious Irssi Script v$VERSION is loaded successfully");
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.