Posts Tagged ‘Unix’

Last.FM submissions with Audacious

June 9th, 2010 5 comments

Some time ago the good folks behind my favorite media player Audacious decided to abandon in-built support for Last.FM submissions.

The reasoning behind this seems to be that the Last.FM API was becoming a little too much to maintain which I suppose is fair enough in its quest to remain just a music player i.e. not a screen-hogging iTunes clone like so many others.

Heres how to put Last.FM support back into Audacity.

I’m going to assume you are a sensible person and using a Debian based system rather than Fedora. If you are one of these hat loving deviants, substitute ‘yum’ for apt-get below and feel free to voyage though the countless pains required to get Yum to actually do its job.

Installing LastFMSubmitD

I’m not sure on the capitalization of the daemon process LastFMSubmitD so that might be the wrong name entirely.

Anyway, first install pretty much the only component we need:

apt-get install lastfmsubmitd


For some reason the daemon does not get proxy details right. This is easily fixed by opening /etc/init.d/lastfmsubmitd in your favorite editor and inserting the following line somewhere near the top (I put it after the ‘GROUP=’ line which should be the last bit of the daemon config area).
If you have no idea what a proxy is or why you should be doing this you can probably skip this section.

export http_proxy=""

Parse Audacious output

Dump the following script somewhere you can find it. For this example I will use /home/user/bin/scrobble

if [ ! -x '/usr/lib/lastfmsubmitd/lastfmsubmit' ]; then
	echo "LastFMSubmitD does not appear to exist on this machine"
	echo "You can install it using Apt or Yum"
	exit 1
if [ "$#" == 0 ]; then
	echo 'Usage: scrobble " - " ""'
	exit 1

