get_artUrl() { artUrl=$(playerctl -p $1 metadata | grep artUrl | awk '{$1=$2=""; print $0}') regex='(https?|ftp)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' if [[ $artUrl =~ $regex ]] then filename=/tmp/spotify-mpris/$(basename $artUrl) if [ ! -f $filename ] then curl -sSL $artUrl --create-dirs -o $filename fi echo $filename else echo $artUrl fi } read -d'\n' -ra PLAYERS <<<"$(playerctl -l 2>/dev/null)" declare -a PAUSED for player in "${PLAYERS[@]}"; do [ "$player" = "playerctld" ] && continue; p_status=$(playerctl -p "$player" status 2>/dev/null) # if we have one playing, we'll use it and EXIT if [ "$p_status" = "Playing" ]; then get_artUrl $player exit 0; fi [ "$p_status" = "Paused" ] && PAUSED+=("$player") done # if we have a paused, show it otherwise assume there are no players or have all stopped if [ -n "${PAUSED[0]}" ]; then get_artUrl ${PAUSED[0]} echo $(playerctl -p metadata | grep artUrl | awk '{$1=$2=""; print $0}') fi