Gnuru.org
Productive Linux


Subscribe

 Subscribe via Feedburner in a reader

Enter your email address:

Delivered by FeedBurner


Login
Login:
Password:



Don't have an account?
Sign up to Gnuru.org
Forgot your password?

Playing .pls files from a browser
8 May 2004 @ 15:38 BST
by Paul

Update: new versions of xmms can play pls files, so the script below should be modified to show this.

Many Linux mp3 players don't correctly undestandling .pls playlist files, at the moment. This problem flummoxes many GNU/Linux users, but the solution is a simple bash script.

Firstly, some browsers such as firefox and lynx use the ~/.mailcap file to see how they should handle various file types. So, put this line, or something similar, in your mailcap:

audio/x-scpls; /home/user/bin/plshandle.sh %s

/home/user/bin/plshandle.sh is the path to a bash script that actually parses the pls file and sends the result to your listener, change it to suit your particular set up.

The code for plshandle.sh should be something like this:

#!/bin/bash

### a little script to help handle shoutcast pls files

if [ -n "$DISPLAY" ]; then
    PLAYER=xmms
else
    PLAYER=mpg123
fi

cat $1 | grep -e '^File1' | cut -f 2 -d = | xargs $PLAYER

New version of script for xmms players that can handle pls files:

#!/bin/bash

### a little script to help handle shoutcast pls files

if [ -n "$DISPLAY" ]; then
    xmms $1 &
    exit 0
else
    PLAYER=mpg123
fi

cat $1 | grep -e '^File1' | cut -f 2 -d = | xargs $PLAYER

Don't forget to use [chmod] +x to make the script executable. This script first checks whether $DISPLAY is set, if it is it means that we can run xmms, otherwise we run a command line program, in this instance mpg123.

The final line does the real work. The contents of the pls file are sent to grep, which takes one line (the one that starts with 'File1' and discards the rest of the file. The result is then passed to 'cut' which splits the data in two and passes everything after '=' to the player.

When you click on a .pls file in your browser, tell it to open the file with plshandle.sh and hey presto! you're listening to pls

Tags: audio



Comments disabled