Add waybar

This commit is contained in:
Hydroxycarbamide 2024-05-14 19:47:03 +02:00
parent e0c17f71e2
commit 1ff2d77058
19 changed files with 1043 additions and 0 deletions

View file

@ -0,0 +1,10 @@
#!/bin/bash
album_art=$(playerctl metadata mpris:artUrl)
if [[ -z $album_art ]]
then
# spotify is dead, we should die to.
exit
fi
curl -s "${album_art}" --output "/tmp/cover.jpeg"
echo "/tmp/cover.jpeg"

View file

@ -0,0 +1,41 @@
#!/bin/bash
write_art() {
album_art=$(playerctl -p $1 metadata mpris:artUrl)
status=$?
if [[ -z $album_art || $status -eq 0 ]]
then
album_art=$(playerctl metadata mpris:artUrl)
if [[ -z $album_art ]]
then
exit
fi
fi
curl -s "${album_art}" --output "/tmp/cover.jpeg"
echo "/tmp/cover.jpeg"
}
read -d'\n' -ra PLAYERS <<<"$(playerctl -l 2>/dev/null)"
declare -a PAUSED
for player in "${PLAYERS[@]}"; do
[ "$player" = "playerctld" ] && continue;
p_status=$(playerctl -p "$player" status 2>/dev/null)
# if we have one playing, we'll use it and EXIT
if [ "$p_status" = "Playing" ]; then
write_art "$player"
exit 0;
fi
[ "$p_status" = "Paused" ] && PAUSED+=("$player")
done
if [ -n "${PAUSED[0]}" ]; then
write_art "${PAUSED[0]}"
fi

View file

@ -0,0 +1,76 @@
#!/bin/bash
# The name of polybar bar which houses the main spotify module and the control modules.
PARENT_BAR="${1:-music}"
PARENT_BAR_PID=$(pgrep -a "polybar" | grep "$PARENT_BAR" | cut -d" " -f1)
urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
send_hook() {
[ -z "$1" ] && echo "send_hook: missing arg" && exit 1
polybar-msg -p "$PARENT_BAR_PID" hook mpris-play-pause "$1" 1>/dev/null 2>&1
}
extract_meta() {
grep "$1\W" <<< "$meta" | awk '{$1=$2=""; print $0}' | sed 's/^ *//; s/; */;/g' | paste -s -d/ -
}
# if "icon" given, determine icon. otherwise, print metadata
get_info() {
if [ -z "$1" ]; then
echo "Usage: get_info PLAYER [icon]"
exit 1
fi
meta=$(playerctl -p "$1" metadata)
# get title
title=$(extract_meta title)
# if no title, try url e.g. vlc
if [ -z "$title" ]; then
title=$(extract_meta url)
title=$(urldecode "${title##*/}")
fi
# if not "icon", display information and return
artist=$(extract_meta artist)
[ -z "$artist" ] && artist=$(extract_meta albumArtist)
if [ -n "$artist" ]; then
album=$(extract_meta album)
[ -n "$album" ] && echo -n " 󰫔 $album"
echo -n " 󰠃 $artist"
fi
echo "$title"
return 0
}
# manually go through players
read -d'\n' -ra PLAYERS <<<"$(playerctl -l 2>/dev/null)"
declare -a PAUSED
for player in "${PLAYERS[@]}"; do
[ "$player" = "playerctld" ] && continue;
p_status=$(playerctl -p "$player" status 2>/dev/null)
# if we have one playing, we'll use it and EXIT
if [ "$p_status" = "Playing" ]; then
send_hook 1
get_info "$player" "$2"
exit 0;
fi
[ "$p_status" = "Paused" ] && PAUSED+=("$player")
done
# if we have a paused, show it otherwise assume there are no players or have all stopped
if [ -n "${PAUSED[0]}" ]; then
send_hook 2
get_info "${PAUSED[0]}" "$2"
else
[ "$2" = icon ] && echo "none" || echo " 󰒲 no players "
fi

View file

@ -0,0 +1,18 @@
#!/bin/bash
# manually go through players
read -d'\n' -ra PLAYERS <<<"$(playerctl -l 2>/dev/null)"
declare -a PAUSED
for player in "${PLAYERS[@]}"; do
[ "$player" = "playerctld" ] && continue;
p_status=$(playerctl -p "$player" status 2>/dev/null)
# if we have one playing, we'll use it and EXIT
if [ "$p_status" = "Playing" ]; then
echo "Playing"
exit 0;
fi
done
echo "Paused"

View file

@ -0,0 +1,15 @@
#!/bin/bash
cmd="${0%/*}/get_status.sh $1"
zscroll -l 30 \
--scroll-padding "$(printf ' %.0s' {1..8})" \
-d 0.5 \
-M "${0%/*}/get_status_paused.sh $1" \
-m "Playing" "--scroll 1" \
-m "Paused" "--scroll 0" \
-m "Stopped" "--scroll 0" \
-U 5 -u true "$cmd" &
wait