82 lines
1.9 KiB
Text
82 lines
1.9 KiB
Text
|
#!/bin/bash
|
||
|
|
||
|
if ! systemctl --user is-active mpd &>/dev/null
|
||
|
then
|
||
|
origstatus='off'
|
||
|
else
|
||
|
origstatus="$(mpc status | sed -n '2p' | grep -Eo '^\[.*\]' | tr -d '[]')"
|
||
|
[[ -z "$origstatus" ]] && origstatus='stop'
|
||
|
fi
|
||
|
|
||
|
|
||
|
case $BLOCK_BUTTON in
|
||
|
1) mpc -q prev ;;
|
||
|
2) mpc -q toggle ;;
|
||
|
3) mpc -q next ;;
|
||
|
4) mpc -q seek +5 ;;
|
||
|
5) mpc -q seek -5 ;;
|
||
|
esac
|
||
|
|
||
|
status="<span foreground=\"#6699CC\">"
|
||
|
case $origstatus in
|
||
|
stop ) status="<span foreground=\"#F2777A\">" ;;
|
||
|
paused ) status="<span foreground=\"#FFCC66\">" ;;
|
||
|
playing ) status="<span foreground=\"#99CC99\">" ;;
|
||
|
off ) status="<span foreground=\"#515151\">" ;;
|
||
|
esac
|
||
|
|
||
|
if [[ "$origstatus" != "stop" ]] && [[ "$origstatus" != "off" ]]
|
||
|
then
|
||
|
if [[ ! -f /dev/shm/mpd ]]
|
||
|
then
|
||
|
mpc -f '[[%artist%, ]%title%|[%file%]' current > /dev/shm/mpd
|
||
|
fi
|
||
|
|
||
|
song=$(</dev/shm/mpd)
|
||
|
|
||
|
song="${song//&/and}"
|
||
|
|
||
|
scroll="$(</dev/shm/mpd-scroll)"
|
||
|
|
||
|
if [[ -z "${scroll// /}" ]]
|
||
|
then
|
||
|
cp /dev/shm/mpd /dev/shm/mpd-scroll
|
||
|
else
|
||
|
song="$(</dev/shm/mpd-scroll)"
|
||
|
echo "${song:1} " > /dev/shm/mpd-scroll
|
||
|
fi
|
||
|
|
||
|
alltime="$(mpc status | column -t -o ' ' | sed -n '2p' | cut -f3)"
|
||
|
elapsed_time="$(dateconv -f "%0H:%0M" "${alltime%/*}" || echo "--:--")"
|
||
|
total_time="$(dateconv -f "%0H:%0M" "${alltime#*/}" || echo "--:--")"
|
||
|
left_time="$(datediff -f "%0H:%0M" "$elapsed_time" "$total_time" || echo "--:--")"
|
||
|
|
||
|
time="[$elapsed_time $left_time $total_time]"
|
||
|
shorttime="$elapsed_time $left_time"
|
||
|
|
||
|
if [[ "$time" = "[ ]" ]] || [[ -z "$time" ]]
|
||
|
then
|
||
|
time="[--:-- --:-- --:--]"
|
||
|
fi
|
||
|
|
||
|
if [[ -z "$shorttime" ]] || [[ "$shorttime" = " " ]]
|
||
|
then
|
||
|
shorttime="--:-- --:--"
|
||
|
fi
|
||
|
|
||
|
if [[ "${#shorttime}" -eq 6 ]]
|
||
|
then
|
||
|
shorttime="${shorttime}--:--"
|
||
|
fi
|
||
|
|
||
|
echo "${song:0:25} $status$time</span>"
|
||
|
echo "${song:0:10} $status$shorttime</span>"
|
||
|
else
|
||
|
[[ -f /dev/shm/mpd ]] && rm /dev/shm/mpd
|
||
|
[[ -f /dev/shm/mpd-scroll ]] && rm /dev/shm/mpd-scroll
|
||
|
echo "$status[--:-- --:-- --:--]</span>"
|
||
|
echo "$status--:-- --:--</span>"
|
||
|
fi
|
||
|
|
||
|
|