added --silent flag

This commit is contained in:
Siddharth Dushantha 2019-03-05 19:47:54 +01:00
parent d9ce6d29a7
commit 95ebc9c393
1 changed files with 43 additions and 15 deletions

34
kunst
View File

@ -30,7 +30,7 @@ show_help() {
# Parse the arguments # Parse the arguments
options=$(getopt -o h --long size:,music_dir:,version,help -- "$@") options=$(getopt -o h --long size:,music_dir:,version,silent,help -- "$@")
eval set -- "$options" eval set -- "$options"
while true; do while true; do
@ -51,6 +51,9 @@ while true; do
echo $VERSION echo $VERSION
exit exit
;; ;;
--silent)
SILENT=true
;;
--) --)
shift shift
break break
@ -74,7 +77,9 @@ is_connected() {
if ping -q -c 1 -W 1 api.deezer.com >/dev/null; then if ping -q -c 1 -W 1 api.deezer.com >/dev/null; then
connected=true connected=true
else else
if [ ! $SILENT ];then
echo "kunst: unable to check online for the album art" echo "kunst: unable to check online for the album art"
fi
connected=false connected=false
fi fi
} }
@ -96,10 +101,14 @@ get_cover_online() {
IMG_URL=$(curl -s "$API_URL" | jq -r '.playlists.data[0] | .picture_big') IMG_URL=$(curl -s "$API_URL" | jq -r '.playlists.data[0] | .picture_big')
if [ "$IMG_URL" = '' ] || [ "$IMG_URL" = 'null' ];then if [ "$IMG_URL" = '' ] || [ "$IMG_URL" = 'null' ];then
if [ ! $SILENT ];then
echo "error: cover not found online" echo "error: cover not found online"
fi
ARTLESS=true ARTLESS=true
else else
if [ ! $SILENT ];then
echo "kunst: cover found online" echo "kunst: cover found online"
fi
curl -o $COVER -s $IMG_URL curl -o $COVER -s $IMG_URL
ARTLESS=false ARTLESS=false
fi fi
@ -117,11 +126,15 @@ update_cover() {
# Check if the file has a embbeded album art # Check if the file has a embbeded album art
if [ $STATUS -eq 0 ];then if [ $STATUS -eq 0 ];then
if [ ! $SILENT ];then
echo "kunst: extracted album art" echo "kunst: extracted album art"
fi
ARTLESS=false ARTLESS=false
else else
DIR="$MUSIC_DIR$(dirname "$(mpc current -f %file%)")" DIR="$MUSIC_DIR$(dirname "$(mpc current -f %file%)")"
if [ ! $SILENT ];then
echo "kunst: inspecting $DIR" echo "kunst: inspecting $DIR"
fi
# Check if there is an album cover/art in the folder. # Check if there is an album cover/art in the folder.
# Look at issue #9 for more details # Look at issue #9 for more details
@ -130,27 +143,38 @@ update_cover() {
STATUS=0 STATUS=0
ARTLESS=false ARTLESS=false
convert "$CANDIDATE" $COVER convert "$CANDIDATE" $COVER
if [ ! $SILENT ];then
echo "kunst: found cover.png" echo "kunst: found cover.png"
fi fi
fi
done done
fi fi
if [ $STATUS -ne 0 ];then if [ $STATUS -ne 0 ];then
if [ ! $SILENT ];then
echo "error: file does not have an album art" echo "error: file does not have an album art"
fi
get_cover_online get_cover_online
fi fi
# Resize the image to 250x250 # Resize the image to 250x250
if [ $ARTLESS == false ]; then if [ $ARTLESS == false ]; then
convert $COVER -resize $SIZE $COVER convert $COVER -resize $SIZE $COVER
if [ ! $SILENT ];then
echo "kunst: resized album art to $SIZE" echo "kunst: resized album art to $SIZE"
fi fi
fi
} }
pre_exit() { pre_exit() {
# Get the proccess ID of kunst and kill it # Get the proccess ID of kunst and kill it.
kill -9 $(cat /tmp/kunst.pid) # We are dumping the output of kill to /dev/null
# because if the user quits sxiv before they
# exit kunst, an error will be shown
# from kill and we dont want that
kill -9 $(cat /tmp/kunst.pid) &> /dev/null
} }
main() { main() {
@ -172,8 +196,10 @@ main() {
echo "$MUSIC_NOTE" | base64 --decode > $COVER echo "$MUSIC_NOTE" | base64 --decode > $COVER
fi fi
if [ ! $SILENT ];then
echo "kunst: swapped album art to $(mpc current)" echo "kunst: swapped album art to $(mpc current)"
echo "------------------------------------------" echo "------------------------------------------"
fi
if [ $FIRST_RUN == true ]; then if [ $FIRST_RUN == true ]; then
FIRST_RUN=false FIRST_RUN=false
@ -189,7 +215,9 @@ main() {
# Waiting for an event from mpd; play/pause/next/previous # Waiting for an event from mpd; play/pause/next/previous
# this is lets kunst use less CPU :) # this is lets kunst use less CPU :)
mpc idle &> /dev/null mpc idle &> /dev/null
if [ ! $SILENT ];then
echo "kunst: received event from mpd" echo "kunst: received event from mpd"
fi
done done
} }