From 3f7f93822e089bdf4b96352fffbbf8f0b5572401 Mon Sep 17 00:00:00 2001 From: elenapan Date: Thu, 19 Sep 2019 09:22:38 +0300 Subject: [PATCH] Added spotify daemon and example spotify widget Former-commit-id: c0cb2979b23234123f9f927a9cc55d12bfe85d79 Former-commit-id: b49f80e039a49894ca2cd98679150fba4c091404 Former-commit-id: 785592b3bc72bebb2dad98c6f12ecaa514eaa206 Former-commit-id: 795b8b77c387b84fb24509fa97733a4b578df2d9 --- config/awesome/evil/init.lua | 1 + config/awesome/evil/spotify.lua | 32 +++++++++++++++++++++++ config/awesome/noodle/spotify.lua | 42 +++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 config/awesome/evil/spotify.lua create mode 100644 config/awesome/noodle/spotify.lua diff --git a/config/awesome/evil/init.lua b/config/awesome/evil/init.lua index f6f9518..2950b5e 100644 --- a/config/awesome/evil/init.lua +++ b/config/awesome/evil/init.lua @@ -8,5 +8,6 @@ require("evil.ram") require("evil.weather") require("evil.mpd") require("evil.brightness") +require("evil.spotify") -- return evil diff --git a/config/awesome/evil/spotify.lua b/config/awesome/evil/spotify.lua new file mode 100644 index 0000000..9bc5883 --- /dev/null +++ b/config/awesome/evil/spotify.lua @@ -0,0 +1,32 @@ +-- Provides: +-- evil::spotify +-- artist (string) +-- song (string) +-- status (string) [playing | paused | stopped] +local awful = require("awful") + +local function emit_info(playerctl_output) + local artist = playerctl_output:match('artist_start(.*)title_start') + local title = playerctl_output:match('title_start(.*)status_start') + -- Use the lower case of status + local status = playerctl_output:match('status_start(.*)'):lower() + status = string.gsub(status, '^%s*(.-)%s*$', '%1') + + awesome.emit_signal("evil::spotify", artist, title, status) +end + +-- Sleeps until spotify changes state (pause/play/next/prev) +local spotify_script = [[ + sh -c ' + playerctl metadata --format 'artist_start{{artist}}title_start{{title}}status_start{{status}}' --follow + ']] + +-- Kill old playerctl process +awful.spawn.easy_async_with_shell("ps x | grep \"playerctl metadata\" | grep -v grep | awk '{print $1}' | xargs kill", function () + -- Emit song info with each line printed + awful.spawn.with_line_callback(spotify_script, { + stdout = function(line) + emit_info(line) + end + }) +end) diff --git a/config/awesome/noodle/spotify.lua b/config/awesome/noodle/spotify.lua new file mode 100644 index 0000000..4ff4d96 --- /dev/null +++ b/config/awesome/noodle/spotify.lua @@ -0,0 +1,42 @@ +local wibox = require("wibox") +local awful = require("awful") +local naughty = require("naughty") + +-- Declare widgets +local spotify_artist = wibox.widget.textbox() +local spotify_title = wibox.widget.textbox() + +-- Main widget that includes all others +local spotify_widget = wibox.widget { + -- Title widget + { + align = "center", + text = "---", + font = "sans 14", + widget = spotify_title + }, + -- Artist widget + { + align = "center", + text = "---", + font = "sans 10", + widget = spotify_artist + }, + spacing = 2, + layout = wibox.layout.fixed.vertical +} + +-- Subcribe to spotify updates +awesome.connect_signal("evil::spotify", function(artist, title, status) + -- Do whatever you want with artist, title, status + -- ... + spotify_artist.text = artist + spotify_title.text = title + + -- Example notification (might not be needed if spotify already sends one) + if status == "playing" then + naughty.notify({ title = "Spotify | Now Playing", message = title.." by "..artist }) + end +end) + +return spotify_widget