2013-11-01 15:27:20 +01:00
|
|
|
-- Drive spotify
|
|
|
|
|
2013-11-01 15:56:21 +01:00
|
|
|
-- Spotify uses the MPRIS D-BUS interface. See more information here:
|
|
|
|
-- http://specifications.freedesktop.org/mpris-spec/latest/
|
|
|
|
|
|
|
|
-- To get the complete interface:
|
|
|
|
-- mdbus2 org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2
|
|
|
|
|
2013-11-02 19:06:51 +01:00
|
|
|
local awful = require("awful")
|
|
|
|
local pairs = pairs
|
2015-07-12 11:31:13 +02:00
|
|
|
local os = os
|
2013-11-02 19:06:51 +01:00
|
|
|
local capi = {
|
|
|
|
client = client
|
|
|
|
}
|
2013-11-01 15:27:20 +01:00
|
|
|
|
|
|
|
module("vbe/spotify")
|
|
|
|
|
2015-07-12 11:31:13 +02:00
|
|
|
-- Get spotify window
|
|
|
|
local function spotify()
|
|
|
|
local clients = capi.client.get()
|
|
|
|
for k, c in pairs(clients) do
|
|
|
|
if awful.rules.match(c, { instance = "spotify",
|
|
|
|
class = "Spotify" }) then
|
|
|
|
return c
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2013-11-01 15:27:20 +01:00
|
|
|
-- Send a command to spotify
|
2015-07-12 11:31:13 +02:00
|
|
|
local function cmd(command)
|
|
|
|
local client = spotify()
|
|
|
|
if client then
|
|
|
|
os.execute("xdotool key --window " .. client.window .. " " .. command)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Show spotify
|
|
|
|
function show()
|
|
|
|
local client = spotify()
|
|
|
|
if client then
|
|
|
|
if not client:isvisible() then
|
|
|
|
awful.tag.viewonly(client:tags()[1])
|
|
|
|
end
|
|
|
|
capi.client.focus = client
|
|
|
|
client:raise()
|
|
|
|
else
|
|
|
|
awful.util.spawn("spotify")
|
|
|
|
end
|
2013-11-01 15:27:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function playpause()
|
2015-07-12 11:31:13 +02:00
|
|
|
cmd("space")
|
2013-11-01 15:27:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function play()
|
2015-07-12 11:31:13 +02:00
|
|
|
cmd("XF86AudioPlay")
|
2013-11-01 15:27:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function pause()
|
2015-07-12 11:31:13 +02:00
|
|
|
cmd("XF86AudioPause")
|
2013-11-01 15:27:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function stop()
|
2015-07-12 11:31:13 +02:00
|
|
|
cmd("XF86AudioStop")
|
2013-11-01 15:27:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function next()
|
2015-07-12 11:31:13 +02:00
|
|
|
cmd("XF86AudioNext")
|
2013-11-01 15:27:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function previous()
|
2015-07-12 11:31:13 +02:00
|
|
|
cmd("XF86AudioPrev")
|
2013-11-01 15:53:35 +01:00
|
|
|
end
|