ARTIST=${1%% - *}
SONG=${1##* - }
LENGTH=$[ $2 / 1000 ]
echo "ARTIST = [$ARTIST]"
echo "SONG = [$SONG]"
echo "LENGTH = [$LENGTH]"

/usr/lib/lastfmsubmitd/lastfmsubmit --artist "$ARTIST" --title "$SONG" --length "$LENGTH"

Pointing Song Change at your script

First make sure you have the Song Change plugin enabled in Audacious first.

Now point the command Audacious is to run when starting a new song at the script in the following way:

/home/user/bin/scrobble "%s" "%l"

All done. Now any tracks played via Audacious will be passed to the script which will parse the incoming song title into a format that the LastFMSubmitD daemon can use.

Categories: Fixes Tags: , ,

Interactive file merging with Unison

August 13th, 2009 3 comments

After trying in vein to find decent documentation on the Merge functionality of Unison I eventually gave in and invested an hour or two trying out different Linux based merge programs in order to find something Unison, the merge program and I were happy with.

So onto the diff-merging candidates:

VimDiff (part of Vim)

Doesn’t work too well with Unison. I can’t get gnome-terminal (my terminal of choice) to execute synchronously so I was forced to fall back on XTerm instead.

After using XTerm I immediately hit upon a problem: there is no sensible way of outputting the results of a merge in VimDiff. Which is a pity because I do prefer VIM as an editor but this lack of functionality is annoying (yes I could have used a wrapper script but I’m trying to keep this simple).


Very pretty but lacks features such as ‘Use Left-hand-side-file for all changes’ and some of the other filtering options provided by KDiff3.

Also, like, VimDiff, does not provide any sensible output mechanism of the eventually merged file.


Not as good looking as Meld but provides pretty much everything I want in a merge program including the all important merged file output that Unison requires.

Can get a little annoying though with its insentient pop-up boxes. I wish there were a ‘Dont show this option again’ option to each. KDE is usually quite good with this so I’m not sure why KDiff3 managed to escape this unspoken standard.


So how to use KDiff3 with Unison? First install kdiff3:

apt-get install kidff3

Then open your Unison profiles .prf file and insert the following:

merge = Name * -> kdiff3 CURRENT1 CURRENT2 -L1 'Local File' -L2 'Remote File' -o NEW -m
confirmmerge = true

If you are comfortable with KDiff3 you could remove the ‘confirmmerge’ line which forces Unison to double check you actually want to accept the changes.

The downside to the above interactive merging process is there is no sensible way to preview the merge in Unison (the ‘View Merge’ button in the confirmation dialogue). For now though its preferable to not having this functionality at all.

Categories: HowTo's Tags: , ,

Converting Null

April 24th, 2009 2 comments

Simple shell script fix this week – convert all newlines to null characters.

Since most Linux shells have a major problem with doing this in a sensible way, the following (on my box called simply ‘0’) takes any input (either from files or via a pipe) and converts the characters.

# From:
# Author: Matt Carter 
while (<>) {

So now commands like:

find -type f | 0 | xargs -0 | mplayer

work perfectly (in the above case to play all files in directories recursively.

You may well ask why I don’t use the simple ‘-print0’ argument for the find program – because it doesn’t work when using later pipes.

For example if i wanted to sort the above, ‘sort’ would see the null symbol as a regular character.

So ‘0’ works nicely in this case:

find -type f | 0 | sort | xargs -0 | mplayer

Or even:

find -type f | 0 | shuffle | xargs -0 | mplayer

To play all files recursively, in random order. See the article on shuffle for the source code of that filter.

Categories: Fixes, HowTo's Tags: , , ,

Easy Apache VirtualHost config

March 15th, 2009 1 comment

Like most of the word I use Apache to serve up both my live and test websites.

The downside to having a box for development though is the constant config of apache to host these sites, most of which require absolute links (e.g. ‘/css/style.css’) to function.

The Apache snippet below sets up dynamic sub-domains which can be changed without reloading Apache every time you add, remove or update anything something. Simply drop your sites inside /var/www whenever you want a new subdomain. Alternatively you can symlink if they are hosted elsewhere on the box.

Its pretty easy to install, simply paste the below in your /etc/apache2/apache.conf file…

# Easy virtual host config
# See

DocumentRoot /var/www/
ServerAdmin admin@localhost
Options +FollowSymLinks -Indexes
LogLevel debug
ServerAlias localhost
ServerName localhost
RewriteEngine  on
RewriteLogLevel 3
RewriteCond    %{HTTP_HOST}  ^localhost
RewriteRule    ^(.*)$        /www/$1 [L]
RewriteCond    %{HTTP_HOST}  ^www.*
RewriteRule    ^(.*)$        /www/$1 [L]
RewriteCond    %{HTTP_HOST}  ^(.*)\.localhost
RewriteRule    ^(.*)$        /%1/$1 [L]

Now add your servers to the /etc/hosts file:      server.localhost

Now any directory you place in the /var/www directory automatically becomes a subdomain. You can now visit http:///server.localhost as a fully fledged webhost.

If you want to use another name than the rather boring ‘localhost’ simply replace the text in both text pastes above.

If only there were a way of removing that /etc/hosts hack it would mean zero config from then on. If anyone has any ideas do let me know. The addition to the hosts file seems to need applying if you are working from the same box the Apache server resides on. If you arn’t and the box is a local dedicated server its not needed at all and domains can be added and removed as necessary.

Categories: HowTo's Tags: , ,

Trash with Bash

March 4th, 2009 6 comments

One of the regrettably unavoidable aspects of the Unix shell like environments is the impedance between what a user says and what a user means. While this is present in all computing environments the sheer power of Unix based command lines make a potential mistake catastrophic.

Who amongst us has not at some point done something like:

> rm * .tmp


> rm *>tmp

The former makes the mistake of a space between the dot and the ‘tmp’ part and the latter the accidental holding down of the shift key while pressing the intended full stop.

While searching for an alternative for the I-have-done-this-too-many-times-and-now-its-embarrassing approach of nuking everything with the ‘rm’ command its time i did something about it.

Inserting the following in your ~/.bashrc file will remap the ‘rm’ command to a slightly safer move-to-trash like behavior. Its not comprehensive but it has saved my life on more than one occasion.

# Trash support by Matt Carter /dev/null

Now the command ‘rm’ moves files into ~/.trashcan. You can also use the command ‘rm!’ when you really mean delete immediately and the utility command ’emptytrash’ to clean everything out.

Categories: HowTo's Tags: ,