Merge pull request #34 from Seirdy/chore/formatting

Chore: format using `shfmt`
This commit is contained in:
Siddharth Dushantha 2020-03-06 16:33:13 +01:00 committed by GitHub
commit 03e858fafd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 98 additions and 102 deletions

View File

@ -3,10 +3,12 @@ root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
insert_final_newline = false
charset = utf-8
indent_style = tab
indent_size = 4
binary_next_line = true
switch_case_indent = true
# Tab indentation (no size specified)
[*.md]

54
kunst
View File

@ -6,7 +6,6 @@
#
# Dependencies: sxiv or imv, bash, ffmpeg, mpc, jq, mpd
VERSION=1.2.5
COVER=/tmp/kunst.jpg
MUSIC_DIR=~/Music/
@ -14,7 +13,6 @@ WIDTH=250
SIZE="${WIDTH}x${WIDTH}"
POSITION="+0+0"
show_help() {
echo "usage: kunst [-h] [--size "px"] [--position "+x+y"] [--viewer <imv|x11>] [--music_dir "path/to/dir"] [--silent] [--version]"
echo " "
@ -33,7 +31,6 @@ show_help() {
echo " --version show the version of kunst you are using"
}
# Parse the arguments
options=$(getopt -o h --long position:,size:,music_dir:,version,silent,help -- "$@")
eval set -- "$options"
@ -41,22 +38,22 @@ eval set -- "$options"
while true; do
case "$1" in
--size)
shift;
shift
SIZE=$1
;;
--position)
shift;
shift
POSITION=$1
;;
--viewer)
shift;
shift
VIEWER=$1
;;
--music_dir)
shift;
shift
MUSIC_DIR=$1
;;
-h|--help)
-h | --help)
show_help
exit
;;
@ -85,11 +82,10 @@ fi
# This is a base64 endcoded image which will be used if
# the file does not have an emmbeded album art.
# The image is an image of a music note
read -d '' MUSIC_NOTE << EOF
read -d '' MUSIC_NOTE <<EOF
iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAJESURBVGhD7Zg/axRRFMVXAtpYphEVREKClnHfJI0MmReSfAC3tRejhaBgo70fwN7aD2BvEU0gfztbu5AqMxNjoVnvG87KZXy7z5m5dxLI/OCw8Pade+7M3n3Dbq+jo6OjY8RwMJhKk+hhlph3eRJ9w/LF5jCOr1PTj6jpD7mNjkjDkbDl4vFjpX87teZJlkSfSD9501zYfv5QJ1fyZHGexuJtZs12ZqMzX8NlwX4+nK3NXMutWaOm39Nd/u5rMCSUao80fjBNwY+p8Y+krNxQVaGsLsfWzFLYS2r4M30Rf5WbaCJE6OILlhIidPEFSwkRuviCpYQIXXzB1WX26bR6ky4v3OPriNCFB1YRHa079Pr6eKk/h1IFfA+WdOGBk+QeXtT0Ft3pV6e2fxf2f+AeLOnCA8tC0xv09H1xGi/cgWUi3I8lXXigEzX8u3gmWPP8JI5uYdt/w2thSRceSM0/zVfnb+CtWvB6WNJFOlC6XhDpQOl6QaQDpesFkQ6UrhdEOlC6XpA6gcPB/avumKXnxCadXHkha766tTr1GlE18CRZvEmN7nHfOMGiS5XA4mdmYg64Z5Jg06VKYHlEQoKtOVIz6zx8f0iwNUNyZt2F+3zjBFt9pGe22gWYFLb6lEckJNjGUmWEssR8ga0+0jNL9Z75fD7Rp7UOW32kZxb/1u37vFyUu+sODtjqozGzxaFADfprFM3vuD3Y3gytmf17LJPHXbgTNb5BWhe58yNan1lpWp9ZDVqdWS1am9mOjo7LRq/3B1ESKyYUVquzAAAAAElFTkSuQmCC
EOF
is_connected() {
# Check if internet is connected. We are using api.deezer.com to test
# if the internet is connected because if api.deezer.com is down or
@ -97,19 +93,18 @@ is_connected() {
if ping -q -c 1 -W 1 api.deezer.com >/dev/null; then
connected=true
else
if [ ! $SILENT ];then
if [ ! $SILENT ]; then
echo "kunst: unable to check online for the album art"
fi
connected=false
fi
}
get_cover_online() {
# Check if connected to internet
is_connected
if [ $connected == false ];then
if [ $connected == false ]; then
ARTLESS=true
return
fi
@ -120,13 +115,13 @@ get_cover_online() {
# Extract the albumcover from the json returned
IMG_URL=$(curl -s --ssl "$API_URL" | jq -r '.playlists.data[0] | .picture_big')
if [ "$IMG_URL" = '' ] || [ "$IMG_URL" = 'null' ];then
if [ ! $SILENT ];then
if [ "$IMG_URL" = '' ] || [ "$IMG_URL" = 'null' ]; then
if [ ! $SILENT ]; then
echo "error: cover not found online"
fi
ARTLESS=true
else
if [ ! $SILENT ];then
if [ ! $SILENT ]; then
echo "kunst: cover found online"
fi
curl -o $COVER -s --ssl $IMG_URL
@ -135,7 +130,6 @@ get_cover_online() {
}
update_cover() {
# Extract the album art from the mp3 file and dont show the messsy
# output of ffmpeg
@ -145,14 +139,14 @@ update_cover() {
STATUS=$?
# Check if the file has a embbeded album art
if [ $STATUS -eq 0 ];then
if [ ! $SILENT ];then
if [ $STATUS -eq 0 ]; then
if [ ! $SILENT ]; then
echo "kunst: extracted album art"
fi
ARTLESS=false
else
DIR="$MUSIC_DIR/$(dirname "$(mpc current -f %file%)")"
if [ ! $SILENT ];then
if [ ! $SILENT ]; then
echo "kunst: inspecting $DIR"
fi
@ -168,16 +162,16 @@ update_cover() {
STATUS=0
ARTLESS=false
ffmpeg -loglevel error -i "$CANDIDATE" -vframes 1 $COVER -y
if [ ! $SILENT ];then
if [ ! $SILENT ]; then
echo "kunst: found cover $CANDIDATE"
fi
break
fi
done <<< "$candidates" # use here string so loop changes vars in main process
done <<<"$candidates" # use here string so loop changes vars in main process
fi
if [ $STATUS -ne 0 ];then
if [ ! $SILENT ];then
if [ $STATUS -ne 0 ]; then
if [ ! $SILENT ]; then
echo "error: file does not have an album art"
fi
get_cover_online
@ -186,7 +180,7 @@ update_cover() {
# Resize the image to 250x250
if [ $ARTLESS == false ]; then
ffmpeg -loglevel error -i $COVER -vframes 1 -vf scale=$WIDTH:-1 $COVER -y
if [ ! $SILENT ];then
if [ ! $SILENT ]; then
echo "kunst: resized album art to $SIZE"
fi
fi
@ -199,7 +193,7 @@ pre_exit() {
# because if the user quits the image viewer
# before they exit kunst, an error will be shown
# from kill and we dont want that
kill -9 $(cat /tmp/kunst.pid) &> /dev/null
kill -9 $(cat /tmp/kunst.pid) &>/dev/null
}
@ -216,17 +210,17 @@ main() {
update_cover
if [ $ARTLESS == true ];then
if [ $ARTLESS == true ]; then
# Dhange the path to COVER because the music note
# image is a png not jpg
COVER=/tmp/kunst.png
# Decode the base64 encoded image and save it
# to /tmp/kunst.png
echo "$MUSIC_NOTE" | base64 --decode > $COVER
echo "$MUSIC_NOTE" | base64 --decode >$COVER
fi
if [ ! $SILENT ];then
if [ ! $SILENT ]; then
echo "kunst: swapped album art to $(mpc current)"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
fi
@ -253,7 +247,7 @@ main() {
while true; do
mpc idle player &>/dev/null && (mpc status | grep "\[playing\]" &>/dev/null) && break
done
if [ ! $SILENT ];then
if [ ! $SILENT ]; then
echo "kunst: received event from mpd"
fi
if [ "$VIEWER" = 'imv' ]; then