#!/bin/bash
######################################################
#                                                    #
#  This script gathers song info for radio display   #
#                                                    #
#  QMMP is used for this                             #
#  Volume method only for pipewire                   #
#  EQ are random numbers                             #
#                                                    #
######################################################

if [ "$1" = "" ]; then
  echo -e "\n\e[31m  Can only be started from within conky!\e[m\n"
  exit
fi

# Get playing status
pstat=$(playerctl -p qmmp status 2>/dev/null)
#echo "$pstat"

if [ "$pstat" = "" ]; then
  stimer="$(date '+%H:%M')"
  shuff1=0
  shuff2=0
elif [ "$pstat" = "Paused" ]; then
  stimer=" PAUSED"
  shuff1=0
  shuff2=0
elif [ "$pstat" = "Stopped" ]; then
  stimer="$(date '+%H:%M')"
  shuff1=0
  shuff2=0
else
  stimer=$(qmmp --status | head -n1 | awk '{print $3}' | awk -F'/' '{print $1}')
  shuff1=$(shuf -i 5-90 -n1)
  shuff2=$(shuf -i 5-90 -n1)
  sartist=$(qmmp --nowplaying '%p')
  stitle=$(qmmp --nowplaying '%t')
  # Use this if you want QMMP volume, comment volume line below
  #svol=$(qmmp --volume-status)
fi

# Use this if you want to display global (pipewire) volume, comment out the volume line above
svol=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk -F': ' '{print $2*100}')


echo "$stimer"           >  "./tempfiles/radio"
echo "${sartist:0:29}"   >> "./tempfiles/radio"
echo "${stitle:0:29}"    >> "./tempfiles/radio"
echo "$svol"             >> "./tempfiles/radio"
echo "$shuff1"           >> "./tempfiles/radio"
echo "$shuff2"           >> "./tempfiles/radio"

