-- exaile.lua, a dxirc script for controlling the Exaile music manager -- 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 = "exaile" local version = "0.9.0" local description = "Control the Exaile music player directly from " .. "dxirc and/or send the currently playing track " .. "to the channel/query. Make sure the Exaile is " .. "already running before using this script." -- Return the information: return name, version, description end -- Register commands: function dxirc_Init() dxirc.AddCommand("exaile", "cmd_exaile","Control the Exaile player. ".. "Usage: /EXAILE [command], where command is either ".. "current, play, pause, stop, next or prev.") end -- Return the string with currently playing song: function exaile_current() -- Run Exaile in a separate process and get the currently playing track: local exaile = io.popen('exaile --get-title --get-artist', 'r') local track_title = exaile:read() local track_artist = exaile:read() exaile:close() -- Check whether the track title is present: if track_title == '' or track_artist == nil then -- Return the Exaile status: return ".:[ Exaile is not playing ]:." else -- Return the formatted result: return ".:[ " .. track_artist .. " - " .. track_title .. " ]:." end end -- Play the track: function exaile_play() -- Run Exaile in a separate process and return its status code: return os.execute('exaile --play-pause') end -- Pause the track: function exaile_pause() -- Run Exaile in a separate process and return its status code: return os.execute('exaile --play-pause') end -- Stop playing the track: function exaile_stop() -- Run Exaile in a separate process and return its status code: return os.execute('exaile --stop') end -- Play previous track: function exaile_prev() -- Run Exaile in a separate process and return its status code: return os.execute('exaile --prev') end -- Play next track: function exaile_next() -- Run Exaile in a separate process and return its status code: return os.execute('exaile --next') end -- Run Exaile with selected command: function cmd_exaile(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(exaile_current(), tab_id) elseif command == "play" then -- Execute the command: exaile_play() elseif command == "pause" then -- Execute the command: exaile_pause() elseif command == "stop" then -- Execute the command: exaile_stop() elseif command == "prev" then -- Execute the command: exaile_prev() elseif command == "next" then -- Execute the command: exaile_next() else -- Report invalid command: dxirc.Print("exaile: Invalid command `" .. command .. "'", tab_id, '4') end end