This code started as one I had found, The only command that it had was /np which would show the current song in Rhythmbox into xchat.
What I have done is changed the output of the /np command to show Album and Genre, I have also added some more commands which people may find helpful.
Triggers are:
/np - Show's the current playing song.
/prev - Goes back to the previous song.
/next - Skips the current track and goes to the next in the playlist.
/pause - Pauses the current song.
/play - Resumes play on the current song.
#!/usr/bin/perl -w
Xchat::register("Rhythmbox Now Playing script for XChat by GrimReaper", "0.1", "Rhythmbox Now Playing script for XChat by GrimReaper" , "");
Xchat::hook_command("np", "nowPlaying");
Xchat::hook_command("next", "NPNext");
Xchat::hook_command("prev", "NPPrev");
Xchat::hook_command("pause", "NPPause");
Xchat::hook_command("play", "NPPlay");
sub nowPlaying
{
# Check if a rhythmbox process exists.
if (`ps -C rhythmbox` =~ /rhythmbox/) {
# Check if rhythmbox streams music
$title = `rhythmbox-client --print-playing-format %st`;
if (length $title > 1) {
$title = `rhythmbox-client --print-playing-format %st\\ -\\ %tt`;
} else {
$title = `rhythmbox-client --print-playing-format %ta\\ -\\ %tt\\ \002[\\\002Album:\\ %at\\\002][\002Genre:\\ %aG\\\002]\002`;
}
# Send out now playing line
chop $title;
Xchat::command("me is listening to " . $title);
} else {
Xchat::print("Rhythmbox is not running.");
}
}
sub NPNext
{
# Check if a rhythmbox process exists.
if (`ps -C rhythmbox` =~ /rhythmbox/) {
# Initiate the NEXT song command.
$NextTrack = `rhythmbox-client --next`;
# Send the NEXT command.
Xchat::command("" . $NextTrack);
Xchat::print("Skipped to the next track..");
} else {
Xchat::print("Rhythmbox is not currently running..");
}
}
sub NPPrev
{
# Check if a rhythmbox process exists.
if (`ps -C rhythmbox` =~ /rhythmbox/) {
# Initiate the PREVIOUS song command
$PrevTrack = `rhythmbox-client --previous`;
# Send the PREVIOUS command.
Xchat::command("" . $PrevTrack);
Xchat::print("Skipping back to the previous track..");
} else {
Xchat::print("Rhythmbox is not currently running..");
}
}
sub NPPause
{
# Check if a rhythmbox process exists.
if (`ps -C rhythmbox` =~ /rhythmbox/) {
# Initiate the PAUSE song command
$PauseTrack = `rhythmbox-client --pause`;
# Send the PAUSE command.
Xchat::command("" . $PauseTrack);
Xchat::print("Pausing the current track..");
} else {
Xchat::print("Rhythmbox is not currently running..");
}
}
sub NPPlay
{
# Check if a rhythmbox process exists.
if (`ps -C rhythmbox` =~ /rhythmbox/) {
# Initiate the PLAY command
$PlayTrack = `rhythmbox-client --play`;
# Send the PLAY command.
Xchat::command("" . $PlayTrack);
Xchat::print("Play resumed for current track..");
} else {
Xchat::print("Rhythmbox is not currently running..");
}
}
To install this script into your Xchat, Copy and paste the contents above and paste into a Unique file something like rhythmbox.pl
Then place the file into your xchat folder which is usually located in your /home directory on Linux.
If you can't see the xchat folder that's because it is usually hidden by default. So press Ctrl+H then look for a folder names .xchat2 and place it in there.
I will do @Hawkee .. To be honest that's the first snippet I have posted since the re-vamp.. and It's awesome.. :) It's also my first Perl script.. Even tho I just modded it to work better and added a few commands.
Ok.. Will change it in a second @Hawkee