#!/usr/bin/perl ## # X-Chat audtool np script v0.10 # (c) 2005 NhJm # # http://nhjm.net/ ## # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## use strict; use Time::HiRes qw(gettimeofday tv_interval usleep); my $audtool_version = "0.10"; my $audtool_exectime = 0; Xchat::register("audtool", "$audtool_version", "X-Chat audtool np script"); Xchat::hook_command("np", "audtool_handler"); Xchat::hook_command("aud", "audtool_control"); my ($bld, $und) = (chr(2), chr(31)); audtool_print("${bld}X-Chat audtool np script v$audtool_version loaded!${bld}"); # Note: Do not put a "/" at the beginning of the following strings! my $audtool_format = "say ${bld}np: [${bld} %song% ${bld}(${bld}%fileformat%${bld}) ] - [${bld} %elapsed%/%length% ${bld}] - [${bld} %bitrate%Kbps @ %frequency%kHz ${bld}] - [${bld} %percent%% ${bld}] - [${bld}%progressbar%${bld}]${bld}"; my $audtool_notrunning = "say ${bld}np: [${bld} None ${bld}]${bld}"; sub audtool_print { Xchat::print("${bld}${und}audtool${und}${bld}\t@_"); } sub audtool_getinfo { my $audtool_cmd = shift; my $audtool_info = `audtool $audtool_cmd`; chomp $audtool_info; return $audtool_info; } sub audtool_exec { my $audtool_cmd = shift; Xchat::command("exec audtool $audtool_cmd"); } sub audtool_control { my $audtool_cmd = $_[0][1]; $audtool_cmd = lc($audtool_cmd); # audtool_print(">> $audtool_cmd <<") if ($audtool_cmd ne ""); if ($audtool_cmd =~ /^play$/) { audtool_exec("playback-play"); } elsif ($audtool_cmd =~ /^pause$/) { audtool_exec("playback-pause"); } elsif ($audtool_cmd =~ /^stop$/) { audtool_exec("playback-stop"); } elsif ($audtool_cmd =~ /^n(?:ext|)$/) { audtool_exec("playlist-advance"); } elsif ($audtool_cmd =~ /^p(?:rev(?:ious|)|)$/) { audtool_exec("playlist-reverse"); } elsif ($audtool_cmd =~ /^j(?:ump|)$/) { if ($_[0][2] ne "") { audtool_exec("playlist-jump $_[0][2]"); } else { my $random = (int(rand() * audtool_getinfo("playlist-length")) + 1); while ($random eq audtool_getinfo("playlist-position")) { $random = (int(rand() * audtool_getinfo("playlist-length")) + 1); } audtool_exec("playlist-jump " . $random); } } elsif ($audtool_cmd =~ /^a(?:dd(?:url|)|)$/) { audtool_exec("playlist-addurl $_[0][2]"); } elsif ($audtool_cmd =~ /^v(?:ol|)$/) { if ($_[0][2] ne "") { my $audtool_volume_old = audtool_getinfo("get-volume"); audtool_exec("set-volume $_[0][2]"); usleep 100000; my $audtool_volume_new = audtool_getinfo("get-volume"); audtool_print("Volume: $audtool_volume_old% -> $audtool_volume_new%"); } else { my $audtool_volume = audtool_getinfo("get-volume"); audtool_print("Volume: $audtool_volume%"); } } elsif ($audtool_cmd =~ /^h(?:elp|)$/) { audtool_print("Commands: play - Plays the current song pause - Pauses the current song stop - Stops the current song next - Plays the next song previous - Plays the previous song jump [#] - Jumps to a (random) position in the playlist addurl - Add a file to the playlist vol [vol] - Shows the volume and changes it if wanted help - Prints this message"); } else { audtool_print("Usage: /aud "); } return 1; } sub audtool_handler { my $t0 = [gettimeofday] if ($audtool_exectime); my $audtool_song = audtool_getinfo("current-song"); if ($audtool_song !~ /audacious server is not running/) { my $audtool_fileformat = audtool_getinfo("playlist-filename"); $audtool_fileformat =~ s/^.*\.//; $audtool_fileformat = uc($audtool_fileformat); my $audtool_length = audtool_getinfo("current-song-length"); my $audtool_length_frames = audtool_getinfo("current-song-length-frames"); my $audtool_elapsed = audtool_getinfo("current-song-output-length"); my $audtool_elapsed_frames = audtool_getinfo("current-song-output-length-frames"); my $audtool_bitrate = audtool_getinfo("current-song-bitrate"); my $audtool_frequency = audtool_getinfo("current-song-frequency"); $audtool_bitrate = $audtool_bitrate/1000; $audtool_frequency = $audtool_frequency/1000; my ($audtool_percent, $audtool_progressbar); if ($audtool_length_frames > 1) { $audtool_percent = ($audtool_elapsed_frames / $audtool_length_frames * 100); $audtool_percent = sprintf("%2.2f", $audtool_percent); $audtool_progressbar = "|" x int($audtool_percent / 10); $audtool_progressbar .= "-" while(length($audtool_progressbar) < 10); } else { $audtool_percent = 0; $audtool_progressbar = "----------"; } my $audtool_output = $audtool_format; if ($audtool_output =~ /%song%/) { $audtool_output =~ s/%song%/$audtool_song/g; } if ($audtool_output =~ /%fileformat%/) { $audtool_output =~ s/%fileformat%/$audtool_fileformat/g; } if ($audtool_output =~ /%length%/) { $audtool_output =~ s/%length%/$audtool_length/g; } if ($audtool_output =~ /%elapsed%/) { $audtool_output =~ s/%elapsed%/$audtool_elapsed/g; } if ($audtool_output =~ /%percent%/) { $audtool_output =~ s/%percent%/$audtool_percent/g; } if ($audtool_output =~ /%progressbar%/) { $audtool_output =~ s/%progressbar%/$audtool_progressbar/g; } if ($audtool_output =~ /%bitrate%/) { $audtool_output =~ s/%bitrate%/$audtool_bitrate/g; } if ($audtool_output =~ /%frequency%/) { $audtool_output =~ s/%frequency%/$audtool_frequency/g; } Xchat::command("$audtool_output"); } else { Xchat::command("$audtool_notrunning"); } Xchat::command("say Exec time: " . tv_interval($t0) . "s") if ($audtool_exectime); return 1; }