-- mpc.lua, a dxirc script for controlling the Music Player Daemon -- Copyright (C) 2010 Jaromir Hradilek -- This program is free software: you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation, version 3 of the License. -- -- This program is distributed in the hope that it will be useful, but -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTA- -- BILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -- License for more details. -- -- You should have received a copy of the GNU General Public License along -- with this program. If not, see . -- Register the script: function dxirc_Register() -- General script information: local name = "mpc" local version = "0.9.0" local description = "Control the Music Player Daemon directly from " .. "dxirc and/or send the currently playing track " .. "to the channel/query. Note that mpc has to be " .. "installed in order to run this script." -- Return the information: return name, version, description end -- Register commands: function dxirc_Init() dxirc.AddCommand("mpc", "cmd_mpc","Control the Music Player Daemon. ".. "Usage: /MPC [command], where allowed commands are ".. "current, play, pause, stop, next or prev.") end -- Return the string with currently playing song: function mpc_current() -- Run mpc in a separate process and get the currently playing track: local mpc = io.popen('mpc current', 'r') local current_track = mpc:read() mpc:close() -- Check whether the track name is present: if current_track == nil then -- Return the MPD status: return ".:[ MPD is not playing ]:." else -- Return the formatted result: return ".:[ " .. current_track .. " ]:." end end -- Play the track: function mpc_play() -- Run mpc in a separate process and return its status code: return os.execute('mpc play') end -- Pause the track: function mpc_pause() -- Run mpc in a separate process and return its status code: return os.execute('mpc pause') end -- Stop playing the track: function mpc_stop() -- Run mpc in a separate process and return its status code: return os.execute('mpc stop') end -- Play previous track: function mpc_prev() -- Run mpc in a separate process and return its status code: return os.execute('mpc prev') end -- Play next track: function mpc_next() -- Run mpc in a separate process and return its status code: return os.execute('mpc next') end -- Run mpc with selected command: function cmd_mpc(arg, tab_id) -- Convert the argument to lower case: local command = arg:lower() -- Parse the command: if command == '' or command == "current" then -- Send the message to the channel/query: dxirc.Command(mpc_current(), tab_id) elseif command == "play" then -- Execute the command: mpc_play() elseif command == "pause" then -- Execute the command: mpc_pause() elseif command == "stop" then -- Execute the command: mpc_stop() elseif command == "prev" then -- Execute the command: mpc_prev() elseif command == "next" then -- Execute the command: mpc_next() else -- Report invalid command: dxirc.Print("mpc: Invalid command `" .. command .. "'", tab_id, '4') end end