#!/usr/bin/perl # amaroknp-0.7.pl (Modified) # Modified by NhJm http://nhjm.net/ # Written by Eric Oden # Based on the amaroknp script by Tuukka Lukkala (ragdim at mbnet dot fi) # http://koti.mbnet.fi/ragdim/amaroknp/ # Tested with amaroK (1.2.3 & 1.3CVS) and X-Chat 2.4.3 # 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. # Usage: /amaroknp or /np use strict; my $VERSION = "0.8"; my %IRSSI = ( authors => "NhJm, Eric Oden, Tuukka Lukkala", contact => "nhjm449\@gmail.com", name => "amaroKnp-Modified", description => "Display script for amaroK", license => "GPL", url => "http://nhjm.net/", changed => "Sun Jun 12 15:21:57 CDT 2005" ); BEGIN { use vars '$irssi','$xchat'; eval q{ use Irssi; Irssi::version(); }; $irssi = !$@; eval q{ IRC::get_info(1); }; $xchat = !$@; } if ($irssi) { Irssi::command_bind("amaroknp", "aminfo"); Irssi::command_bind("np", "aminfo"); Irssi::active_win->command("/echo You have successfully loaded ".$IRSSI{"name"}." $VERSION!"); Irssi::active_win->command("/echo Usage: /amaroknp or /np"); } elsif ($xchat) { Xchat::register($IRSSI{"name"}, $VERSION, "Display script for amaroK"); Xchat::hook_command("amaroknp","aminfo"); Xchat::hook_command("np", "aminfo"); # Kinda pointless: $version = Xchat::get_info("version"); $nick = Xchat::get_info("nick"); Xchat::print("You have successfully loaded ".$IRSSI{"NAME"}." $VERSION!"); Xchat::print("Usage: /amaroknp or /np"); } sub aminfo { my $playing; # Is amaroK plaing something? my $title; # Title of song my $album; # Album my $timenow; # Current position of song my $timetotal; # Total time of song my $kbs; # Bitrate of song my $hz; # Samplerate of song my $score; # Score my $volume; # Current volume my $year; # Year my $minutes; # Current time converted to full minutes my $seconds; # Current time converted to seconds my $minutestotal; # Total amount of minutes my $secondstotal; # Total amount of seconds my $output; # The format in which all this is going -> channel my $amaroktest; # To see if amarok is running or not my $amarokNOTrunning; # Don't ask me.. :z my $outputcmd; # Either MSG or ACTION for now.. my $mode = "message"; # Holds the value of amarok_output setting my $times; # Times song has been played my $rating; # Rating based on bitrate my $totaltks; # Tells total tracks in playlist my $activeindex; # Returns an integer value for the current track's position in the playlist. my $percent; # Percentage of song played. my $progbar; # Progress bar my $extension; # File extension # NOTE !! Adjust this to the full path of dcop if it's not in your PATH. eg. /opt/kde/bin/dcop !! my $dcop = "dcop"; # Checks to see if it can find dcop if (!`$dcop`) { xchat::print("Couldn't find the dcop executable.. Make sure dcop is in your PATH or edit dcopbin in the script"); return 1; } $amaroktest = `$dcop amarok 2> /dev/null`; chomp($amaroktest); if ($amaroktest =~ s/^$/No such application: 'amarok'/) { Xchat::print("amaroK isn't running?"); $amarokNOTrunning = "nope"; return 1; } # If amaroK is running, let's get the info! if (!$amarokNOTrunning) { $playing = `$dcop amarok default isPlaying`; chomp($playing); if ($playing eq "false") { if ($irssi) { Irssi::active_win->command("/echo amaroK isn't playing anything!"); } elsif ($xchat) { Xchat::print("amaroK isn't playing anything!"); } return 1; } else { # Get some info $title = `$dcop amarok default nowPlaying`; chomp($title); $timenow = `$dcop amarok default trackCurrentTime`; # Bitrate and samplerate $hz = `$dcop amarok default sampleRate`; chomp($hz); $kbs = `$dcop amarok default bitrate`; chomp($kbs); # Album $album = `$dcop amarok default album`; chomp($album); # Score $score = `$dcop amarok default score`; chomp($score); # Volume $volume = `$dcop amarok default getVolume`; chomp($volume); if ($volume eq "100") { $volume = "110"; } # Year $year = `$dcop amarok default year`; chomp($year); $times = `$dcop amarok default trackPlayCounter`; chomp($times); if ($times eq "0") { $times = "never"; } elsif ($times eq "1") { $times = "once"; } # Rating based on bitrate $rating; chomp($rating); if ($kbs >= "500") { $rating = "Hella Good"; } elsif ($kbs >= "320") { $rating = "Very Good"; } elsif ($kbs >= "160") { $rating = "Good"; } elsif ($kbs >= "128") { $rating = "OK"; } elsif ($kbs >= "64") { $rating = "Bad"; } elsif ($kbs >= "0") { $rating = "Crap"; } # The getActiveIndex function returns an integer value for the current track's position in the playlist. $activeindex = `$dcop amarok playlist getActiveIndex`; $activeindex = $activeindex + 1; chomp($activeindex); # Total tacks in playlist $totaltks = `$dcop amarok playlist getTotalTrackCount`; chomp($totaltks); # Total time of track $timetotal = `$dcop amarok default trackTotalTime`; # Percentage $percent = ($timenow/$timetotal)*100; $percent = sprintf("%2.2f", $percent); # Old: %.0f chomp($percent); # Progress bar $progbar = "|" x int($percent/10); $progbar .= "-" while( length($progbar) < 10 ); # Converting times to a more readable format $minutes = ($timenow/60)%60; $seconds = $timenow%60; # Add the leading zero #if ($seconds < 10) { $seconds = "0" . $seconds; } $seconds = ("0" x (2 - (length($seconds)))) . $seconds; $minutestotal = ($timetotal/60)%60; $secondstotal = $timetotal%60; # Here too #if ($secondstotal < 10) { $secondstotal = "0" . $secondstotal; } $secondstotal = ("0" x (2 - (length($secondstotal)))) . $secondstotal; $extension = `dcop amarok default path`; chomp($extension); if ($extension !~ /\./) { $extension = "None"; } else { $extension =~ s/^.*\.(.*?)$/\1/; } if ($extension eq "") { $extension = "None"; } $extension = lc($extension); # The way it's gonna show up when we do /amaroknp: if (lc($mode) eq "message") { $outputcmd = "say"; $output = "\2np: [\2 $title \2(\2$extension\2) ] - [\2 $minutes:$seconds/$minutestotal:$secondstotal \2] - [\2 $percent% \2] - [\2 $kbs \2@\2 $hz Hz \2] - [\2$progbar\2]\2"; } elsif (lc($mode) eq "action") { $outputcmd = "me"; $output = "np: $title [Time:$minutes:$seconds/$minutestotal:$secondstotal($percent%)][Bitrate:$kbs|Freq:$hz Hz]";#[Track $activeindex of $totaltks] } else { if ($irssi){ Irssi::active_win->command("/echo '$mode' isn't a valid output mode!"); Irssi::active_win->command("/echo Use either message or action"); } elsif ($xchat){ Xchat::print("'$mode' isn't a valid output mode!"); Xchat::print("Use either message or action"); return 1; } } } if ($output) { if ($irssi) { Irssi::active_win->command("/$outputcmd $output"); } elsif ($xchat) { Xchat::command("$outputcmd $output"); } } } }