- What's lmpdc?
- It's one of my Lua-binding C libraries at git clone
It implements direct interface for interacting with MPD (Music Player Daemon)
without
any external utils like "mpc". So no spawns, no dependencies (except for Lua
5.1 :),
it's very fast and small.
- How to install?
$ git clone git://github.com/kstep/lua_mod.git
$ make lmpdc.so
$ cp lmpdc.so ~/.config/awesome/
(or you can put it in any place you wish, of cause)
In rc.lua:
assert(package.loadlib("./lmpdc.so", "luaopen_mpdc"))
- What I get? How to use it?
mpd = mpdc.open(os.getenv("MPD_HOST") or "localhost", os.getenv("MPD_PORT") or
6600)
Now "mpd" variable is your gateway to MPD, so you can:
mpd:stop()
mpd:play()
mpd:next()
mpd:prev()
mpd:shuffle()
You can as well do:
mpd:set_repeat(<bool>)
and
mpd:set_random(<bool>)
to turn repeat/random on/off
mpd:clear() - cleans your current playlist
mpd:status() - returns table with MPD's status
mpd:currentsong() - table with your current song meta
mpd:playlistid() - table with your current playlist
mpd:add(filename) - add file into playlist,
mpd:delid(songid) - remove song from playlist,
mpd:seekid(songid, seconds) - start playing song by id at specified time offset
in seconds.
For example here's a function(s) I use to build awesome menu with my current
playlist
to choose song to play:
function mpdc_create_song_title(song)
local songtitle = ""
if song["Artist"] then
songtitle = song["Artist"]
else
songtitle = "Unknown artist"
end
if song["Title"] then
songtitle = songtitle .. " - " .. song["Title"]
elseif song["file"] then
songtitle = songtitle .. " - " .. song["file"]:gsub("^.*/",
""):gsub("%.[a-z0-3]+$", "")
end
return songtitle
end
function mpdc_playlistmenu(pagesize, moretext)
local playlist = mpd:playlistid()
local pagenum = 1
if not pagesize then pagesize = 40 end
if not moretext then moretext = "more (page %d)" end
local function playlist_xform(from)
local it = 0
local songlist = {}
for k = from, #playlist do
it = it + 1
if it > pagesize then
pagenum = pagenum + 1
table.insert(songlist, { moretext:format(pagenum),
playlist_xform(k) })
break
end
table.insert(songlist, { mpdc_create_song_title(playlist[k]), function ()
mpd:seekid(playlist[k]["Id"], 0) end })
end
return songlist
end
local songlist = playlist_xform(1)
return awful.menu.new({ items = songlist, border_width = 0, width = 400 })
end
So I run:
mpdmenu = mpdc_playlistmenu(20, "more...")
and get awesome menu in mpdmenu with my playlist.
And if playlist is longer than 20, it will be splitted into cascade submenus
("pages") with text "more..." being the menu item which shows next menu-page.
It's the tightest MPD-Lua binding! No spawns of "mpc" and parsing its output.
You work with native Lua structures.
This release is proved to be stable (at least on my machine).
I've just caught the last bug in it :)
Hope it will help somebody.
--
To unsubscribe, send mail to [email protected].