Webradio

From YobiWiki
Jump to navigation Jump to search

Intro

I was struggling to fit some requirements:

  • I ripped all my CDs on the HD attached to the slug
  • I wanted my Philips Streamium (which is not UPnP) to be able to play whatever I want
    • Streamium is not UPnP
    • Streamium doesn't understand Ogg format
    • Streamium has a very poor UI
  • I wanted to be able to control the playlist from any other computer in the house
  • Why not extending those possibilities from anywhere on the Net?

Resources

  • madplay/libmad (fixed point mp3 player)
    • In terms of codecs this is the only fixed-point lib available for the slug and it allows only mp3 playback.
  • musicdp, aka mpd (its faq)
    • That's THE solution to manage the playlists, now we need to cope with its playing capabilities...
  • http://www.nslu2-linux.org/wiki/HowTo/SlugAsAudioPlayer
    • With mpd and libmad, good idea but is using the slug soundcard (if you add one), not icecast
  • icecast2
    • The solution for streaming, if we find the right way to add a mp3 source to it.
  • mpd + icecast2
    • 2 problems: only streaming in Ogg and needs to reencode the stream, too much without a fixed point encoder!
  • oggfwd
    • Would solve one problem: does not reencode, but, as the name tells you, only Ogg.
  • EzStream
    • Good candidate, feeds icecast with mp3 without reencoding, but needs to be hooked to mpd
  • Ices and especially the versions 0.x
    • Same as for EzStream
  • Jinzora
    • To be explored... but requires php/mysql, maybe too much for the slug
  • Hack mpd with ices client
    • That's the best I could find: a Perl script as scriptable playlist for ices fetches the songs from mpd playlist ans streams them to icecast2
    • Ices in its basic configuration doesn't perform any reencoding
    • Note that the old version of ices is required as the new one supports only Ogg

Let's go

mpd

apt-get install mpd mpc
  • Edit /etc/mpd.conf
    • point music_directory to your mp2s or make a symlink from /var/lib/mpd/music
    • define password for clients if you want
  • On the slug there is by default no soundcard but mpd cannot start without at least one output, we'll give it a dummy soundcard:
echo snd-dummy >> /etc/modules
modprobe snd-dummy
  • Generate DB
/etc/init.d/mpd stop
mpd --create-db
  • Launch mpd
/etc/init.d/mpd start
mpc stop

(Remember that we don't use mpd to play music but only to handle playlists)

  • When need to update the DB:
    • There are plenty of tools to tune id3 tags, mp3info is one of them and by default allows to change one item without touching the other id3 infos. Then update the DB or the dirs you touched/added
mpc update [relative path]
  • gmpc can display content in UTF-8 but depending on the locales of your platform, encoding done by mpd could be wrong, in that case you need to add to /etc/mpd.conf sth like this and recreate the db
filesystem_charset              "UTF-8"
id3v1_encoding                  "UTF-8"
mpd --create-db

icecast2

apt-get install icecast2
  • Edit /etc/icecast2/icecast.xml
    • Change passwords in <authentication>
    • Change <hostname> if it's relevant
    • You can add clients authentication as well:
   <mount>
       <mount-name>/mymountpoint</mount-name>
       <authentication type="htpasswd">
               <option name="filename" value="/etc/icecast2/authusers"/>
               <option name="allow_duplicate_users" value="0"/>
       </authentication>
   </mount>
touch /etc/icecast2/authusers
chown icecast2 /etc/icecast2/authusers
chmod 700 /etc/icecast2/authusers

Note that my streamium cannot handle basic authentication, the only way would then be based on IP, with URL auth in icecast2 or simply through iptables.

  • Edit /etc/default/icecast2
    • ENABLE=true
/etc/init.d/icecast2 start
  • Then to manage users, go to the admin page http://myserver:port/admin/ -> Manage authentication of that source
  • Stream playing can be achieved with sth like
xmms http://user:pwd@myserver:port/mymountpoint
vlc http://user:pwd@myserver:port/mymountpoint.m3u

ices as glue

  • Debian features only ices2 so we've to compile the old version ourselves
apt-get install libshout3-dev libperl-dev libmp3-info-perl
wget http://downloads.us.xiph.org/releases/ices/ices-0.4.tar.gz
tar xzf ices-0.4.tar.gz 
cd ices-0.4
./configure --with-perl
make
cp src/ices /usr/local/bin
cp conf/ices.conf.dist /etc/ices.conf
wget -q -O - http://mpd.wikia.com/wiki/Hack:ices-client | awk '/<pre/,/<\/pre/'|html2text -width 200 > mpdplaylist.pm
  • Edit mpdplaylist.pm
    • my $mediaroot: points to your mp3 directory, must be identical to music_directory in /etc/mpd.conf but with trailing /
    • my $playlistdir: points to your playlists dir, must be identical to playlist_directory in /etc/mpd.conf (default is /var/lib/mpd/playlists) but with trailing /
    • Add the following lines to use authentication for musicp clients (cf password in /etc/mpd.conf) or to connect to a remote mpd or a non default port
$ENV{'MPD_HOST'} = 'mypassword@localhost';
$ENV{'MPD_PORT'} = '6600';
  • Edit /etc/ices.conf
 <Playlist>
   <Type>perl</Type>
   <Module>mpdplaylist</Module>
 </Playlist>

Maybe you need to adapt also <Mountpoint>, <Password> to match the icecast2 source pwd and the <Bitrate> but that's just for info as we won't recode the stream anyway, and once everything is running properly, set <Background> to 1.

  • Run
rm /tmp/ices.log
ices -c /etc/ices.conf
# or as icecast2 user:
su icecast2 -m /bin/bash -c "ices -c /etc/ices.conf"
  • Fallback playlist: prepare the playlist in mpd then
mpc save fallbackplaylist
  • To get the playlist shuffled differently everytime, change in mpdplaylist.pm
system("mpc load $playlistname");
->
system("mpc load $playlistname && mpc shuffle");
  • To let mpd playing the songs at the same time, only for sync display of the playing song in mpd clients, you can edit mpdplaylist.pm by moving the "mpc del 1" call to the begin of ices_get_next() and adding a call to play the current top song when fetching it, as shown below.
       if (length($playlist) > 0) {
           system("mpc stop && mpc play 1");

phpMp2

  • Download phpMp2
  • Extract into a directory on your webserver
  • Change $mpd_host and $mpd_port in config.php
  • Surf to the location of the phpMp2 directory on your webserver
  • If you use password with mpd, several ways: add it to config.php:
"password" => "mypass",
  • Or use auth.php but be careful "http://" is hardcoded and probably needs to be adapted to "https://" in your case. Anyway, remember, password won't fly in clear between client and phpMp2 but could well between phpMp2 and a remote mpd!
  • As mpd is here only for playlist management we don't need the control panel, we can remove it by removing the following from the layout, e.g. layouts/classic/right.php (once we have a correct way to sent SIGUSR1 to ices we could add it here)
<?php include("control.php") ?>
  • Fix: I got sometimes (when using find) errors because phpMp2 sent a command with protected quotes (\"), maybe because of magic_quoting being active. I solved it by modifying functions.php:
function do_mpd_command($conn, $command, $varname = null, $return_array = false) {   
       //Phil: fix magic quoting breaking mpd msgs                                            
       $command = str_replace('\"', '"', $command);

Other (good) clients of mpd

  • mpc (CLI)
  • gmpc (Gnome GUI)

Media Players That Support Icecast Streaming

TODO

  • setup phpmp2?
  • auto upload of ripped CDs?
  • ices:
    • next song: killall -s USR1 ices
    • how to make it remotely?? through icecast2(php auth?) or mpd...
    • ices crossfade?
    • use mpc play to sync display of played song? will consume a few CPU (dummy sound card, we could try to do a dummy libmad ;-)), otherwise be sure to do mpc stop
  • icecast authorisation, cf http://www.icecast.org/docs/icecast-2.3.1/icecast2_listenerauth.html
    • as streamium does not understand http auth_basic, one solution is to use iptables to filter access locally and use an icecast2 relay with auth_basic for external use when I'm on-the-go