1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #!/bin/dash
-
- getpos() {
- #
- # Get track position
- #
- local h
- local m
- local s
- s=$(qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.PositionGet)
- s=$((s/1000))
- h=$((s/3600))
- s=$((s%3600))
- m=$((s/60))
- s=$((s%60))
- case $h in
- 0) printf '%d:%02d' $m $s ;;
- *) printf '%d:%02d:%02d' $h $m $s ;;
- esac
- }
-
- mktext() {
- #
- # Compose info text from DBus
- #
- local artist
- local year
- local album
- local tracknumber
- local title
- local sigil
- local sigilcolor
- local value
- local key
- local color_attr
- local cache
- cache=$(mktemp -t cstatus.GetMetadata.XXXXXXXX)
- qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.GetMetadata >"$cache"
- case $(qdbus org.mpris.clementine /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus) in
- Stopped) sigil=""; sigilcolor= ;;
- Playing) sigil=""; sigilcolor=green ;;
- Paused) sigil=""; sigilcolor=gray;;
- *) sigil=""; sigilcolor=red ;;
- esac
- test -n "$sigilcolor" && color_attr=" color='$sigilcolor'"
- while read -r line; do
- key=${line%%:*}
- value=${line#$key: }
- case $key in
- artist) artist=$value ;;
- year) year=$value ;;
- album) album=$value ;;
- tracknumber) tracknumber=$value ;;
- title) title=$value ;;
- esac
- done <"$cache"
- printf "%s [%d %s]: %02d %s (%s) <span%s>%s</span>" \
- "$artist" "$year" "$album" "$tracknumber" "$title" \
- "$(getpos)" \
- "$color_attr" "$sigil"
- rm "$cache"
- }
-
- main() {
- local head=true
- echo '{"version":1}'
- echo "["
- while true; do
- $head || echo -n ","
- head=false
- echo -n '[{'
- echo -n '"markup":"pango",'
- echo -n '"full_text":"'"$(mktext)"'"'
- echo -n '}]'
- echo
- sleep 1
- done
- }
-
- main
|