Advertisement
nitestryker

Better Pianobar Config. ((fixed)

Jan 3rd, 2024 (edited)
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.01 KB | None | 0 0
  1. add this to the pianobar config file.
  2. vi ~/.config/pianobar/config
  3.  
  4. event_command = ~/.config/pianobar/eventcmd.sh
  5. nowplaying_short = "%t - %a - %l"
  6. nowplaying_prefix = "♪ Now Playing: "
  7. time_remaining_prefix = "⏳ Time Remaining: "
  8.  
  9. create shell file:
  10. touch ~/.config/pianobar/eventcmd.sh
  11. edit file:
  12. vi ~/.config/pianobar/eventcmd.sh
  13.  
  14. #!/bin/bash
  15.  
  16. # Define the file path to store the now playing and time remaining information
  17. INFO_FILE=~/.config/pianobar/pianobar_info
  18.  
  19. case "$1" in
  20.     songstart)
  21.         # Clear the previous information
  22.         > "$INFO_FILE"
  23.         ;;
  24.     songlove)
  25.         # Update the information when you "love" a song
  26.         RATING="♥"  # Heart symbol for liked songs
  27.         ;;
  28.     songunlove)
  29.         # Update the information when you "unlove" a song
  30.         RATING="♡"  # Heart outline for unliked songs
  31.         ;;
  32.     songprogress)
  33.         # Extract the progress information (elapsed and duration)
  34.         ELAPSED="$2"
  35.         DURATION="$3"
  36.        
  37.         # Calculate the progress percentage
  38.         PROGRESS=$(echo "scale=2; ($ELAPSED / $DURATION) * 100" | bc)
  39.        
  40.         # Create a progress bar (adjust the number of '=' characters as needed)
  41.         PROGRESS_BAR="["
  42.         for ((i = 0; i < 50; i++)); do
  43.             if ((i < PROGRESS / 2)); then
  44.                 PROGRESS_BAR+="="
  45.             else
  46.                 PROGRESS_BAR+=" "
  47.             fi
  48.         done
  49.         PROGRESS_BAR+="] $PROGRESS%"
  50.  
  51.         # Save the progress information to the file
  52.         echo "$PROGRESS_BAR" >> "$INFO_FILE"
  53.         ;;
  54.     stationfetchplaylist)
  55.         # Handle the stationfetchplaylist event (when fetching a station)
  56.         FETCHING_MESSAGE="Fetching station playlist..."
  57.        
  58.         # Save the fetching message to the file
  59.         echo "$FETCHING_MESSAGE" >> "$INFO_FILE"
  60.         ;;
  61.     songfinish)
  62.         # Handle the songfinish event (song has finished playing)
  63.         # Clear the information to prepare for the next song
  64.         > "$INFO_FILE"
  65.         ;;
  66.     *)
  67.         # Save the song and time information to the file
  68.         echo "$1" >> "$INFO_FILE"
  69.         ;;
  70. esac
  71.  
  72. # Parse and display the information in the terminal
  73. INFO=$(tail -n 2 "$INFO_FILE")
  74.  
  75. # Extract the song, artist, album, and time remaining information
  76. SONG=$(echo "$INFO" | tail -n 1)
  77. TIME_REMAINING=$(echo "$INFO" | head -n 1)
  78. ARTIST=$(echo "$SONG" | awk -F ' - ' '{print $2}')
  79. ALBUM=$(echo "$SONG" | awk -F ' - ' '{print $3}')
  80.  
  81. # Display the information with color codes and custom formatting
  82. if [ -n "$SONG" ]; then
  83.     if [ "$SONG" != "$FETCHING_MESSAGE" ]; then
  84.         echo -e "\n♪ Now Playing: $SONG"
  85.         echo -e "⏳ Time Remaining: $TIME_REMAINING"
  86.         echo -e "★ Rating: $RATING"
  87.     else
  88.         echo -e "\n♪ Now Playing: $FETCHING_MESSAGE"
  89.     fi
  90. fi
  91.  
  92. # Send a desktop notification with the song information
  93. if [ "$SONG" != "$FETCHING_MESSAGE" ]; then
  94.     notify-send "Now Playing" "$SONG\nArtist: $ARTIST\nAlbum: $ALBUM" -i audio-x-generic
  95. fi
Tags: pianobar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement