From b94881edb758c19b972b3dd7ac188ed7dcab1262 Mon Sep 17 00:00:00 2001 From: Sigmanificient Date: Fri, 8 Sep 2023 00:10:06 +0200 Subject: [PATCH] Add drawu's spotify widget Co-authored-by: drawbu --- config/default.nix | 1 + home/default.nix | 4 ++-- home/qtile/default.nix | 4 ++-- home/qtile/src/core/bar.py | 2 ++ home/qtile/src/widgets/__init__.py | 3 +++ home/qtile/src/widgets/spotify.py | 33 ++++++++++++++++++++++++++++++ 6 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 home/qtile/src/widgets/spotify.py diff --git a/config/default.nix b/config/default.nix index 065f4f8..09dac1c 100644 --- a/config/default.nix +++ b/config/default.nix @@ -186,6 +186,7 @@ networkmanagerapplet libsForQt5.ark libsForQt5.plasma-nm + playerctl git htop diff --git a/home/default.nix b/home/default.nix index f737722..cf027bc 100644 --- a/home/default.nix +++ b/home/default.nix @@ -1,16 +1,16 @@ -{ pkgs, conf, ecsls, qtile, ... }: +{ pkgs, conf, ecsls, ... }: { nixpkgs.config.allowUnfree = true; imports = [ (import ./nvim { inherit ecsls pkgs conf; }) - (import ./qtile { inherit qtile; }) ./btop ./neofetch ./picom ./dunst ./firefox + ./qtile ./thunar ./tmux ./zsh diff --git a/home/qtile/default.nix b/home/qtile/default.nix index c3f9f0d..402e338 100644 --- a/home/qtile/default.nix +++ b/home/qtile/default.nix @@ -1,7 +1,7 @@ -{ qtile, ... }: +{ ... }: { home.file.qtile_configs = { - source = "${qtile}/src"; + source = ./src; target = ".config/qtile"; recursive = true; }; diff --git a/home/qtile/src/core/bar.py b/home/qtile/src/core/bar.py index e9ec4db..db18b6c 100644 --- a/home/qtile/src/core/bar.py +++ b/home/qtile/src/core/bar.py @@ -12,6 +12,7 @@ Prompt, QuickExit, Separator, + SpotifyNowPlaying, TaskList, Wakatime, ) @@ -30,6 +31,7 @@ class Bar(bar.Bar): TaskList, Separator, Prompt, + SpotifyNowPlaying, Wakatime, Battery, Memory, diff --git a/home/qtile/src/widgets/__init__.py b/home/qtile/src/widgets/__init__.py index 2a51e8b..d47886e 100644 --- a/home/qtile/src/widgets/__init__.py +++ b/home/qtile/src/widgets/__init__.py @@ -10,6 +10,8 @@ Separator, TaskList, ) + +from .spotify import SpotifyNowPlaying from .wakatime import Wakatime __all__ = ( @@ -22,6 +24,7 @@ "Prompt", "QuickExit", "Separator", + "SpotifyNowPlaying", "TaskList", "Wakatime", ) diff --git a/home/qtile/src/widgets/spotify.py b/home/qtile/src/widgets/spotify.py new file mode 100644 index 0000000..e9bfb4e --- /dev/null +++ b/home/qtile/src/widgets/spotify.py @@ -0,0 +1,33 @@ +"""Wakatime widget inspired by drawbu.""" +from typing import List +import subprocess + +from libqtile import qtile +from libqtile.widget import base + + +COVER_PATH = "/tmp/spotify-now-playing.png" + + +def get_stdout(cmd: List[str]) -> str: + try: + sub = subprocess.Popen(cmd, stdout=subprocess.PIPE) + except FileNotFoundError: + return "" + return sub.communicate()[0].decode("utf-8").strip() + + +class SpotifyNowPlaying(base.InLoopPollText): + def __init__(self, **config): + super().__init__("", update_interval=5, qtile=qtile, **config) + self.name = "Spotify now playing" + + def poll(self) -> str: + is_playing = get_stdout(["playerctl", "--player=spotify", "status"]) + if is_playing != "Playing": + return "" + artist = get_stdout(["playerctl", "--player=spotify", "metadata", "artist"]) + title = get_stdout(["playerctl", "--player=spotify", "metadata", "title"]) + if artist == "" or title == "": + return "" + return f" {artist} - {title}"