Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ###################################################################
- #Script Name :music_bar
- #Description :polybar module for displaying music bar
- #Args :
- #Author :unixsilk
- #Email :
- ###################################################################
- function check_if_something_plays() {
- no_player=$(playerctl status 2>&1)
- if [ "${no_player}" == "No players found" ]; then
- exit # Exit the entire script without any further output
- fi
- }
- check_if_something_plays
- find_playing_player() {
- for each_player in $(playerctl -l); do
- status=$(playerctl -p "${each_player}" status)
- if [ "${status}" == "Playing" ]; then
- player="${each_player}"
- break
- else
- exit
- fi
- done
- }
- find_string_length() {
- grab_artist=$(playerctl -p "${player}" metadata artist)
- grab_title=$(playerctl -p "${player}" metadata title)
- combined_length=$((${#grab_artist} + ${#grab_title}))
- if [[ ${combined_length} -ge 55 ]]; then
- length="greater"
- else
- length="lesser"
- fi
- }
- function set_timestamps() {
- current_duration=$(playerctl -p "${player}" metadata --format '{{duration(position)}}')
- total_duration=$(playerctl -p "${player}" metadata --format '{{duration(mpris:length)}}')
- }
- function print_firefox_bar_moving() {
- title_string_length=${#grab_title}
- counter=0
- for ((each = 0; each <= title_string_length; each++)); do
- echo -e "${begin_white}""" "${grab_artist:0:15}" "•" "${end_color}""${grab_title:counter:55}"
- ((counter++))
- sleep 0.19
- done
- }
- function print_firefox_bar_static() {
- echo "${begin_white}""" "${grab_artist}" "•" "${end_color}""${grab_title}"
- }
- function print_other_player_bar_moving() {
- title_string_length=${#grab_title}
- counter=0
- for ((each = 0; each <= title_string_length; each++)); do
- set_timestamps
- echo -e "${begin_yellow}""${current_duration}""/""${total_duration}" "${begin_white}""" "${grab_artist:0:15}" "•" "${end_color}""${grab_title:counter:40}"
- ((counter++))
- sleep 0.19
- done
- }
- function print_other_player_bar_static() {
- echo -e "${begin_yellow}""${current_duration}""/""${total_duration}" "${end_color}""${begin_white}""" "${grab_artist:0:9}" "•" "${end_color}""${grab_title}"
- }
- function define_colors() {
- begin_yellow="%{F#F0C674}"
- begin_white="%{F#FFFFFF}"
- end_color="%{F-}"
- }
- #Find which player is playing currently and define that as variable $player
- find_playing_player
- #find the string length of title and artist
- find_string_length
- #invoke ANSI colors for Polybar
- define_colors
- combine_values="${player}-${length}"
- case "${combine_values}" in
- firefox*-greater)
- print_firefox_bar_moving
- ;;
- firefox*-lesser)
- print_firefox_bar_static
- ;;
- *-greater)
- set_timestamps
- print_other_player_bar_moving
- ;;
- *-lesser)
- set_timestamps
- print_other_player_bar_static
- ;;
- *)
- exit
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement