Play Last.fm in mpd

Linux guide to Play Last.fm streams in mpd
  1. Install Python, install and configure MPD, install mpc(optional)
  2. Download lastfmproxy
  3. Unpack it to /usr/local/bin/lastfmproxy
  4. edit /usr/local/bin/lastfmproxy/config.py
    username and password are enought
  5. make file /etc/init.d/lastfmproxy:
    #!/bin/sh

    case "$1" in
      start)
            pkill -f "lastfmproxy/main.py"
            /usr/local/bin/lastfmproxy/main.py 1,2>/dev/null &
            ;;
      stop)
            pkill -f "lastfmproxy/main.py"
            ;;
      restart)
            pkill -f "lastfmproxy/main.py"
            /usr/local/bin/lastfmproxy/main.py 1,2>/dev/null &
            ;;
      *)
            N=/etc/init.d/$NAME
            echo "Usage: $N {start|stop|restart|status}" >&2
            exit 1
            ;;
    esac

    exit 0
  6. add lastfmproxy to runlevels 2-5 (for example with help of sysv-rc-conf)
  7. Make file executable and run lastfmproxy:
    sudo chmod u+x /etc/init.d/lastfmproxy sudo /etc/init.d/lastfmproxy start
  8. You can now find interesting page with your browser "http://localhost:1881/"
  9. If you have mpc installed then find file m3u-handler.sh and use it to add radio streams to mpd
    /path_to_file/m3u-handler.sh "url"
    You may need to make it executable:
    chmod +x /path_to_file/m3u-handler.sh
    You can just use
    mpc add "url" mpc play
  10. Some usefull urls:
    http://localhost:1881/user/username/recommended.mp3
    http://localhost:1881/user/username/personal.mp3
    http://localhost:1881/globaltags/tag.mp3
    Only one stream can be played at time
  11. Usefull info:
    Read /usr/local/bin/lastfmproxy/README.txt because you can find there how to change your firefox settings for changing station on proxy while choosing them on last.fm site
  12. You may also install QMPDClient or sonata for Graphical frontedn to MPD
    There exist other frontends too:
    ario - GTK+ client for the Music Player Daemon (MPD)
    gimmix - graphical music player daemon (MPD) client using GTK+2
    glurp - gtk2.4+ frontend to the Music Player Daemon (MPD)
    gmpc - Gnome Music Player Client (graphical interface to MPD)
    pygmy - PyGTK client for the Music Player Daemon (MPD)
    pympd - Frontend for mpd in the style of rhythmbox and itunes
    sonata - GTK+ client for the Music Player Daemon (MPD)
    xfmpc - graphical GTK+ MPD client

P.S. if you want scrobbling to last.fm you may install "lastmp - MPD client for lastfmsubmitd" (don't forget to configure it)
P.P.S. I recommend you to use xbindkeys to control MPD with mpc. Here is my ~/.xbindkeysrc:
"mpc stop" Control+Alt + Delete "mpc toggle" Control+Alt + Insert "mpc toggle" Control+Alt + Home "mpc next" Control+Alt + Next "mpc prev" Control+Alt + Prior "qmpdclient" Control+Alt + P "mpc seek +00:00:02" Control+Alt + Right "mpc seek -00:00:02" Control+Alt + Left


P.P.P.S. If you are expiriencing lags you may increase buffer size for mpd(/etc/mpd.conf):
http_buffer_size "1024" http_prebuffer_size "256"

В Gentoo всё проще. Там просто надо размаскировать пакет lastfmproxy, поставить его, отредактировать /usr/share/lastfmproxy/config.py и можно добавлять его в ранлевел