Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add this to the pianobar config file.
- vi ~/.config/pianobar/config
- event_command = ~/.config/pianobar/eventcmd.sh
- nowplaying_short = "%t - %a - %l"
- nowplaying_prefix = "♪ Now Playing: "
- time_remaining_prefix = "⏳ Time Remaining: "
- create shell file:
- touch ~/.config/pianobar/eventcmd.sh
- edit file:
- vi ~/.config/pianobar/eventcmd.sh
- #!/bin/bash
- # Define the file path to store the now playing and time remaining information
- INFO_FILE=~/.config/pianobar/pianobar_info
- case "$1" in
- songstart)
- # Clear the previous information
- > "$INFO_FILE"
- ;;
- songlove)
- # Update the information when you "love" a song
- RATING="♥" # Heart symbol for liked songs
- ;;
- songunlove)
- # Update the information when you "unlove" a song
- RATING="♡" # Heart outline for unliked songs
- ;;
- songprogress)
- # Extract the progress information (elapsed and duration)
- ELAPSED="$2"
- DURATION="$3"
- # Calculate the progress percentage
- PROGRESS=$(echo "scale=2; ($ELAPSED / $DURATION) * 100" | bc)
- # Create a progress bar (adjust the number of '=' characters as needed)
- PROGRESS_BAR="["
- for ((i = 0; i < 50; i++)); do
- if ((i < PROGRESS / 2)); then
- PROGRESS_BAR+="="
- else
- PROGRESS_BAR+=" "
- fi
- done
- PROGRESS_BAR+="] $PROGRESS%"
- # Save the progress information to the file
- echo "$PROGRESS_BAR" >> "$INFO_FILE"
- ;;
- stationfetchplaylist)
- # Handle the stationfetchplaylist event (when fetching a station)
- FETCHING_MESSAGE="Fetching station playlist..."
- # Save the fetching message to the file
- echo "$FETCHING_MESSAGE" >> "$INFO_FILE"
- ;;
- songfinish)
- # Handle the songfinish event (song has finished playing)
- # Clear the information to prepare for the next song
- > "$INFO_FILE"
- ;;
- *)
- # Save the song and time information to the file
- echo "$1" >> "$INFO_FILE"
- ;;
- esac
- # Parse and display the information in the terminal
- INFO=$(tail -n 2 "$INFO_FILE")
- # Extract the song, artist, album, and time remaining information
- SONG=$(echo "$INFO" | tail -n 1)
- TIME_REMAINING=$(echo "$INFO" | head -n 1)
- ARTIST=$(echo "$SONG" | awk -F ' - ' '{print $2}')
- ALBUM=$(echo "$SONG" | awk -F ' - ' '{print $3}')
- # Display the information with color codes and custom formatting
- if [ -n "$SONG" ]; then
- if [ "$SONG" != "$FETCHING_MESSAGE" ]; then
- echo -e "\n♪ Now Playing: $SONG"
- echo -e "⏳ Time Remaining: $TIME_REMAINING"
- echo -e "★ Rating: $RATING"
- else
- echo -e "\n♪ Now Playing: $FETCHING_MESSAGE"
- fi
- fi
- # Send a desktop notification with the song information
- if [ "$SONG" != "$FETCHING_MESSAGE" ]; then
- notify-send "Now Playing" "$SONG\nArtist: $ARTIST\nAlbum: $ALBUM" -i audio-x-generic
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement