Wikia

Music Player Daemon Community Wiki

Music Player Daemon Browser Stream Setup

Talk3
522pages on
this wiki

Overview Edit

Opening a link to a playlist file in your browser requires a helper script. The following scripts use the mpc program to open .m3u and .pls lists, so mpc must be installed on your system for it to work. At the bottom of the page is an experimental script for playing ASF playlists of MMS streams, without mpc. The mpc client sends the parsed playlist (.pls or .m3u) in appropriate format to mpd (specifically, adding it to the currently active mpd playlist).

  • MPD provides native support for http based (mp3 or ogg) streams, but this example provides an easy way to add the http stream urls to your playlist using a standard web browser and mime-types/helper application script.
  • Check your mpd.conf file if you use a proxy.
  • See Hack:streammpc for an optional innovative example that will prompt the user to determine if the stream should be played locally, or remotely on mpd.

Setting the MPD host Edit

This step is unnecessary if the MPD host is on the computer you're on (localhost), and is probably a little beyond the scope of this documentation.

You must have your MPD_HOST set to your MPD host. The way to accomplish this is different on most distributions, so seek your distributions instructions on how to set an environment variable globally.

Prepare the scripts Edit

Only one of the following is necessary, If the scripts are not available in your /usr/doc/mpc/doc or /usr/local/doc/mpc/doc, then skip the first step and create them from scratch.

Create the scripts Edit

This is unnecessary now, you should have a copy of both files in your /usr/doc/mpc or possibly the /usr/local/doc/mpc or the /usr/share/doc/mpc/examples directories, or it should be in the tarball in the docs/ directory, skip this step for further instruction. Copy the files to the location best to suit you ; consider /usr/bin/ or /usr/local/bin/

Create the pls-handler.sh script Edit

$cd ~
$[your favorite editor] ~/pls-handler.sh

then edit...

#!/usr/bin/env sh
mpc clear
grep '^File[0-9]*' $1 | sed -e 's/^File[0-9]*=//' | mpc add
mpc play

Create the m3u-handler.sh script Edit

$[your favorite editor] ~/m3u-handler.sh

then

#!/usr/bin/env sh
mpc clear
cat $1 | sed -e '/^#/D' | mpc add
mpc play

Copy them to your path Edit

Optional, but remember the path they're in, you'll need it later

$cp -av m3u-handler.sh /to/your/path
$cp -av pls-handler.sh /to/your/path

Set the executable bit Edit

$chmod u+x m3u-handler.sh
$chmod u+x pls-handler.sh

Testing the scripts Edit

$./pls-handler /home/user/path/to/saved.pls

Configure your browser Edit

Konqueror Edit

  1. Open your browser and go to settings->Configure Konqueror.
  2. File Associations.
  3. Goto audio->x-scpls
  4. Under Application Preference Order click Add...
  5. Put the pls-handler path and filename in.
  6. Goto audio->mpegurl
  7. Under Application Preference Order click Add...
  8. Put the m3u-handler.sh path and filename in.

Mozilla Firefox / Mozilla Suite / Netscape 7 Edit

  1. Open your browser and go to edit->preferences->downloads in the "file types" area remove the pls or m3u entry if they exist.
  2. Go to your favorite streaming website.
  3. Open the pls or m3u link, your browser will open a dialog box asking what to do with this file, choose "open with" and "other".
  4. Find the script pls-handler.sh and/or m3u-handler.sh, respectively, which should be in your /usr/doc/mpc directory.
  5. Check the box "do this automatically...from now on".

Opera Edit

  1. Click on a pls file, for instance on the shoutcast page.
  2. To the right of Opens with click the box marked Change...
  3. Click the Open with other application radio button, and then click the Choose button to the right.
  4. Fill in the path and filename for pls-handler.sh, click OK and the stream should start.
  5. Click on a m3u file, for instance on the icecast page.
  6. To the right of Opens with click the box marked Change...
  7. Click the Open with other application radio button, and then click the Choose button to the right.
  8. Fill in the path and filename for m3u-handler.sh, click OK and the stream should start.

ASF Playlists (Windows Media)Edit

The following script is not well tested, but it may help someone. It accepts an ASF file as an argument. Using some regular expressions, it extracts URLs with an mms method (mms:), sends the URLs to mpd via netcat, and tries to play the first song that was added. It has

It defaults to an mpd @ localhost:6600. Override with settings in ~/.handle-mms-mpd.rc like:

mpd_host=frankenstein.mydomain.com
mpd_port=17777
summary_file=/tmp/handle-mms-mpd-last-attempt

Or just this should do in most cases:

mpd_host=192.168.100.100

The script (tested in bash):

#!/bin/sh

#  #     handle-mms-mpd.sh       #  #
#        rev. 201009231600          #
#                                   #
# Usage:                            #
#                                   #
#     handle-mms-mpd.sh <file.asf>  #
#                                   #
# DEPENDENCIES:                     #
#     netcat (nc)                   #
#                                   #
# NOTE:                             #
#     This is highly experimental.  #
#  I have only tried it on Coast    #
#  to Coast's streaming service,    #
#  where it works like a charm.     #
#                                   #
#     If you successfully use this  #
#  script, please let me know! If   #
#  it doesn't work for you--please  #
#  let me know!                     #
#                                   #
#       created by Jay Straw        #
# jay@jaystraw.info / jaystraw.info #

# DEFAULTS
mpd_host=localhost
mpd_host_port=6600
summary_file=~/handle-mms-mpd-summary # contains output from most recent run (useful when something goes wrong and the (file|web) browser won't show you what. Use /dev/null if you don't care to use this feature.

if [ -a ~/.handle-mms-mpd.rc ]; then
    source ~/.handle-mms-mpd.rc
fi

echo "`date`" > $summary_file

if [ -z "${1}" ]; then
    echo "`basename ${0}` requires a single argument, a path to an asf file." | tee -a $summary_file
    echo "Make sure your browser's 'Open with...' command looks like:" | tee -a $summary_file
    echo | tee -a $summary_file
    echo "    ${0} %s" | tee -a $summary_file
    echo | tee -a $summary_file
    echo "Your browser should replace the %s with the asf file." | tee -a $summary_file
    exit 128
fi

# Pipe the asf file through grep and sed
# The result is the URL of each clip on a line (now on single line)
resources="`cat ${1} | grep HREF=\\\"mms: | sed 's#^.*\(mms[^"]*\).*$#\1#g' | tr '\n' ' '`"

first='true'
firstID=0

for resource in ${resources}
do
    cmd="addid ${resource}
close"
    ID="`echo "${cmd}" | nc ${mpd_host} ${mpd_host_port}`"
    # if grepping for ACK isn't NOT null--
    if [[ -n "`echo "${ID}" | grep 'ACK '`" ]]; then
        # -- ERROR, leave!
        echo "ERROR:"
        echo "\t${ID}"
        exit 1
    fi
    # -- otherwise, extract the ID out of the response (confusing variable names, I know)
    ID="`echo "${ID}" | grep "Id: " | awk '{print $2}'`"
    if [[ "${first}" == 'true' ]]; then
        firstID=${ID}
        first='false'
    fi
    echo "ID: ${ID}" >> $summary_file
done

# play firstID
echo "Playing first track, ID |${firstID}|" | tee -a "${summary_file}"
result="`echo "play ${firstID}
close" | nc ${mpd_host} ${mpd_port}`"

echo "Result: ${result}" | tee -a "${summary_file}"

exit

Around Wikia's network

Random Wiki