2021-02-09 15:15:20 +01:00
|
|
|
-- Provides:
|
|
|
|
-- bling::playerctl::status
|
|
|
|
-- playing (boolean)
|
2021-02-17 02:14:26 +01:00
|
|
|
-- bling::playerctl::title_artist_album
|
2021-02-13 03:37:45 +01:00
|
|
|
-- title (string)
|
|
|
|
-- artist (string)
|
2021-02-17 02:14:26 +01:00
|
|
|
-- album_path (string)
|
2021-02-13 03:37:45 +01:00
|
|
|
-- bling::playerctl::position
|
2021-02-09 15:15:20 +01:00
|
|
|
-- interval_sec (number)
|
|
|
|
-- length_sec (number)
|
|
|
|
--
|
|
|
|
local awful = require("awful")
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
|
2021-02-12 12:16:24 +01:00
|
|
|
local interval = beautiful.playerctl_position_update_interval or 1
|
2021-02-09 15:15:20 +01:00
|
|
|
|
|
|
|
local function emit_player_status()
|
2021-02-12 12:16:24 +01:00
|
|
|
local status_cmd = "playerctl status -F"
|
|
|
|
|
|
|
|
-- Follow status
|
|
|
|
awful.spawn.easy_async_with_shell(
|
|
|
|
"ps x | grep \"playerctl status\" | grep -v grep | awk '{print $1}' | xargs kill",
|
|
|
|
function()
|
|
|
|
awful.spawn.with_line_callback(status_cmd, {
|
|
|
|
stdout = function(line)
|
|
|
|
local playing = false
|
|
|
|
if line:find("Playing") then
|
|
|
|
playing = true
|
|
|
|
else
|
|
|
|
playing = false
|
|
|
|
end
|
|
|
|
awesome.emit_signal("bling::playerctl::status", playing)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end)
|
2021-02-09 15:15:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function emit_player_info()
|
|
|
|
local art_script = [[
|
|
|
|
sh -c '
|
|
|
|
|
2021-02-11 15:12:19 +01:00
|
|
|
tmp_dir="$XDG_CACHE_HOME/awesome/"
|
|
|
|
|
|
|
|
if [ -z ${XDG_CACHE_HOME} ]; then
|
|
|
|
tmp_dir="$HOME/.cache/awesome/"
|
|
|
|
fi
|
|
|
|
|
2021-02-09 15:15:20 +01:00
|
|
|
tmp_cover_path=${tmp_dir}"cover.png"
|
|
|
|
|
|
|
|
if [ ! -d $tmp_dir ]; then
|
|
|
|
mkdir -p $tmp_dir
|
|
|
|
fi
|
|
|
|
|
2021-02-16 02:20:44 +01:00
|
|
|
link="$(playerctl metadata mpris:artUrl)"
|
2021-02-09 15:15:20 +01:00
|
|
|
|
|
|
|
curl -s "$link" --output $tmp_cover_path
|
|
|
|
|
2021-02-13 03:37:45 +01:00
|
|
|
echo "$tmp_cover_path"
|
2021-02-09 15:15:20 +01:00
|
|
|
']]
|
|
|
|
|
2021-02-12 12:16:24 +01:00
|
|
|
-- Command that lists artist and title in a format to find and follow
|
|
|
|
local song_follow_cmd =
|
|
|
|
"playerctl metadata --format 'artist_{{artist}}title_{{title}}' -F"
|
2021-02-09 15:15:20 +01:00
|
|
|
|
2021-02-12 12:16:24 +01:00
|
|
|
-- Progress Cmds
|
2021-02-09 15:15:20 +01:00
|
|
|
local prog_cmd = "playerctl position"
|
|
|
|
local length_cmd = "playerctl metadata mpris:length"
|
|
|
|
|
2021-02-12 12:16:24 +01:00
|
|
|
awful.widget.watch(prog_cmd, interval, function(_, interval)
|
2021-02-09 15:15:20 +01:00
|
|
|
awful.spawn.easy_async_with_shell(length_cmd, function(length)
|
|
|
|
local length_sec = tonumber(length) -- in microseconds
|
|
|
|
local interval_sec = tonumber(interval) -- in seconds
|
|
|
|
if length_sec and interval_sec then
|
|
|
|
if interval_sec >= 0 and length_sec > 0 then
|
|
|
|
awesome.emit_signal("bling::playerctl::position",
|
|
|
|
interval_sec, length_sec / 1000000)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2021-02-12 12:16:24 +01:00
|
|
|
-- Follow title
|
|
|
|
awful.spawn.easy_async_with_shell(
|
2021-02-17 06:21:29 +01:00
|
|
|
"ps x | grep \"playerctl metadata\" | grep -v grep | awk '{print $1}' | xargs kill",
|
|
|
|
function()
|
2021-02-12 12:16:24 +01:00
|
|
|
awful.spawn.with_line_callback(song_follow_cmd, {
|
|
|
|
stdout = function(line)
|
2021-02-17 05:52:59 +01:00
|
|
|
local album_path = ""
|
2021-02-12 12:16:24 +01:00
|
|
|
awful.spawn.easy_async_with_shell(art_script, function(out)
|
2021-02-17 02:14:26 +01:00
|
|
|
-- Get album path
|
2021-02-17 05:52:59 +01:00
|
|
|
album_path = out:gsub('%\n', '')
|
2021-02-17 06:21:29 +01:00
|
|
|
-- Get title and artist
|
|
|
|
local artist = line:match('artist_(.*)title_')
|
|
|
|
local title = line:match('title_(.*)')
|
|
|
|
awesome.emit_signal(
|
|
|
|
"bling::playerctl::title_artist_album", title,
|
|
|
|
artist, album_path)
|
2021-02-12 12:16:24 +01:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end)
|
2021-02-09 15:15:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Emit info
|
|
|
|
-- emit_player_status()
|
|
|
|
-- emit_player_info()
|
|
|
|
|
|
|
|
local enable = function()
|
|
|
|
emit_player_status()
|
|
|
|
emit_player_info()
|
|
|
|
end
|
|
|
|
|
|
|
|
return {enable = enable}
|