Alexays / Waybar

Highly customizable Wayland bar for Sway and Wlroots based compositors. :v: :tada:
MIT License
6.28k stars 689 forks source link

Spotify Script Example #34

Closed SethBarberee closed 6 years ago

SethBarberee commented 6 years ago

Hi,

I was wondering if you could add your script for Spotify somewhere on the project? Whether it be on wiki or included in the files with config/css, that is up to your discretion. I just wanted a sample to look at how custom modules worked in Waybar. Thanks!

Alexays commented 6 years ago

It's just a script using playerctl and written on the output :) You can also use polybar scripts there are plenty on github

#!/bin/sh
player_status=$(playerctl status 2> /dev/null)
if [ "$player_status" = "Playing" ]; then
    echo "$(playerctl metadata artist) - $(playerctl metadata title)"
elif [ "$player_status" = "Paused" ]; then
    echo " $(playerctl metadata artist) - $(playerctl metadata title)"
fi
Alexays commented 6 years ago

Script added in the resources folder ;) e9478f548ee97e6c30f9e34b645f9774cbf662ca

SethBarberee commented 6 years ago

Thanks a lot!

forbade commented 1 year ago

For some reason playerctl was not recognizing my spotify, so I instead I did playerctl -p spotify I also wasn't able to edit the module in my css file heres what I did:

script:

!/bin/bash

while true do player_status=$(playerctl -p spotify status 2> /dev/null)

if [ "$player_status" = "Playing" ]; then artist=$(playerctl -p spotify metadata artist) title=$(playerctl -p spotify metadata title) echo '{"text": "'"$artist - $title"'", "class": "custom-spotify", "alt": "Spotify"}' elif [ "$player_status" = "Paused" ]; then artist=$(playerctl -p spotify metadata artist) title=$(playerctl -p spotify metadata title) echo '{"text": "'"Paused"'", "class": "custom-spotify", "alt": "Spotify (Paused)"}' fi sleep 3 done

config:

"custom/spotify": { "format": "{} ", "exec": "~/.config/waybar/scripts/mediaplayer.sh", "return-type": "json", "on-click": "playerctl -p spotify play-pause", "on-scroll-up": "playerctl -p spotify next", "on-scroll-down": "playerctl -p spotify previous", "exec-if": "pgrep spotfiy" }

style:

.custom-spotify { padding: 2px 12px; margin: 0 1px; background-color: black; }

seanPruss commented 2 months ago

@forbade your script didn't handle song names with an ampersand in them so here is the proper script:

#!/bin/bash

while true; do
    player_status=$(playerctl -p spotify status 2>/dev/null)

    if [ "$player_status" = "Playing" ]; then
        artist=$(playerctl -p spotify metadata artist)
        title=$(playerctl -p spotify metadata title)
        # Escape special characters for JSON
        artist=$(echo "$artist" | sed 's/&/&/g')
        title=$(echo "$title" | sed 's/&/&/g')
        echo '{"text": "'"$artist - $title"'", "class": "custom-spotify", "alt": "Spotify"}'
    elif [ "$player_status" = "Paused" ]; then
        echo '{"text": "Paused", "class": "custom-spotify", "alt": "Spotify (Paused)"}'
    fi
    sleep 3
done
1-minute-to-midnight commented 1 month ago

Could you guys tell me, how I could migrate this to waybar:

[module/spotify-play-pause]
type = custom/ipc
hook-0 = echo "  "
hook-1 = echo "  "
format = %{T13} <label>
initial = 1
click-left = playerctl -p spotify play-pause; playerctl -p audacious play-pause
format-underline = #5656F5

I don't know how I should convert the hooks into waybar config. Hook-0 echos pause and Hook-1 echos play.