-- amarok.lua, a dxirc script for controlling the Amarok -- Copyright (C) 2010 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 = "amarok" local version = "0.9.0" local description = "Control the Amarok directly from " .. "dxirc and/or send the currently playing track " .. "to the channel/query. Note that Amarok 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("amarok", "cmd_amarok","Control the Amarok. ".. "Usage: /AMAROK [command], where allowed commands are ".. "current, play, pause, stop, next or prev.") end function amarok_is_playing() local amarok = assert(io.popen('qdbus | grep org.kde.amarok', 'r')) if amarok:read() == ' org.kde.amarok' then amarok:close() return true else amarok:close() return false end end -- Return the string with currently playing song: function amarok_current() if amarok_is_playing() then local f = assert(io.popen('qdbus org.kde.amarok /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 ".:[ Amarok is not playing ]:." else if artist == nil or artist == '' or title == nil or title == '' then return ".:[ Amarok is playing something ]:." else return ".:[ " .. artist .. " - " .. title .. " ]:." end end else return ".:[ Amarok is not playing ]:." end end -- Play the track: function amarok_play() if amarok_is_playing() then return os.execute('qdbus org.kde.amarok /Player Play') else return false end end -- Pause the track: function amarok_pause() if amarok_is_playing() then return os.execute('qdbus org.kde.amarok /Player Pause') else return false end end -- Stop playing the track: function amarok_stop() if amarok_is_playing() then return os.execute('qdbus org.kde.amarok /Player Stop') else return false end end -- Play previous track: function amarok_prev() if amarok_is_playing() then return os.execute('qdbus org.kde.amarok /Player Prev') else return false end end -- Play next track: function amarok_next() if amarok_is_playing() then return os.execute('qdbus org.kde.amarok /Player Next') else return false end end -- Run amarok with selected command: function cmd_amarok(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(amarok_current(), tab_id) elseif command == "play" then -- Execute the command: amarok_play() elseif command == "pause" then -- Execute the command: amarok_pause() elseif command == "stop" then -- Execute the command: amarok_stop() elseif command == "prev" then -- Execute the command: amarok_prev() elseif command == "next" then -- Execute the command: amarok_next() else -- Report invalid command: dxirc.Print("amarok: Invalid command `" .. command .. "'", tab_id, '4') end end