diff --git a/desktop/configs/polybar/.config/polybar/everforest.ini b/desktop/configs/polybar/.config/polybar/everforest.ini index 9db39af..12d0678 100644 --- a/desktop/configs/polybar/.config/polybar/everforest.ini +++ b/desktop/configs/polybar/.config/polybar/everforest.ini @@ -28,8 +28,9 @@ padding-right = 2 module-margin = 1 font-0 = CartographCF Nerd Font;2 +font-1 = SauceCodePro Nerd Font:size=16;3 -modules-left = xworkspaces +modules-left = xworkspaces spotify-title spotify-prev spotify-playpause spotify-next modules-right = tray xwindow pulseaudio modules-center = date @@ -98,4 +99,39 @@ label-foreground = ${colors.primary} screenchange-reload = true pseudo-transparency = true +[module/spotify-title] +type = custom/script +tail = true +format-prefix = " " +interval = 2 +exec = ~/.config/polybar/spotify.sh --scroll +click-left = kitty spt +click-right = playerctl --player=spotifyd metadata --format "{{ xesam:url }}" | xclip -selection clipboard + +[module/spotify-prev] +type = custom/text +content = "󰼨 " +content-padding = 0 +content-spacing = 0 +content-margin = 0 +click-left = ~/.config/polybar/spotify.sh --previous + + +[module/spotify-next] +type = custom/text +content = "󰼧 " +content-padding = 0 +content-spacing = 0 +content-margin = 0 +click-left = ~/.config/polybar/spotify.sh --next + + +[module/spotify-playpause] +type = custom/text +content = "󰐎 " +content-padding = 0 +content-spacing = 0 +content-margin = 0 +click-left = ~/.config/polybar/spotify.sh --play-pause + ; vim:ft=dosini diff --git a/desktop/configs/polybar/.config/polybar/spotify.sh b/desktop/configs/polybar/.config/polybar/spotify.sh new file mode 100755 index 0000000..2a29ab3 --- /dev/null +++ b/desktop/configs/polybar/.config/polybar/spotify.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +# Author : https://github.com/Crash-Zeus + +readonly command=$1 + +# Set the source audio player here. +# Examples: spotify, vlc, chrome, mpv and others. +# See more here: https://github.com/altdesktop/playerctl/#selecting-players-to-control +readonly PLAYER="spotify" + +# Delay (in seconds) for scrolling update; lower this for faster scrolling +readonly ZSCROLL_DELAY="0.3" + +# Time in seconds to wait in between running update checking commands +# Make also a "pause" in scroll but its just due by playerctl hang time to get informations +readonly ZSCROLL_UPDATE_DELAY="2" + +# if display text lenght > number the text is going to scroll +readonly ZSCROLL_LENGTH="20" + +function get_status() { + PLAYERCTL_STATUS=$(playerctl --player=$PLAYER status) + EXIT_CODE=$? + + if [ $EXIT_CODE -eq 0 ]; then + STATUS=$PLAYERCTL_STATUS + else + STATUS="No player is running" + fi +} + +function get_metadata() { + DATA=$(playerctl --player=$PLAYER metadata --format "$1") + echo $DATA +} + +function display_data() { + if [ "$STATUS" = "Stopped" ]; then + echo "No music is playing" + elif [ "$STATUS" = "Paused" ]; then + get_metadata "Paused" + elif [ "$STATUS" = "No player is running" ]; then + echo "$STATUS" + else + get_metadata "{{ title }} by {{ artist }}" + fi +} + +function display_status() { + if [ "$STATUS" = "Stopped" ]; then + echo "" + elif [ "$STATUS" = "Paused" ]; then + echo "" + elif [ "$STATUS" = "No player is running" ]; then + echo "" + else + echo "" + fi +} + +function exec_player_command() { + readonly CMD=$1 + playerctl --player=$PLAYER $CMD +} + +case $command in + + "--get-infos") + get_status + display_data + ;; + + "--get-status") + get_status + display_status + ;; + + "--scroll") + $0 --get-infos | zscroll -d $ZSCROLL_DELAY -U $ZSCROLL_UPDATE_DELAY -l $ZSCROLL_LENGTH -u true "`dirname $0`/spotify.sh --get-infos" + # -d update scroll delay + # -U launch update command delay + # -l length of scrolling text + # -u Update command + ;; + + "--play-pause") + get_status + if [ "$STATUS" = "Playing" ] ; then + exec_player_command pause + elif [ "$STATUS" = "Paused" ] ; then + exec_player_command play + elif [ "$STATUS" = "Stopped" ] ; then + exec_player_command play + fi + ;; + + "--next") + exec_player_command next + ;; + + "--previous") + exec_player_command previous + ;; + + *) + echo "No command specified." + echo "" + echo "Available commands :" + echo "--get-infos Get the song name if playing or return No playing song / Paused" + echo "--get-status Get the current status of player like Playing | Stopped | Paused but return icon" + echo "--scroll Display the song metadata with zscroll to scroll text" + echo "--play-pause Execute play or pause command (depend on playerctl status)" + echo "--next Execute next command" + echo "--previous Execute previous command" + exit 0 + ;; +esac