Skip to content

Latest commit

ย 

History

History
367 lines (279 loc) ยท 8.24 KB

File metadata and controls

367 lines (279 loc) ยท 8.24 KB

๐ŸŽต Replace MPD with Spotify in Archcraft Polybar

This guide shows how to replace the default MPD (Music Player Daemon) module in Archcraft's Polybar with Spotify integration using Spotifyd and Playerctl.

๐Ÿ“‹ Prerequisites

  • Archcraft Linux installation
  • Polybar configuration (default Archcraft theme)
  • Spotify account
  • KeepassXC (optional, for secure password management)

๐Ÿ”ง Installation

Step 1: Install Required Packages

yay -S spotifyd playerctl --noconfirm

Step 2: Backup Your Configuration

cd ~/.config/openbox/themes/default/polybar
cp modules.ini modules.ini.backup

๐Ÿ“ Configuration Changes

Step 3: Update modules.ini

Replace the MPD module with Spotify module:

Find this section (around line 416):

[module/mpd]
type = internal/mpd
# ... (entire MPD configuration)

Replace with:

[module/spotify]
type = custom/script
exec = ~/.config/openbox/themes/default/polybar/scripts/spotify-controls.sh
interval = 2
format = <label>
format-background = ${color.ALTBACKGROUND}
format-padding = 1
label = %output%
click-left = playerctl play-pause
click-right = playerctl next
click-middle = playerctl previous
scroll-up = playerctl next
scroll-down = playerctl previous

Find the song module (around line 432):

[module/song]
type = internal/mpd
# ... (entire song configuration)

Replace with:

[module/spotify-song]
type = custom/script
exec = ~/.config/openbox/themes/default/polybar/scripts/spotify-song.sh
interval = 2
format = <label>
format-font = 5
label = %output%
label-maxlen = 25
label-ellipsis = true

Step 4: Update config.ini

Find line 148:

modules-center = LD date RD dot-alt LD mpd RD sep song

Replace with:

modules-center = LD date RD dot-alt LD spotify RD sep spotify-song

๐Ÿ“œ Create Scripts

Step 5: Create Scripts Directory and Files

mkdir -p ~/.config/openbox/themes/default/polybar/scripts

Step 6: Create spotify-controls.sh

nano ~/.config/openbox/themes/default/polybar/scripts/spotify-controls.sh

Content:

#!/bin/bash

# Check if Spotify is running
if ! pgrep -x "spotify" > /dev/null; then
    echo "๓ฐš Spotify Offline"
    exit 0
fi

# Check if playerctl can find spotify
if ! playerctl --player=spotify status > /dev/null 2>&1; then
    echo "๓ฐš Spotify Not Playing"
    exit 0
fi

# Get current status
STATUS=$(playerctl --player=spotify status 2>/dev/null)

# Define icons
PLAY_ICON="๓ฐŠ"
PAUSE_ICON="๓ฐค"
PREV_ICON="๓ฐ’ฎ"
NEXT_ICON="๓ฐ’ญ"

# Output the controls based on status
case $STATUS in
    "Playing")
        echo "${PREV_ICON} ${PAUSE_ICON} ${NEXT_ICON}"
        ;;
    "Paused")
        echo "${PREV_ICON} ${PLAY_ICON} ${NEXT_ICON}"
        ;;
    *)
        echo "${PREV_ICON} ${PLAY_ICON} ${NEXT_ICON}"
        ;;
esac

Step 7: Create spotify-song.sh

nano ~/.config/openbox/themes/default/polybar/scripts/spotify-song.sh

Content:

#!/bin/bash

# Check if Spotify is running
if ! pgrep -x "spotify" > /dev/null; then
    echo "๓ฐš Offline"
    exit 0
fi

# Check if playerctl can find spotify
if ! playerctl --player=spotify status > /dev/null 2>&1; then
    echo "๓ฐš Not Playing"
    exit 0
fi

# Get current status
STATUS=$(playerctl --player=spotify status 2>/dev/null)

# If not playing, show paused or stopped status
if [ "$STATUS" != "Playing" ]; then
    echo "๓ฐš $STATUS"
    exit 0
fi

# Get song information
ARTIST=$(playerctl --player=spotify metadata artist 2>/dev/null)
TITLE=$(playerctl --player=spotify metadata title 2>/dev/null)

# If we have both artist and title, display them
if [ -n "$ARTIST" ] && [ -n "$TITLE" ]; then
    echo "๓ฐš $TITLE"
else
    echo "๓ฐš Unknown"
fi

Step 8: Make Scripts Executable

chmod +x ~/.config/openbox/themes/default/polybar/scripts/spotify-controls.sh
chmod +x ~/.config/openbox/themes/default/polybar/scripts/spotify-song.sh

