all repos — dotfiles @ 0df91d9c0197c7acd8db85015f1b36cb12d4173c

my *nix dotfiles

polybar,bin/np.sh: Add now playing script

Signed-off-by: Anirudh Oppiliappan <x@icyphox.sh>
Anirudh Oppiliappan x@icyphox.sh
Sun, 15 Sep 2019 10:36:44 +0530
commit

0df91d9c0197c7acd8db85015f1b36cb12d4173c

parent

e127293d9be6179083d08c51c0578d72cf51b6af

2 files changed, 30 insertions(+), 1 deletions(-)

jump to
A bin/np.sh

@@ -0,0 +1,24 @@

+#!/usr/bin/env bash +# now playing +# requires the last.fm API key + +source ~/.lastfm # `export API_KEY="<key>"` +fg="$(xres color0)" +light="$(xres color8)" + +USER="icyphox" +URL="http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks" +URL+="&user=$USER&api_key=$API_KEY&format=json&limit=1&nowplaying=true" +NOTPLAYING="not playing" +RES=$(curl -s $URL) +NOWPLAYING=$(jq '.recenttracks.track[0]."@attr".nowplaying' <<< "$RES" | tr -d '"') + + +if [[ "$NOWPLAYING" = "true" ]] +then + TRACK=$(jq '.recenttracks.track[0].name' <<< "$RES" | tr -d '"') + ARTIST=$(jq '.recenttracks.track[0].artist."#text"' <<< "$RES" | tr -d '"') + echo -ne "%{F$light}$TRACK %{F$fg}by $ARTIST" +else + echo -ne " " +fi
M config/polybar/barconfig/polybar/bar

@@ -31,7 +31,7 @@ foreground = ${colors.fg}

font-0 = SF Mono:size=12:weight=semibold;3 -modules-left = date time volume battery +modules-left = date time volume battery music modules-center = modules-right = ewmh

@@ -100,6 +100,11 @@ [module/battery]

type = custom/script interval = 1.0 exec = ~/bin/bat.sh + +[module/music] +type = custom/script +interval = 1.0 +exec = ~/bin/np.sh [module/spotipy] type = custom/script