Skip to content

This simple script generates a customizable string, which can be easily modified, for two chosen audio players.

Notifications You must be signed in to change notification settings

skafiend/polybar-player

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

polybar-player

This simple script generates a customizable string, which can be easily modified, for two chosen audio players.

i3 bindings

# only one player at a time is supposed to be running

# run cmus and kill mpv
bindsym mod4+s exec pgrep -f '^cmus' || pkill -f mpv_audiobook; exec kitty --class cmus -o font_size=13 -e cmus
# run mpv and kill cmus
bindsym mod4+b exec pgrep -f '^mpv_audiobook' || pkill -f cmus; exec mpv --title="mpv_audiobook" --input-ipc-server=/tmp/mpvsocket --save-position-on-quit -no-video "$(cat ~/.config/mpv/curbook.tmp)"

~/polybar/config.ini

  • The script should work for any bar which supports custom scripts/modules
  [module/player]
  type = custom/script
  exec = ~/.config/polybar/player.sh
  # modify this line as necessary
  exec-if = pgrep -f mpv_audiobook || pgrep -x cmus
  tail = true
  interval = 1
  click-left = ~/.config/polybar/player.sh play
  click-right = ~/.config/polybar/player.sh exit
  scroll-up = ~/.config/polybar/player.sh up
  scroll-down = ~/.config/polybar/player.sh down

~/polybar/player.sh

  • Change these variables as you need. Keep in mind that POSITION and DURATION are measured in seconds
  • Other variables are pretty self-explanatory

cmus

cmus_preview

  NAME=$(cmus-remote -C status | grep "tag title" | cut -f 3- -d ' ')
  ARTIST=$(cmus-remote -C status | grep "tag artist" | cut -f 3- -d ' ')
  TITLE="$ARTIST - $NAME"
  POSITION=$(cmus-remote -C status | grep "position" | cut -f 2 -d ' ')
  DURATION=$(cmus-remote -C status | grep "duration" | cut -f 2 -d ' ')
  PLAY="cmus-remote --pause"
  EXIT="pkill -x cmus"
  UP="cmus-remote --volume +5%"
  DOWN="cmus-remote --volume -5%"

mpv

mpv_preview

  MPV_SOCKET='/tmp/mpvsocket'
  TITLE=$(echo '{ "command": ["get_property", "media-title"] }' | socat - $MPV_SOCKET | jq -r .data)
  POSITION=$(echo '{ "command": ["get_property_string", "time-pos"] }' | socat - $MPV_SOCKET  | jq -r .data | cut -d'.' -f 1)
  DURATION=$(echo '{ "command": ["get_property_string", "duration"] }' | socat - $MPV_SOCKET | jq -r .data | cut -d'.' -f 1)
  PLAY="echo 'cycle pause' | socat - $MPV_SOCKET" 
  EXIT="echo 'quit' | socat - $MPV_SOCKET" 
  UP="echo 'add volume +5' | socat - $MPV_SOCKET" 
  DOWN="echo 'add volume -5' | socat - $MPV_SOCKET" 

About

This simple script generates a customizable string, which can be easily modified, for two chosen audio players.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages