-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f17c3a4
commit fbf2246
Showing
6 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,6 +186,7 @@ | |
networkmanagerapplet | ||
libsForQt5.ark | ||
libsForQt5.plasma-nm | ||
playerctl | ||
|
||
git | ||
htop | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"""Wakatime widget inspired by drawbu.""" | ||
from typing import List, Optional | ||
import subprocess | ||
import urllib.request | ||
|
||
from libqtile import qtile, widget | ||
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 SpotifyCover(widget.Image): | ||
def __init__(self, **config): | ||
super().__init__(filename=COVER_PATH, **config) | ||
self.name = "Spotify cover" | ||
self.filename: Optional[str] = None | ||
self.__last_cover: Optional[str] = None | ||
|
||
def update_cover(self) -> None: | ||
if self.filename is None: | ||
self.img = None | ||
self.bar.draw() | ||
return | ||
|
||
cover_url = get_stdout(["playerctl", "--player=spotify", "metadata", "mpris:artUrl"]) | ||
if cover_url == "": | ||
self.__cover.remove_cover() | ||
return | ||
if cover_url == self.__last_cover: | ||
return | ||
self.__last_cover = cover_url | ||
urllib.request.urlretrieve(cover_url, self.filename) | ||
|
||
old_length = self.calculate_length() | ||
self._update_image() | ||
|
||
if self.calculate_length() == old_length: | ||
self.draw() | ||
else: | ||
self.bar.draw() | ||
|
||
def remove_cover(self) -> None: | ||
self.filename = None | ||
self.__last_cover = None | ||
self.update_cover() | ||
|
||
|
||
class SpotifyNowPlaying(base.InLoopPollText): | ||
def __init__(self, cover: SpotifyCover, **config): | ||
super().__init__("", update_interval=5, qtile=qtile, **config) | ||
self.name = "Spotify now playing" | ||
self.__cover = cover | ||
|
||
def poll(self) -> str: | ||
is_playing = get_stdout(["playerctl", "--player=spotify", "status"]) | ||
if is_playing != "Playing": | ||
self.__cover.remove_cover() | ||
return "" | ||
artist = get_stdout(["playerctl", "--player=spotify", "metadata", "artist"]) | ||
title = get_stdout(["playerctl", "--player=spotify", "metadata", "title"]) | ||
if artist == "" or title == "": | ||
self.__cover.remove_cover() | ||
return "" | ||
if self.__cover.filename is None: | ||
self.__cover.filename = COVER_PATH | ||
self.__cover.update_cover() | ||
return f" {artist} - {title}" |