ogg / mp3 signatures in slrn

Random signatures are cool, but a signature that includes the current song you're playing is the very height of coolness.  I've wanted this for slrn for a while — here's how.  This is for Unix-likes only so far, I've no idea how to do this stuff on win32 and no inclination to find out.   This method is a little quick-and-dirty, but it works. ;)

As well as slrn you'll need xmms or the Beep Media Player (BMP), and the xmms-infopipe plugin.  xmms-infopipe 1.3 needs patching before it will work with Beep Media Player, follow the instructions carefully to compile it as it can be tricky (worked fine for me). If you've not heard of BMP before, it's very good and worth trying.  Think xmms for gtk+2.  I'll assume you can compile & install / apt-get / emerge / urpmi / whatever these apps.

xmms-infopipe

While xmms is running, xmms-infopipe outputs the current status of xmms to a named pipe.  mp3sig.sh is a small script that creates a signature for a Usenet article or email using said pipe:
#!/bin/bash
## mp3sig.sh, a small signature generator ##
## script including current song.         ##
# Add newlines, sigdash, name, Linux user number
echo -e "\n\n-- \nAndrew Preater\nLinux user #238547"
# Optionally add system uptime using uptime script
# echo -e "Uptime: `uptime.proc.sh`\r"
# If music is playing, add title of the current song
if [ -p /tmp/xmms-info ]
  then
  echo -e "Now playing:\c"
  grep Title: /tmp/xmms-info | cut -f 2 -d :
fi
# end
Flavour to taste to include your name and whatever other info you like.  The script first echos information I want in the sig: a few newlines; a properly-formatted sigdash; name; Linux user number; then if /tmp/xmms-info is a named pipe it greps the Title: line and cuts the field containing the song title.  This assumes your audio files are properly tagged. Note: my slrn normally inserts a few newlines at the end of the quoted article text and before the signature, so I've mimicked this behaviour here.

Example output:

$ mp3sig.sh


-- 
Andrew Preater
Linux user #238547
Now playing: Basement Jaxx - Get Me Off

Optional: adding uptime to sig

uptime.proc.sh mentioned above is a small script that attempts to generate nice output from /proc/uptime.  Parsing output from uptime(1) itself is quite difficult - usually well into the realms of the fiendish sed one-liner.   Working with /proc/uptime directly is easier.  If you know of a better way to do this let me know. Here's what it looks like:
#!/bin/bash
## uptime.proc.sh                                               ##
## small script to show system uptime: days, hours, and minutes ##
let upSeconds="$(awk '{ print $1 }' /proc/uptime | cut -f1 -d ".")"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
if [ "${days}" -ne "0" ]
then
 echo -n "${days} days"
fi
echo -n " ${hours}:${mins}"
# end
Example output:
$ uptime.proc.sh
8 days 23:59

Setting up slrn and $editor

Assuming this works okay from the command-line, edit your .slrnrc to make use of this script.  Change post_editor_command to this:
set post_editor_command "FILE='%s'; mp3sig.sh >> $FILE; vim '+set filetype=mail' +%d $FILE"
'%s' is the temporary file created when you compose an article.  This post_editor_command calls mp3sig.sh and appends the output to the temporary file, which is then edited using Vim and afterwards handed back to slrn for posting as normal.  I borrowed this approach from Nicholas Avenell - thanks!

If you've set a signature in slrn, comment it out from your .slrnrc and make sure ~/.signature doesn't exist.  I use mp3sig.sh to create the whole signature — sigdash and all — so you can bypass slrn's usual method.  The problem with this is that if you decided to abandon an article without editing it, slrn still asks if you wish to post because the temporary file has been modified by appending the sig.   I know I could get around this by calling mp3sig.sh in post_editor_command, redirecting the output to a file, and using this as my signature.  But I don't want to, so don't mail me to tell me to. :)

I use "+set filetype=mail" in my slrnrc because for me, around Vim 6.1 and Mandrake 9.1 colourisation of slrn's temporary files broke.  This was a quick fix back then, but I kept it.  I don't set a textwidth for Vim in my .slrnrc, rather I keep that in my .vimrc:

au FileType mail set tw=70
So there you are!

Send email: preater--at--zworg.com | Last modified: 2007-03-08 22:26:47 GMT Get Dillo!