Skip to content

Commit

Permalink
Add drawu's spotify widget
Browse files Browse the repository at this point in the history
Co-authored-by: drawbu <[email protected]>
  • Loading branch information
Sigmanificient and drawbu committed Sep 7, 2023
1 parent f17c3a4 commit b94881e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
networkmanagerapplet
libsForQt5.ark
libsForQt5.plasma-nm
playerctl

git
htop
Expand Down
4 changes: 2 additions & 2 deletions home/default.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions home/qtile/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ qtile, ... }:
{ ... }:
{
home.file.qtile_configs = {
source = "${qtile}/src";
source = ./src;
target = ".config/qtile";
recursive = true;
};
Expand Down
2 changes: 2 additions & 0 deletions home/qtile/src/core/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Prompt,
QuickExit,
Separator,
SpotifyNowPlaying,
TaskList,
Wakatime,
)
Expand All @@ -30,6 +31,7 @@ class Bar(bar.Bar):
TaskList,
Separator,
Prompt,
SpotifyNowPlaying,
Wakatime,
Battery,
Memory,
Expand Down
3 changes: 3 additions & 0 deletions home/qtile/src/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
Separator,
TaskList,
)

from .spotify import SpotifyNowPlaying
from .wakatime import Wakatime

__all__ = (
Expand All @@ -22,6 +24,7 @@
"Prompt",
"QuickExit",
"Separator",
"SpotifyNowPlaying",
"TaskList",
"Wakatime",
)
33 changes: 33 additions & 0 deletions home/qtile/src/widgets/spotify.py
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit b94881e

Please sign in to comment.