-- banshee.lua, a dxirc script for controlling Banshee Media 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 = "banshee" local version = "0.9.0" local description = "Control your Banshee Media Player directly from " .. "dxirc and/or send the currently playing track to ".. "the channel/query. Make sure Banshee is already " .. "running before using this script." -- Return the information: return name, version, description end -- Register commands: function dxirc_Init() dxirc.AddCommand("banshee","cmd_banshee","Control Banshee Media Player".. ". Usage: /BANSHEE [command], where allowed commands ".. "are current, play, pause, stop, next or prev.") end -- Return the string with currently playing song: function banshee_current() -- Run the remote control application in a separate process and get the -- currently playing track: local banshee = io.popen('banshee --query-title --query-artist','r') local track_title = banshee:read():gsub("title:%s*", "", 1) local track_artist = banshee:read():gsub("artist:%s*", "", 1) banshee:close() -- Check whether the track title is present: if track_title == '' and track_artist == '' then -- Return the player status: return ".:[ Banshee is not playing ]:." else -- Return the formatted result: return ".:[ " .. track_artist .. " - " .. track_title .. " ]:." end end -- Play the track: function banshee_play() -- Run the remote control application in a separate process and return -- its status code: return os.execute('banshee --play') end -- Pause the track: function banshee_pause() -- Run the remote control application in a separate process and return -- its status code: return os.execute('banshee --pause') end -- Stop playing the track: function banshee_stop() -- Run the remote control application in a separate process and return -- its status code: return os.execute('banshee --stop') end -- Play previous track: function banshee_prev() -- Run the remote control application in a separate process and return -- its status code: return os.execute('banshee --previous') end -- Play next track: function banshee_next() -- Run the remote control application in a separate process and return -- its status code: return os.execute('banshee --next') end -- Run the remote control application with selected command: function cmd_banshee(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(banshee_current(), tab_id) elseif command == "play" then -- Execute the command: banshee_play() elseif command == "pause" then -- Execute the command: banshee_pause() elseif command == "stop" then -- Execute the command: banshee_stop() elseif command == "prev" then -- Execute the command: banshee_prev() elseif command == "next" then -- Execute the command: banshee_next() else -- Report invalid command: dxirc.Print("banshee: Invalid command `" .. command .. "'", tab_id,"4") end end