-- clementine.lua, a dxirc script for controlling the Clementine player -- Copyright (C) 2011 Jaromir Hradilek -- Copyright (C) 2010 David Vachulka -- 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 = "clementine" local version = "0.9.0" local description = "Control the Clementine player directly from " .. "dxirc and/or send the currently playing track " .. "to the channel/query. Note that Clementine 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("clementine", "cmd_clementine","Control Clementine. " .. "Usage: /CLEMENTINE [command], where allowed " .. "commands are current, play, pause, stop, next " .. "or prev.") end function player_is_playing() local player = assert(io.popen('qdbus|grep org.mpris.clementine', 'r')) local retval = true if player:read() ~= ' org.mpris.clementine' then retval = false end player:close() return retval end -- Return the string with currently playing song: function player_current() if player_is_playing() then local f = assert(io.popen('qdbus org.mpris.clementine /Player GetMetadata | grep -e artist -e title')) local artist = f:read():gsub("artist:%s*", "", 1) local title = f:read():gsub("title:%s*", "", 1) f:close() if artist == nil or title == nil then return ".:[ Clementine is not playing ]:." else if artist == nil or artist == '' or title == nil or title == '' then return ".:[ Clementine is playing something ]:." else return ".:[ " .. artist .. " - " .. title .. " ]:." end end else return ".:[ Clementine is not playing ]:." end end -- Play the track: function player_play() if player_is_playing() then return os.execute('qdbus org.mpris.clementine /Player Play') else return false end end -- Pause the track: function player_pause() if player_is_playing() then return os.execute('qdbus org.mpris.clementine /Player Pause') else return false end end -- Stop playing the track: function player_stop() if player_is_playing() then return os.execute('qdbus org.mpris.clementine /Player Stop') else return false end end -- Play the previous track: function player_prev() if player_is_playing() then return os.execute('qdbus org.mpris.clementine /Player Prev') else return false end end -- Play the next track: function player_next() if player_is_playing() then return os.execute('qdbus org.mpris.clementine /Player Next') else return false end end -- Run the player with the selected command: function cmd_clementine(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(player_current(), tab_id) elseif command == "play" then -- Execute the command: player_play() elseif command == "pause" then -- Execute the command: player_pause() elseif command == "stop" then -- Execute the command: player_stop() elseif command == "prev" then -- Execute the command: player_prev() elseif command == "next" then -- Execute the command: player_next() else -- Report invalid command: dxirc.Print("clementine: Invalid command `" .. command .. "'", tab_id, '4') end end