#!/usr/bin/perl -w # # $Id: .bloggere, v0.2 -- 10/01/2005 16:30:12 # Robert Rendler # use strict; # For Replaces::playing(), remove them if you don't want it including the # actual func. use Xmms::Remote; use MP3::Info; use IPC::Open2; use HTML::Entities; $Replaces::home = 'http://members.iinet.net.au/~rendler/'; # These replaces get saved to your locally stored posts. Say a call to # playing(), you'd want the output from the func (current playing song) to be # put into the original stored post that way it's only interpreted once. %Replaces::Orig::replaces = ( '\[playing\]' => q(Replaces::playing()), ); # These replaces are expanded each and everytime you post/repost, that way # should something need to be changed you can just make the changes here, then # repost and the place holders will be expanded to the new values and reposted. %Replaces::Temp::replaces = ( '\b([dD]cow(facehed)?)\b' => q(qq($1)), '([Tt]cow)\b' => q(qq($1)), '\bSlashdot\b' => q(q(Slashdot)), '\bCPAN\b' => q(q(CPAN)), '\bGloom\b' => q(q(Gloom)), '\[home://([^:]+):([^\]]+)\]' => q(qq($1)), '\[img://(\S+)(\.[^\]]+)\]' => q(qq(
)), '\[cpan://([^\]]+)\]' => q(qq($1)), '\[fm://([^\]]+)\]' => q(qq($1)), '\[a://([^:]+):([^\]]+)\]' => q(qq($1)), '\*(arrow|grin|conf|cool|cry|eek|evil|ex|frown|idea|lol|mad|green|neutral|\?|razz|red|roll|sad|smile|sup|twist|wink)\*' => q(Replaces::smiles($1)), ); sub Replaces::smiles { my $smile = shift; my %smiles = ( 'arrow' => 'arrow', 'grin' => 'biggrin', 'conf' => 'confused', 'cool' => 'cool', 'cry' => 'cry', 'eek' => 'eek', 'evil' => 'evil', 'ex' => 'exclaim', 'frown' => 'frown', 'idea' => 'idea', 'lol' => 'lol', 'mad' => 'mad', 'green' => 'mrgreen', 'neutral' => 'neutral', '?' => 'question', 'razz' => 'razz', 'red' => 'redface', 'roll' => 'rolleyes', 'sad' => 'sad', 'smile' => 'smile', 'sup' => 'surprised', 'twist' => 'twisted', 'wink' => 'wink', ); return $smiles{$smile} ? qq() : ''; } sub Replaces::playing { my $file; my %info; my @formats = ( q#'(' . (%{artist} && %{title} ? '%a ' . (%{album} ? "« %A »" : '-') . ' %t' : '%f') . ')'#, q#'(' . (%{artist} && %{title} ? '%a - %t' : '%f') . ')'# ); my $format = 0; my $remote = Xmms::Remote->new; # Get filename for any currently playing file. if ($remote->is_running && $remote->is_playing) { $file = $remote->get_playlist_file( $remote->get_playlist_pos ); } else { my $pid = (split /\n/, `/bin/ps --no-heading -Cmpg123,ogg123 o %p`)[0]; $pid =~ s#\D##g if defined $pid; return '' if !$pid; open PROC_CMDLINE, "/proc/$pid/cmdline" or die "Replaces::playing(); Couldn't open proc file: '$!'\n"; chomp( my $cmdline = ); close PROC_CMDLINE; if (my ($psfile) = $cmdline =~ /([^\000]+)\000$/) { my ($name, $ext) = $psfile =~ m#([^/]+)\.([^.]+)$#; if ($psfile !~ m#^/# && -l "/proc/$pid/cwd") { $psfile = readlink("/proc/$pid/cwd") . "/$psfile"; } $file = $psfile; } } $info{size} = -s $file; $info{size} = sprintf "%.1f", $info{size} / 1024 / 1024; $info{name} = lc $file; $info{name} =~ s#.*/##; $info{name} =~ s#\.([^.]+)$##; if (lc $1 eq 'mp3' || lc $1 eq 'mp2') { my $info = get_mp3info($file); my $tag = get_mp3tag($file); $info{artist} = $tag->{ARTIST}; $info{album} = $tag->{ALBUM}; $info{title} = $tag->{TITLE}; $info{track} = $tag->{TRACK}; $info{kbps} = $info->{BITRATE}; $info{hz} = $info->{FREQUENCY}; $info{time} = sprintf "%d:%0.2d", $info->{MM}, $info->{SS}; } elsif (lc $1 eq 'ogg') { open2 \*INFO_READ, \*INFO_WRITE, 'ogginfo', $file or die "Replaces::playing(): couldn't run ogginfo: '$!'\n"; while () { chomp; if (/Average bitrate: (\d+)/) { $info{kbps} = $1; } elsif (/Playback length: (\S+)/) { $info{time} = $1; $info{time} =~ s#(\d+\.\d+)#sprintf("%0.2d",int($1))#eg; $info{time} =~ s#[ms]##g; } elsif (/Rate: (\d+)/) { $info{hz} = $1; $info{hz} = $info{kbps} / 1000; } elsif (/(ARTIST|ALBUM|TRACK|TITLE)=(.*)/) { $info{lc $1} = lc $2; } } close INFO_WRITE; close INFO_READ; } $format = $formats[$format]; $format =~ s#(?:\%{([^}]+)})#\$info{$1}#g; local $_ = eval $format; s#\%a#$info{artist}#eg; s#\%A#$info{album}#eg; s#\%t#$info{title}#eg; s#\%n#$info{track}#eg; s#\%f#$info{name}#eg; s#\%T#$info{time}#g; s#\%k#$info{kbps}kbps#g; s#\%h#$info{hz}#g; s#\%s#$info{size}#g; encode_entities($_); return qq(
$_
); }