made many of the if statements into a oneliner

These if statements would check before echoing some info if the user had used the --silent flag. If they did, it would not echo anything. These if statements have now been made into a oneliner because it is easier to read, and the file size is smaller.
This commit is contained in:
Siddharth Dushantha 2020-03-20 16:02:28 +01:00 committed by GitHub
parent 03e858fafd
commit 791f26fe54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 24 deletions

32
kunst
View File

@ -93,9 +93,7 @@ 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 [ ! $SILENT ] && 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
} }
@ -116,14 +114,10 @@ get_cover_online() {
IMG_URL=$(curl -s --ssl "$API_URL" | jq -r '.playlists.data[0] | .picture_big') IMG_URL=$(curl -s --ssl "$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 [ ! $SILENT ] && echo "error: cover not found online"
echo "error: cover not found online"
fi
ARTLESS=true ARTLESS=true
else else
if [ ! $SILENT ]; then [ ! $SILENT ] && echo "kunst: cover found online"
echo "kunst: cover found online"
fi
curl -o $COVER -s --ssl $IMG_URL curl -o $COVER -s --ssl $IMG_URL
ARTLESS=false ARTLESS=false
fi fi
@ -140,15 +134,11 @@ 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 [ ! $SILENT ] && 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 [ ! $SILENT ] && 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
@ -162,27 +152,21 @@ update_cover() {
STATUS=0 STATUS=0
ARTLESS=false ARTLESS=false
ffmpeg -loglevel error -i "$CANDIDATE" -vframes 1 $COVER -y ffmpeg -loglevel error -i "$CANDIDATE" -vframes 1 $COVER -y
if [ ! $SILENT ]; then [ ! $SILENT ] && echo "kunst: found cover $CANDIDATE"
echo "kunst: found cover $CANDIDATE"
fi
break break
fi 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 fi
if [ $STATUS -ne 0 ]; then if [ $STATUS -ne 0 ]; then
if [ ! $SILENT ]; then [ ! $SILENT ] && 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
ffmpeg -loglevel error -i $COVER -vframes 1 -vf scale=$WIDTH:-1 $COVER -y ffmpeg -loglevel error -i $COVER -vframes 1 -vf scale=$WIDTH:-1 $COVER -y
if [ ! $SILENT ]; then [ ! $SILENT ] && echo "kunst: resized album art to $SIZE"
echo "kunst: resized album art to $SIZE"
fi
fi fi
} }