All pastes #513820 Raw Edit

Miscellany

public text v1 · immutable
#513820 ·published 2007-05-27 13:01 UTC
rendered paste body
#!/usr/bin/perl -w

# Rhythmbox irssi Announcer 0.1
# (c) Copyright 2006, 2007 - Paul Foote <pfoote@gmail.com>                                                           
# based loosely on Rhythmbox XChat Announcer 0.3                                                                     
# by Tim Denholm <tim@codestorm.net>
# + Thanks to moch for the DBUS info
#                  
# 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 vars qw($VERSION %IRSSI);
        
use Irssi;
$VERSION = '1.00'; 
%IRSSI = (
    authors     => 'Paul Foote',                                                                                     
    contact     => 'pfoote@gmail.com',                                                                               
    name        => 'Rhythmbox irssi Announcer',                                                                      
    description => 'Announces the current playing ' .                                                                
                   'song information from ' .
                   'Rhythmbox in irssi.',                                                                            
    license     => 'GPL',                                                                                            
);                                                                                                                   


sub rb_announce {
    my ($data, $server, $witem) = @_;
    #check to see rhytmbox is running
    if (`ps -C rhythmbox` =~ /rhythmbox/) {
        # OK it's running - lets grab the DBUS pipe and set the env var...
        my $RHYTHMBOXPID = `pidof rhythmbox`;
        chomp $RHYTHMBOXPID;
        my $DBUSPIPEINFO = `strings /proc/$RHYTHMBOXPID/environ | grep DBUS_SESSION_BUS_ADDRESS`;
        chomp $DBUSPIPEINFO; 
        $DBUSPIPEINFO =~ s/DBUS_SESSION_BUS_ADDRESS=//;
        $ENV{'DBUS_SESSION_BUS_ADDRESS'} = $DBUSPIPEINFO;
        # done, now lets get the song info
        my $SONGINFO = `rhythmbox-client --print-playing-format %ta\\ -\\ %tt\\ -\\ "(%td)"`;
        chomp $SONGINFO;
        # Print the song info
        if ($witem && ($witem->{type} eq "CHANNEL" || $witem->{type} eq "QUERY")) {
        $witem->command("MSG ".$witem->{name}." $SONGINFO");
        } else {                                                                                                     
        Irssi::print("$SONGINFO");                                                                                   
        }                                                                                                            
    } else {                                                                                                         
        Irssi::print("Rhythmbox is not currently running.");                                                         
    } 
}   

Irssi::command_bind song => \&rb_announce;