#!/usr/bin/perl -w # xmms-infopipe-parser.pl parses the information produced by the XMMS Infopipe plugin # . # This script is roughly based on the "fifolog" example from # . # Copyright 2004-2005 by Susanna Winter. # # Changelog: # v0.1 - Jul 2004: this is the current version # v.0.1.1 - Feb 2005: use scp with session keys # v.0.1.2 - Mar 2005: fixed segfault when using arTs output in XMMS. With arTs output, the # infopipe in /tmp/xmms-info is constantly updated. When reading it, the # script ran out of memory and segfaulted. A crude solution: read only the # first 14 lines from the file. # TODO: * log every song to a textfile and/or SQL database (for funky statistics etc.) # * parameterize stuff (I'm too lazy for that) # * probably need to convert more unprintable characters but can't think of any more ATM use strict; use IO::File; $| = 1; # flush my $previous = "/path/to/xmms-infopipe/previous"; my $previous3 = "/path/to/xmms-infopipe/previous3"; my $xmmsinfo = "/path/to/xmms-infopipe/xmms-info"; $SIG{ALRM} = sub { close(FIFO) }; # move on to the next queued process while (1) { alarm(0); # turn off alarm for blocking open if (-r "/tmp/xmms-info") { open(FIFO, "< /tmp/xmms-info") or die; alarm(1); # you have 1 second to log # comment the next line if you use aRts output #my @info = ; # comment the next line if you use other than aRts output my @info = `/usr/bin/head -14 /tmp/xmms-info`; chomp @info; alarm(0); # turn off alarms for message processing my %infohash = (); %infohash = map { split(': ', $_, 2) } @info; if ($infohash{'Status'} =~ /^playing/i) { open(PREV, $previous); my $previoussong = ; close(PREV); unless ($previoussong eq $infohash{'Title'}) { open(OUTPREV, "> $previous"); print OUTPREV $infohash{'Title'}; close(OUTPREV); open(PREV3, $previous3); my @previoussongs = ; close(PREV3); open(OUTPREV3, "> $previous3"); if ($infohash{'File'} =~ /^https?:\/\//i) { my $parsedtitle = $infohash{'Title'}; my $station = $infohash{'File'}; if ( ($parsedtitle = $infohash{'Title'}) =~ s/\(([^(\)\s+)]*\(?[^\)]*\)?)\)$//i) { $station = $1; $station =~ s/^\s+//; } $parsedtitle =~ s/\s+-?\s?$//; my @ascii = unpack("C*", $parsedtitle); foreach (@ascii) { if ($_ =~ m/^146$/) { $_ =~ s/^146$/39/; } # non-printable ASCII 146 to ' (apostrophe) } $parsedtitle = pack("C*", @ascii); open(OUTINFO, ">$xmmsinfo"); print OUTINFO "$station [$infohash{'Position'}] playing
  • $parsedtitle
\n"; print OUTINFO "Previous 3:\n
    \n$previoussongs[0]$previoussongs[1]$previoussongs[2]
\n"; close(OUTINFO); print OUTPREV3 "
  • $parsedtitle
  • \n$previoussongs[0]$previoussongs[1]"; } else { open(OUTINFO, ">$xmmsinfo"); print OUTINFO "
    • $infohash{'Title'} [$infohash{'Time'}]
    \nPrevious 3:\n
      \n$previoussongs[0]$previoussongs[1]$previoussongs[2]
    \n"; close(OUTINFO); print OUTPREV3 "
  • $infohash{'Title'} [$infohash{'Time'}]
  • \n$previoussongs[0]$previoussongs[1]"; } close(OUTPREV3); `/usr/bin/scp -o 'IdentityFile2 /path/to/sessionkey' /path/to/xmms-infopipe/xmms-info user\@host:`; } } } else { # uncomment the following 5 lines if you want output when XMMS if stopped #open(OUTINFO, ">$xmmsinfo"); #print OUTINFO "
    • the sound of silence
    \n"; #close(OUTINFO); #`/usr/bin/scp -o 'IdentityFile2 /path/to/sessionkey' /path/to/xmms-infopipe/xmms-info user\@host:`; #exit; } sleep(10); # run forever and ever and ever (until xmms not running or at least /tmp/xmms-info not readable #exit; # run only once - if you want to set up a cron job }