# # AmarokId - Irssi Amarok ID Script. # # $Id: AmarokId.pl 28 2005-09-13 21:54:13Z meff $ # # (C) 2004, 2005 Rodney Gordon II # 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 URI::Escape qw(uri_unescape); use Irssi; use vars qw($VERSION %IRSSI); $VERSION = "2.0"; %IRSSI = ( authors => 'Rodney Gordon II (meff)', contact => 'meff@pobox.com', name => 'AmarokId', description => 'Irssi Amarok ID Script.', license => 'GNU General Public License', url => 'null', changed => '$Id: AmarokId.pl 28 2005-09-13 21:54:13Z meff $' ); # thanks to john for this idea.. ############## do not edit above ##################### ###################################################### # types of amarokid_display vars: # # NORMALSAYING = saying (is listening to:) # RANDOMSAYING = random saying # TITLE = title of song # ALBUM = album of current song # TIME = time string of song # KBPSRATE = kbps rate of song # KHZFREQ = kHz freq of song # FILESIZE = size of song file # EXTENSION = song file extension # ###################################################### ############### do not edit below #################### my %data; sub AmarokId { my ($data, $server, $witem) = @_; my @arguments = split(/ /, $data, 2); if($arguments[0] eq "help") { DisplayHelp(); } else { if(CheckPlaying()) { FeedVars(); my $string = BuildDisplay(GetDisplay()); # do it! if ($witem && ($witem->{'type'} eq "CHANNEL" || $witem->{'type'} eq "QUERY")) { $witem->command("ME $string"); } else { Irssi::print("Not on an active channel/query"); } } } } sub DisplayHelp { Irssi::print("The following variables are valid in amarokid_display:\n" . "NORMALSAYING RANDOMSAYING TITLE ALBUM TIME KBPSRATE KHZFREQ FILESIZE EXTENSION\n" . "See the script for more detailed help."); } sub FeedVars { my $buildup; # random saying $data{'randomSaying'} = RandomSaying(); # title $data{'title'} = DCOPGrab('amarok player nowPlaying'); # album $data{'album'} = DCOPGrab('amarok player album'); # bitrate $buildup = DCOPGrab('amarok player bitrate'); $buildup =~ s/ kbps//; $data{'kbpsrate'} = $buildup; # freq $buildup = DCOPGrab('amarok player sampleRate'); $buildup = ($buildup / 1000); $data{'khzfreq'} = $buildup; # time $data{'time'} = DCOPGrab('amarok player currentTime') . "/" . DCOPGrab('amarok player totalTime'); # file info $buildup = DCOPGrab('amarok player encodedURL'); $buildup = uri_unescape($buildup); if($buildup =~ m/^file\:/) { $buildup =~ s/file\://; if(-e $buildup) { $data{'filesize'} = sprintf("%.2f", (((-s $buildup) / 1024) / 1024)); $data{'extension'} = (split /\./, $buildup)[-1]; } else { $data{'filesize'} = 0; $data{'extension'} = 'FileNotFound'; } } if($buildup =~ m/^http\:/) { $data{'filesize'} = 0; $data{'extension'} = 'Stream'; } unless($data{'filesize'} && $data{'extension'}) { $data{'filesize'} = 0; $data{'extension'} = 'Unknown'; } } sub DCOPGrab { my $dcopline = shift; my $dcopreturn = qx{ dcop $dcopline }; chomp($dcopreturn); return $dcopreturn; } sub GetDisplay { my $display = Irssi::settings_get_str('amarokid_display'); return $display; } sub BuildDisplay { my $altered = shift; # build the line to display $altered =~ s/NORMALSAYING/is listening to:/g; $altered =~ s/RANDOMSAYING/$data{'randomSaying'}/g; $altered =~ s/TITLE/$data{'title'}/g; $altered =~ s/ALBUM/$data{'album'}/g; $altered =~ s/TIME/$data{'time'}/g; $altered =~ s/KBPSRATE/$data{'kbpsrate'}kbps/g; $altered =~ s/KHZFREQ/$data{'khzfreq'}kHz/g; $altered =~ s/FILESIZE/$data{'filesize'}MiB/g; $altered =~ s/EXTENSION/$data{'extension'}/g; return $altered; } sub CheckPlaying { # check if something is even playing my $check = DCOPGrab('amarok player isPlaying'); unless($check eq 'true') { Irssi::print("No song playing!"); return 0; } else { return 1; } } # doug's idea from pf.. thanks man! sub RandomSaying { my @sayings = ('bumpin to', 'rockin out to', 'chillin to', 'annoying roommates with', 'killing time with', 'cruising to', 'jammin to', 'moshing out with', 'getting drunk to', 'groovin to', 'jumpin to', 'making love to', 'pissing off neighbours with', 'dancing to'); my $randSayingNum = int(rand(($#sayings + 1))); return("is $sayings[$randSayingNum]:"); } # do our irssi stuff Irssi::command_bind('amarokid', 'AmarokId'); Irssi::settings_add_str('amarokid', 'amarokid_display', 'RANDOMSAYING TITLE on "ALBUM" [TIME] (KBPSRATE) KHZFREQ) [FILESIZE EXTENSION]');