From 736251f20d2ece65923f2f68f8392e95b8745438 Mon Sep 17 00:00:00 2001 From: Gokul Swami Date: Tue, 9 Feb 2021 06:15:20 -0800 Subject: [PATCH 01/10] Added playerctl daemon --- module/init.lua | 3 +- module/playerctl_daemon.lua | 90 +++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 module/playerctl_daemon.lua diff --git a/module/init.lua b/module/init.lua index 953e24a..3501ec9 100644 --- a/module/init.lua +++ b/module/init.lua @@ -3,5 +3,6 @@ return { tiled_wallpaper = require(... .. ".tiled_wallpaper"), wallpaper = require(... .. ".wallpaper"), flash_focus = require(... .. ".flash_focus"), - tabbed = require(... .. ".tabbed") + tabbed = require(... .. ".tabbed"), + playerctl_daemon = require(... .. ".playerctl_daemon") } diff --git a/module/playerctl_daemon.lua b/module/playerctl_daemon.lua new file mode 100644 index 0000000..36b4278 --- /dev/null +++ b/module/playerctl_daemon.lua @@ -0,0 +1,90 @@ +-- Provides: +-- bling::playerctl::status +-- playing (boolean) +-- bling::playerctl::album +-- album_art (string) +-- bling::playerctl::title +-- stdout (string) +-- bling::playerctl::info +-- interval_sec (number) +-- length_sec (number) +-- +local awful = require("awful") +local beautiful = require("beautiful") + +local update_interval = beautiful.playerctl_album_update_interval or 5 +local interval_status = beautiful.playerctl_position_update_interval or 1 + +local function emit_player_status() + local status_cmd = "playerctl status" + awful.widget.watch(status_cmd, interval_status, function(_, stdout) + local playing = false + if stdout:find("Playing") then + playing = true + else + playing = false + end + awesome.emit_signal("bling::playerctl::status", playing) + end) +end + +local function emit_player_info() + local art_script = [[ +sh -c ' + +tmp_dir="/tmp/awesomewm/bling-playerctl/" +tmp_cover_path=${tmp_dir}"cover.png" + +if [ ! -d $tmp_dir ]; then + mkdir -p $tmp_dir +fi + +link="$(playerctl metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g')" + +curl -s "$link" --output $tmp_cover_path + +echo $tmp_cover_path +']] + + local song_title_cmd = "playerctl metadata title" + local song_title = "No Song Playing" + + awful.widget.watch(song_title_cmd, update_interval, function(_, stdout) + if not (song_title == stdout) then + awful.spawn.easy_async_with_shell(art_script, function(out) + local album_path = out:gsub('%\n', '') + awesome.emit_signal("bling::playerctl::album", album_path) + end) + song_title = stdout + end + awesome.emit_signal("bling::playerctl::title", stdout) + end) + + local prog_cmd = "playerctl position" + local length_cmd = "playerctl metadata mpris:length" + + awful.widget.watch(prog_cmd, interval_status, function(_, interval) + 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) + +end + +-- Emit info +-- emit_player_status() +-- emit_player_info() + +local enable = function() + emit_player_status() + emit_player_info() +end + +return {enable = enable} From 31e7357b1fc56dcf7f666e7d9be8ba071711adfd Mon Sep 17 00:00:00 2001 From: Gokul Swami Date: Thu, 11 Feb 2021 05:58:36 -0800 Subject: [PATCH 02/10] Refractor signals --- init.lua | 7 ++----- module/init.lua | 3 +-- signals/init.lua | 1 + module/playerctl_daemon.lua => signals/playerctl.lua | 0 4 files changed, 4 insertions(+), 7 deletions(-) create mode 100644 signals/init.lua rename module/playerctl_daemon.lua => signals/playerctl.lua (100%) diff --git a/init.lua b/init.lua index 38c84df..e94645f 100644 --- a/init.lua +++ b/init.lua @@ -1,12 +1,9 @@ --[[ Bling Layouts, widgets and utilities for Awesome WM ---]] - - -return { +--]] return { layout = require(... .. ".layout"), module = require(... .. ".module"), helpers = require(... .. ".helpers"), + signals = require(... .. ".signals") } - diff --git a/module/init.lua b/module/init.lua index 3501ec9..953e24a 100644 --- a/module/init.lua +++ b/module/init.lua @@ -3,6 +3,5 @@ return { tiled_wallpaper = require(... .. ".tiled_wallpaper"), wallpaper = require(... .. ".wallpaper"), flash_focus = require(... .. ".flash_focus"), - tabbed = require(... .. ".tabbed"), - playerctl_daemon = require(... .. ".playerctl_daemon") + tabbed = require(... .. ".tabbed") } diff --git a/signals/init.lua b/signals/init.lua new file mode 100644 index 0000000..a4a2ad7 --- /dev/null +++ b/signals/init.lua @@ -0,0 +1 @@ +return {playerctl = require(... .. ".playerctl")} diff --git a/module/playerctl_daemon.lua b/signals/playerctl.lua similarity index 100% rename from module/playerctl_daemon.lua rename to signals/playerctl.lua From 1deb7e4ab20348c6623bae60be9261aee6925c40 Mon Sep 17 00:00:00 2001 From: Gokul Swami Date: Thu, 11 Feb 2021 06:12:19 -0800 Subject: [PATCH 03/10] Change art download path --- signals/playerctl.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/signals/playerctl.lua b/signals/playerctl.lua index 36b4278..1fa30dc 100644 --- a/signals/playerctl.lua +++ b/signals/playerctl.lua @@ -32,7 +32,12 @@ local function emit_player_info() local art_script = [[ sh -c ' -tmp_dir="/tmp/awesomewm/bling-playerctl/" +tmp_dir="$XDG_CACHE_HOME/awesome/" + +if [ -z ${XDG_CACHE_HOME} ]; then + tmp_dir="$HOME/.cache/awesome/" +fi + tmp_cover_path=${tmp_dir}"cover.png" if [ ! -d $tmp_dir ]; then From 5270fe90de704352eed6e232703c60478f5bbf5f Mon Sep 17 00:00:00 2001 From: Gokul Swami Date: Fri, 12 Feb 2021 00:17:01 -0800 Subject: [PATCH 04/10] Added artist --- signals/playerctl.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/signals/playerctl.lua b/signals/playerctl.lua index 1fa30dc..b3f6f2a 100644 --- a/signals/playerctl.lua +++ b/signals/playerctl.lua @@ -3,8 +3,9 @@ -- playing (boolean) -- bling::playerctl::album -- album_art (string) --- bling::playerctl::title +-- bling::playerctl::title_artist -- stdout (string) +-- out (string) -- bling::playerctl::info -- interval_sec (number) -- length_sec (number) @@ -52,6 +53,7 @@ echo $tmp_cover_path ']] local song_title_cmd = "playerctl metadata title" + local song_artist_cmd = "playerctl metadata artist" local song_title = "No Song Playing" awful.widget.watch(song_title_cmd, update_interval, function(_, stdout) @@ -62,7 +64,9 @@ echo $tmp_cover_path end) song_title = stdout end - awesome.emit_signal("bling::playerctl::title", stdout) + awful.spawn.easy_async_with_shell(song_artist_cmd, function(out) + awesome.emit_signal("bling::playerctl::title_artist", stdout, out) + end) end) local prog_cmd = "playerctl position" From 07f485d37580cbf67c1d894c2c8262bceb23562b Mon Sep 17 00:00:00 2001 From: Gokul Swami Date: Fri, 12 Feb 2021 03:16:24 -0800 Subject: [PATCH 05/10] Changed some functions to rely on follows --- signals/playerctl.lua | 74 ++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/signals/playerctl.lua b/signals/playerctl.lua index b3f6f2a..a8e7231 100644 --- a/signals/playerctl.lua +++ b/signals/playerctl.lua @@ -13,20 +13,27 @@ local awful = require("awful") local beautiful = require("beautiful") -local update_interval = beautiful.playerctl_album_update_interval or 5 -local interval_status = beautiful.playerctl_position_update_interval or 1 +local interval = beautiful.playerctl_position_update_interval or 1 local function emit_player_status() - local status_cmd = "playerctl status" - awful.widget.watch(status_cmd, interval_status, function(_, stdout) - local playing = false - if stdout:find("Playing") then - playing = true - else - playing = false - end - awesome.emit_signal("bling::playerctl::status", playing) - end) + 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) end local function emit_player_info() @@ -52,27 +59,15 @@ curl -s "$link" --output $tmp_cover_path echo $tmp_cover_path ']] - local song_title_cmd = "playerctl metadata title" - local song_artist_cmd = "playerctl metadata artist" - local song_title = "No Song Playing" - - awful.widget.watch(song_title_cmd, update_interval, function(_, stdout) - if not (song_title == stdout) then - awful.spawn.easy_async_with_shell(art_script, function(out) - local album_path = out:gsub('%\n', '') - awesome.emit_signal("bling::playerctl::album", album_path) - end) - song_title = stdout - end - awful.spawn.easy_async_with_shell(song_artist_cmd, function(out) - awesome.emit_signal("bling::playerctl::title_artist", stdout, out) - end) - end) + -- 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" + -- Progress Cmds local prog_cmd = "playerctl position" local length_cmd = "playerctl metadata mpris:length" - awful.widget.watch(prog_cmd, interval_status, function(_, interval) + awful.widget.watch(prog_cmd, interval, function(_, interval) awful.spawn.easy_async_with_shell(length_cmd, function(length) local length_sec = tonumber(length) -- in microseconds local interval_sec = tonumber(interval) -- in seconds @@ -85,6 +80,27 @@ echo $tmp_cover_path end) end) + -- Follow title + awful.spawn.easy_async_with_shell( + "ps x | grep \"playerctl metadata\" | grep -v grep | awk '{print $1}' | xargs kill", + function() + awful.spawn.with_line_callback(song_follow_cmd, { + stdout = function(line) + -- Get Album Art + awful.spawn.easy_async_with_shell(art_script, function(out) + local album_path = out:gsub('%\n', '') + awesome.emit_signal("bling::playerctl::album", + album_path) + end) + + -- Get Title and Artist + local artist = line:match('artist_(.*)title_') + local title = line:match('title_(.*)') + awesome.emit_signal("bling::playerctl::title_artist", title, + artist) + end + }) + end) end -- Emit info From a9d411a833813eec4157a46e7cdfbeb464fe048e Mon Sep 17 00:00:00 2001 From: Gokul Swami Date: Fri, 12 Feb 2021 18:37:45 -0800 Subject: [PATCH 06/10] Fix header --- signals/playerctl.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/signals/playerctl.lua b/signals/playerctl.lua index a8e7231..866b09e 100644 --- a/signals/playerctl.lua +++ b/signals/playerctl.lua @@ -4,9 +4,9 @@ -- bling::playerctl::album -- album_art (string) -- bling::playerctl::title_artist --- stdout (string) --- out (string) --- bling::playerctl::info +-- title (string) +-- artist (string) +-- bling::playerctl::position -- interval_sec (number) -- length_sec (number) -- @@ -56,7 +56,7 @@ link="$(playerctl metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g curl -s "$link" --output $tmp_cover_path -echo $tmp_cover_path +echo "$tmp_cover_path" ']] -- Command that lists artist and title in a format to find and follow From 2d829460ef0a07a94164e21922645bdd88a1b45f Mon Sep 17 00:00:00 2001 From: Gokul Swami Date: Mon, 15 Feb 2021 17:16:26 -0800 Subject: [PATCH 07/10] renamed signals to signal --- init.lua | 2 +- {signals => signal}/init.lua | 0 {signals => signal}/playerctl.lua | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename {signals => signal}/init.lua (100%) rename {signals => signal}/playerctl.lua (100%) diff --git a/init.lua b/init.lua index e94645f..0ac3478 100644 --- a/init.lua +++ b/init.lua @@ -5,5 +5,5 @@ layout = require(... .. ".layout"), module = require(... .. ".module"), helpers = require(... .. ".helpers"), - signals = require(... .. ".signals") + signal = require(... .. ".signal") } diff --git a/signals/init.lua b/signal/init.lua similarity index 100% rename from signals/init.lua rename to signal/init.lua diff --git a/signals/playerctl.lua b/signal/playerctl.lua similarity index 100% rename from signals/playerctl.lua rename to signal/playerctl.lua From 47515afdf986be75ca3f789907c121299f48779d Mon Sep 17 00:00:00 2001 From: Gokul Swami Date: Mon, 15 Feb 2021 17:20:44 -0800 Subject: [PATCH 08/10] Script Change Turns out the link given by playerctl works now, no need to pipe through sed. --- signal/playerctl.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/signal/playerctl.lua b/signal/playerctl.lua index 866b09e..9719130 100644 --- a/signal/playerctl.lua +++ b/signal/playerctl.lua @@ -52,7 +52,7 @@ if [ ! -d $tmp_dir ]; then mkdir -p $tmp_dir fi -link="$(playerctl metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g')" +link="$(playerctl metadata mpris:artUrl)" curl -s "$link" --output $tmp_cover_path From f12f38fcef24c3830b7b9517c0beec1d4858ed02 Mon Sep 17 00:00:00 2001 From: gokul swaminathan <33443763+JavaCafe01@users.noreply.github.com> Date: Mon, 15 Feb 2021 17:42:44 -0800 Subject: [PATCH 09/10] added readme documentation --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/README.md b/README.md index 23c4e51..3049db4 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,52 @@ bling.module.tabbed.iter() -- iterates through the currently focused bling.module.tabbed.pick_with_dmenu() -- picks a client with a dmenu application (defaults to rofi, other options can be set with a string parameter like "dmenu") ``` +##### 🎵 Playerctl Signals + +This is a signal module in which you can connect to certain bling signals to grab playerctl info. Currently, this is what it supports: + +- Song title and artist +- Album art (the path this module downloaded the art to) +- If playing or not +- Position +- Song length + +This module relies on `playerctl` and `curl`. If you have this module disabled, you won't need those programs. + +###### Signals + +```lua +-- bling::playerctl::status -- first line is the signal +-- playing (boolean) -- indented lines are function parameters +-- bling::playerctl::album +-- album_art (string) +-- bling::playerctl::title_artist +-- title (string) +-- artist (string) +-- bling::playerctl::position +-- interval_sec (number) +-- length_sec (number) +``` + +###### Example Implementation + +Lets say we have an imagebox. If I wanted to set the imagebox to show the album art, all I have to do is this: +```lua +local art = wibox.widget { + image = "default_image.png", + resize = true, + forced_height = dpi(80), + forced_width = dpi(80), + widget = wibox.widget.imagebox +} + +awesome.connect_signal("bling::playerctl::album", function(path) + art:set_image(gears.surface.load_uncached(path)) +end) +``` +Thats all! You don't even have to worry about updating the imagebox, the signals will handle that for you. + + ### 🌈 Theme variables You will find a list of all theme variables that are used in bling and comments on what they do in the `theme-var-template.lua` file - ready for you to copy them into your `theme.lua`. Theme variables are not only used to change the appearance of some features but also to adjust the functionality of some modules. So it is worth it to take a look at them. @@ -241,6 +287,11 @@ gif by [javacafe](https://github.com/JavaCafe01) gif by me :) +### Playerctl Signals Implementation +![](https://user-images.githubusercontent.com/33443763/107377569-fa807900-6a9f-11eb-93c1-174c58eb7bf1.png) + +screenshot by [javacafe](https://github.com/JavaCafe01) + ## TODO - [ ] Add external sources management for the wallpaper module (URLs, RSS feeds, NASA picture of the day, ...) - [ ] Scratchpad module From 3ec15e21d7aea4f56136067b04b852ae0d274d29 Mon Sep 17 00:00:00 2001 From: gokul swaminathan <33443763+JavaCafe01@users.noreply.github.com> Date: Mon, 15 Feb 2021 17:45:34 -0800 Subject: [PATCH 10/10] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3049db4..fb16d93 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ bling.module.tabbed.iter() -- iterates through the currently focused bling.module.tabbed.pick_with_dmenu() -- picks a client with a dmenu application (defaults to rofi, other options can be set with a string parameter like "dmenu") ``` -##### 🎵 Playerctl Signals +##### 🎵 Playerctl This is a signal module in which you can connect to certain bling signals to grab playerctl info. Currently, this is what it supports: @@ -217,11 +217,13 @@ This is a signal module in which you can connect to certain bling signals to gra This module relies on `playerctl` and `curl`. If you have this module disabled, you won't need those programs. +To enable: `bling.signal.playerctl.enable()` + ###### Signals ```lua --- bling::playerctl::status -- first line is the signal --- playing (boolean) -- indented lines are function parameters +-- bling::playerctl::status -- first line is the signal +-- playing (boolean) -- indented lines are function parameters -- bling::playerctl::album -- album_art (string) -- bling::playerctl::title_artist