jan146 / playerctl-scroller

Scroll the currently playing song via playerctl. It can also be used with polybar.
2 stars 1 forks source link

playerctl-scroller

Scroll the currently playing song via playerctl. It is mainly meant to be used with polybar.
Backend is based on Cscroll.
Frontend is based on polybar-spotify.
All credit for the idea goes to the original creator.

Installation

Before installing, make sure you have installed all the required dependencies (listed below).

git clone https://github.com/jan146/playerctl-scroller.git
cd playerctl-scroller
sudo make
make config

Configuration

After installation, add the following modules to the config in ~/.config/polybar/config:


[module/spotify]
type = custom/script
tail = true
format = <label>
exec = $HOME/.config/polybar/scripts/scroller.sh

[module/spotify-play-pause]
type = custom/ipc
hook-0 = echo "  "
hook-1 = echo "  "
initial = 1
click-left = playerctl -p spotify play-pause

[module/spotify-prev]
type = custom/text
content = " "
click-left = playerctl -p spotify previous

[module/spotify-next]
type = custom/text
content = ""
click-left = playerctl -p spotify next

In order to change the play-pause button on-click, ipc has to be enabled.
This can be done by adding enable-ipc=true to where your bar is defined.
Additionally, you will also want to add these modules to the bar. The end result should look something like this:

[bar/example]
enable-ipc=true
modules-left = spotify spotify-prev spotify-play-pause spotify-next
; other bar settings

Now you can configure the scroller.sh file, located in ~/.config/polybar/scripts. There, you can adjust numerous parameters, such as the delay between scrolling a single character (i. e. scrolling speed), update frequency, player, text format, length of the text ...

Switch player

If you want to switch to, say vlc as your preffered media player, you have to do the following:
In the polybar modules (~/.config/polybar/config), change the click-left options. For instance:

click-left = playerctl -p spotify play-pause
click-left = playerctl -p spotify previous
click-left = playerctl -p spotify next

to

click-left = playerctl -p vlc play-pause
click-left = playerctl -p vlc previous
click-left = playerctl -p vlc next

Also, you have to edit the scroller.sh file:

PLAYER="spotify"

to

PLAYER="vlc"

You can view all the available (currently active) players by running playerctl -l.

Default player

There is also the playerctl option, which will use the player that was last active.
This can be enabled by omitting the -p parameter:

click-left = playerctl play-pause
click-left = playerctl previous
click-left = playerctl next

and editing the scroller.sh file:

PLAYER="playerctl"

Why

All credit for the idea goes to the original creator.

This solution is a bit more optimized, since it communicates directly with the dbus interface, instead of using playerctl. Along with other performance optimizations, this solution yields much lower cpu usage, without making any significant sacrifices, which was my original goal.

Dependencies