Rhythmbox Now Playing

By GrimReaper on Feb 14, 2013

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.

Comments

Sign in to comment.
Hawkee   -  Feb 14, 2013

@GrimReaper I added X-Chat to our platform list so you can label this better.

GrimReaper  -  Feb 14, 2013

Ok.. Will change it in a second @Hawkee

Hawkee  -  Feb 14, 2013

Great, the new snippet system allows for a more clear distinction between platforms and programming languages since the two are not mutually exclusive. If you find we're missing a platform just let me know and I can add it.

GrimReaper  -  Feb 14, 2013

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.

DragonHeart  -  Mar 17, 2013

now you have to explain how to install this in XChat ;)

GrimReaper  -  Mar 17, 2013

Good point, I never explained that.. [Edits the description]

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.