-- rhythmbox.lua, a dxirc script for controlling the Rhythmbox music player -- 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 = "rhythmbox" local version = "0.9.0" local description = "Control the Rhythmbox music player directly from ".. "dxirc and/or send the currently playing track to ".. "the channel/query." -- Return the information: return name, version, description end -- Register commands: function dxirc_Init() dxirc.AddCommand("rhythmbox", "cmd_rhythmbox","Control the Rhythmbox. ".. "Usage: /RHYTHMBOX [command], where allowed commands ".. "are current, play, pause, stop, next or prev.") end -- Return the string with currently playing song: function rhythmbox_current() -- Run the remote control in a separate process and get the name of the -- currently playing track: local rhythmbox = io.popen("rhythmbox-client --no-start " .. "--print-playing-format '%aa - %tt'", 'r') local current_track = rhythmbox:read() rhythmbox:close() -- Check whether the track name is present: if current_track == nil then -- Return the player status: return ".:[ Rhythmbox is not playing ]:." else -- Return the formatted result: return ".:[ " .. current_track .. " ]:." end end -- Play the track: function rhythmbox_play() -- Run the remote control in a separate process and return its status -- code: return os.execute('rhythmbox-client --no-start --play') end -- Pause the track: function rhythmbox_pause() -- Run the remote control in a separate process and return its status -- code: return os.execute('rhythmbox-client --no-start --pause') end -- Stop playing the track: function rhythmbox_stop() -- Run the remote control in a separate process and return its status -- code: return os.execute('rhythmbox-client --no-start --pause') end -- Play previous track: function rhythmbox_prev() -- Run the remote control in a separate process and return its status -- code: return os.execute('rhythmbox-client --no-start --previous') end -- Play next track: function rhythmbox_next() -- Run the remote control in a separate process and return its status -- code: return os.execute('rhythmbox-client --no-start --next') end -- Run the remote control with selected command: function cmd_rhythmbox(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(rhythmbox_current(), tab_id) elseif command == "play" then -- Execute the command: rhythmbox_play() elseif command == "pause" then -- Execute the command: rhythmbox_pause() elseif command == "stop" then -- Execute the command: rhythmbox_stop() elseif command == "prev" then -- Execute the command: rhythmbox_prev() elseif command == "next" then -- Execute the command: rhythmbox_next() else -- Report invalid command: dxirc.Print("rhythmbox: Invalid command `" .. command .. "'", tab_id, "4") end end