Created
July 9, 2021 11:32
-
-
Save turbulentie/af24e43488522dba57ddea9dee7e1d3b to your computer and use it in GitHub Desktop.
script for conky to show MOC playback info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
state=$(mocp -Q %state) | |
mocp_status() { | |
if [[ $state == "PLAY" ]]; then | |
state="Playing" | |
echo $state | |
elif [[ $state == "STOP" ]]; then | |
state="Stopped" | |
echo $state | |
elif [[ $state == "PAUSE" ]]; then | |
state="Paused" | |
echo $state | |
else | |
if [[ $state != "" ]]; then | |
echo $state | |
else | |
state="N/A" | |
echo $state | |
exit 0 | |
fi | |
fi | |
} | |
mocp_bar() { | |
mocts=$(mocp -Q %ts) | |
moccs=$(mocp -Q %cs) | |
mocpercent=$(echo "scale=2; $moccs/$mocts*100.0" | bc) | |
echo $mocpercent | |
} | |
mocp_artist() { | |
mocartist=$(mocp -Q %artist) | |
echo $mocartist | |
} | |
mocp_album() { | |
mocalbum=$(mocp -Q %album) | |
echo $mocalbum | |
} | |
mocp_title() { | |
moctitle=$(mocp -Q %song) | |
echo $moctitle | |
} | |
mocp_lenght() { | |
moclenght=$(mocp -Q %tt) | |
echo $moclenght | |
} | |
mocp_playposition() { | |
mocplayposition=$(mocp -Q %ct) | |
echo $mocplayposition | |
} | |
mocp_bitrate() { | |
mocbitrate=$(mocp -Q %b) | |
echo $mocbitrate | |
} | |
mocp_samplerate() { | |
mocsamplerate=$(mocp -i | awk /'^Rate:/ {print $2}') | |
if [[ $mocsamplerate == "44kHz" ]]; then | |
echo "44100" | |
elif [[ $mocsamplerate == "48kHz" ]]; then | |
echo "48000" | |
elif [[ $mocsamplerate == "88kHz" ]]; then | |
echo "88200" | |
elif [[ $mocsamplerate == "96kHz" ]]; then | |
echo "96000" | |
elif [[ $mocsamplerate == "176kHz" ]]; then | |
echo "176400" | |
elif [[ $mocsamplerate == "192kHz" ]]; then | |
echo "192000" | |
else | |
echo $mocsamplerate | |
fi | |
} | |
mocp_codecinfo() { | |
mocp_file=$(mocp -Q %file) | |
codec=$(mediainfo --Inform="Audio;%Format%" "$mocp_file") | |
echo $codec | |
} | |
mocp_bitdepth() { | |
mocp_file=$(mocp -Q %file) | |
bits=$(mediainfo --Inform="Audio;%BitDepth%" "$mocp_file") | |
echo $bits | |
} | |
mocp_channels() { | |
mocp_file=$(mocp -Q %file) | |
channels=$(mediainfo --Inform="Audio;%Channels%" "$mocp_file") | |
echo $channels | |
} | |
Init() { | |
for args | |
do | |
case "$args" in | |
status) mocp_status;; | |
bar) mocp_bar;; | |
artist) mocp_artist;; | |
album) mocp_album;; | |
title) mocp_title;; | |
lenght) mocp_lenght;; | |
position) mocp_playposition;; | |
bitrate) mocp_bitrate;; | |
samplerate) mocp_samplerate;; | |
codec) mocp_codecinfo;; | |
bitdepth) mocp_bitdepth;; | |
channels) mocp_channels;; | |
*) | |
initname=$(basename "$0") | |
echo "Usage: $initname (status|bar|artist|album|title|lenght|position|bitrate|samplerate)" | |
exit 1 | |
esac | |
done | |
} | |
if [[ $state != "STOP" ]]; then | |
Init "$1" | |
else | |
case "$1" in | |
status) mocp_status;; | |
esac | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MOC Playback info for conky
Can output:
Conky integration example: