Name: ~parafin/linux/addfile2mpd
Summary: script to add files not from database to MPD playlist
Author: parafin
Created: Mon, 17 Aug 2009 14:06:35 GMT
Last update: Wed, 19 Aug 2009 17:51:18 GMT by parafin
Atom feed
Modify access level: moderator

addfile2mpd

This expect script makes use of file:// protocol feature of recent MPD server so you can listen to music files not in your MPD database. Usage is simple: ./addfile2mpd relative/path/to/song.ogg /absolute/path/to/song.flac. You can also use it as "Run action" or "Send to" program in your file manager (that's how I use it in my ROX-Filer).

Dependencies

  • dev-tcltk/expect
  • net-misc/socat
  • >=media-sound/mpd-0.15

Also you have to add to your MPD config these lines:

~/.mpdconf
#change /path/to/ in next line to some existing directory
bind_to_address "/path/to/mpd.socket"
#next line is only needed when there was no bind_to_address parameters before this change
bind_to_address "any"
Note: BTW, media-sound/gmpc has support for this MPD feature - you must simply put /path/to/mpd.socket in location field and then you can drag'n'drop files to gmpc's top widget to add them to playlist.

Code listing

addfile2mpd
#!/usr/bin/expect
#change /path/to/mpd.socket to actual path from your MPD config
spawn socat - UNIX-CONNECT:/path/to/mpd.socket
expect "OK MPD"
#change LetMePass to your MPD password
#or comment out entire next line if you haven't set password parameter in MPD config
send "password LetMePass\n"
foreach i $argv {
        set i [exec readlink -ve $i]
        regsub -all {([\\"])} $i {\\\1} i
        if { $i ne "" } {
                expect OK
                send "add \"file://$i\"\n"
        }
}
expect OK