๐Ÿ”’ Spotifyd Configuration (Optional)

Step 9: Create Spotifyd Config

mkdir -p ~/.config/spotifyd
nano ~/.config/spotifyd/spotifyd.conf

Content:

[global]
# Your Spotify username
username = "YOUR_SPOTIFY_USERNAME"

# Use KeepassXC to retrieve password securely (recommended)
password_cmd = "keepassxc-cli show -s -a password /path/to/your/database.kdbx Spotify"

# Or use plain text password (not recommended)
# password = "YOUR_SPOTIFY_PASSWORD"

# The audio backend to use
backend = "pulseaudio"

# The name that will be displayed under the connect tab
device_name = "spotifyd"

# The audio bitrate. 96, 160 or 320 kbit/s
bitrate = 320

# The directory used to cache audio data
cache_path = "/tmp/spotifyd"

# Volume on startup between 0 and 100
initial_volume = "90"

# If set to true, enables volume normalisation between songs
volume_normalisation = true

# The normalisation pregain that is applied for each song
normalisation_pregain = -10

# The displayed device type in Spotify clients
device_type = "computer"

Step 10: KeepassXC Integration (Recommended)

  1. Create Spotify entry in KeepassXC:

    • Open KeepassXC
    • Create new entry titled "Spotify"
    • Set username to your Spotify username
    • Set password to your Spotify password
  2. Update spotifyd.conf:

    • Replace YOUR_SPOTIFY_USERNAME with your actual username
    • Update /path/to/your/database.kdbx with your KeepassXC database path
  3. Test the integration:

    keepassxc-cli show -s -a password /path/to/your/database.kdbx Spotify

๐Ÿš€ Testing and Activation

Step 11: Test Scripts

# Test the control script
~/.config/openbox/themes/default/polybar/scripts/spotify-controls.sh

# Test the song script
~/.config/openbox/themes/default/polybar/scripts/spotify-song.sh

Step 12: Start Spotifyd (Optional)

# Enable and start spotifyd service
systemctl --user enable spotifyd
systemctl --user start spotifyd

Step 13: Restart Polybar

pkill polybar && ~/.config/openbox/themes/default/polybar/launch.sh

โœจ Features

  • ๐ŸŽฎ Interactive Controls:

    • Left-click: Play/Pause
    • Right-click: Next track
    • Middle-click: Previous track
    • Scroll up/down: Next/Previous track
  • ๐Ÿ“ฑ Status Display:

    • Shows current song title
    • Displays playback status (Playing/Paused)
    • Shows offline status when Spotify not running
  • ๐Ÿ”’ Secure Authentication:

    • KeepassXC integration for password management
    • No plain text passwords in config files
  • ๐ŸŽจ Visual Consistency:

    • Maintains original Archcraft theme styling
    • Uses Nerd Font icons for modern look

๐Ÿ”ง Troubleshooting

Common Issues:

  1. Scripts not working:

    # Check if scripts are executable
    ls -la ~/.config/openbox/themes/default/polybar/scripts/
    
    # Make executable if needed
    chmod +x ~/.config/openbox/themes/default/polybar/scripts/*.sh
  2. Spotify not detected:

    # Check if Spotify is running
    pgrep -x spotify
    
    # Check playerctl
    playerctl --player=spotify status
  3. Polybar not updating:

    # Restart polybar
    pkill polybar && ~/.config/openbox/themes/default/polybar/launch.sh
  4. Icons not showing:

    • Ensure you have Nerd Fonts installed
    • Check if your terminal supports Unicode

๐Ÿ“ File Structure

After completion, your file structure should look like:

~/.config/openbox/themes/default/polybar/
โ”œโ”€โ”€ config.ini                    # Modified
โ”œโ”€โ”€ modules.ini                   # Modified
โ”œโ”€โ”€ modules.ini.backup             # Backup
โ””โ”€โ”€ scripts/
    โ”œโ”€โ”€ spotify-controls.sh        # New
    โ”œโ”€โ”€ spotify-song.sh            # New
    โ””โ”€โ”€ bluetooth.sh               # Existing

~/.config/spotifyd/
โ””โ”€โ”€ spotifyd.conf                  # New (optional)

๐ŸŽฏ Result

You'll get a fully functional Spotify integration in your Archcraft Polybar that:

  • Shows current song title
  • Provides interactive playback controls
  • Handles offline states gracefully
  • Maintains the original theme aesthetics
  • Uses secure password management

Tested on: Archcraft with Openbox + Polybar Requirements: spotifyd, playerctl, KeepassXC (optional) Theme: Default Archcraft theme

Feel free to customize the scripts and configuration to match your preferences!