Retabularize script

The script had an ugly mix of spaces and tabs. Now it's only using
spaces.
This commit is contained in:
M.B. Christiansen 2022-10-10 10:40:25 +02:00
parent c5d51654c0
commit 83ad18b0eb
1 changed files with 76 additions and 76 deletions

152
kunst
View File

@ -54,13 +54,13 @@ while true; do
MUSIC_DIR=$1 MUSIC_DIR=$1
;; ;;
-h|--help) -h|--help)
show_help show_help
exit exit
;;
--version)
echo $VERSION
exit
;; ;;
--version)
echo $VERSION
exit
;;
--force-online) --force-online)
ONLINE_ALBUM_ART=true ONLINE_ALBUM_ART=true
;; ;;
@ -84,46 +84,46 @@ EOF
is_connected() { is_connected() {
# Check if internet is connected. We are using api.deezer.com to test # 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 # if the internet is connected because if api.deezer.com is down or
# the internet is not connected this script will work as expected # the internet is not connected this script will work as expected
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
[ ! "$SILENT" ] && echo "kunst: unable to check online for the album art" [ ! "$SILENT" ] && echo "kunst: unable to check online for the album art"
connected=false connected=false
fi fi
} }
get_cover_online() { get_cover_online() {
# Check if connected to internet # Check if connected to internet
is_connected is_connected
if [ "$connected" == false ];then if [ "$connected" == false ];then
ARTLESS=true ARTLESS=true
return return
fi fi
# If the current playing song ends with .mp3 or something similar, remove # If the current playing song ends with .mp3 or something similar, remove
# it before searching for the album art because including the file extension # it before searching for the album art because including the file extension
# reduces the chance of good results in the search query # reduces the chance of good results in the search query
QUERY=$(mpc current | sed 's/\.[^.]*$//' | iconv -t ascii//TRANSLIT -f utf8) QUERY=$(mpc current | sed 's/\.[^.]*$//' | iconv -t ascii//TRANSLIT -f utf8)
# Try to get the album cover online from api.deezer.com # Try to get the album cover online from api.deezer.com
API_URL="https://api.deezer.com/search/autocomplete?q=$QUERY" && API_URL=${API_URL//' '/'%20'} API_URL="https://api.deezer.com/search/autocomplete?q=$QUERY" && API_URL=${API_URL//' '/'%20'}
echo $API_URL echo $API_URL
# Extract the albumcover from the json returned # Extract the albumcover from the json returned
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
[ ! "$SILENT" ] && echo "error: cover not found online" [ ! "$SILENT" ] && echo "error: cover not found online"
ARTLESS=true ARTLESS=true
else else
[ ! "$SILENT" ] && echo "kunst: cover found online" [ ! "$SILENT" ] && echo "kunst: cover found online"
curl -o "$COVER" -s "$IMG_URL" curl -o "$COVER" -s "$IMG_URL"
ARTLESS=false ARTLESS=false
fi fi
} }
@ -132,27 +132,27 @@ find_album_art(){
# regardless if the curent song has an embedded album art or not # regardless if the curent song has an embedded album art or not
if [ "$ONLINE_ALBUM_ART" == true ];then if [ "$ONLINE_ALBUM_ART" == true ];then
[ ! "$SILENT" ] && echo "kunst: getting cover from internet" [ ! "$SILENT" ] && echo "kunst: getting cover from internet"
get_cover_online get_cover_online
return return
fi fi
# Extract the album art from the mp3 file and dont show the messsy # Extract the album art from the mp3 file and dont show the messsy
# output of ffmpeg # output of ffmpeg
ffmpeg -i "$MUSIC_DIR$(mpc current -f %file%)" "$COVER" -y &> /dev/null ffmpeg -i "$MUSIC_DIR$(mpc current -f %file%)" "$COVER" -y &> /dev/null
# Get the status of the previous command # Get the status of the previous command
STATUS=$? STATUS=$?
# 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
[ ! "$SILENT" ] && echo "kunst: extracted album art" [ ! "$SILENT" ] && echo "kunst: extracted album art"
ARTLESS=false ARTLESS=false
else else
DIR="$MUSIC_DIR$(dirname "$(mpc current -f %file%)")" DIR="$MUSIC_DIR$(dirname "$(mpc current -f %file%)")"
[ ! "$SILENT" ] && echo "kunst: inspecting $DIR" [ ! "$SILENT" ] && echo "kunst: inspecting $DIR"
# 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
for CANDIDATE in "$DIR/cover."{png,jpg}; do for CANDIDATE in "$DIR/cover."{png,jpg}; do
if [ -f "$CANDIDATE" ]; then if [ -f "$CANDIDATE" ]; then
STATUS=0 STATUS=0
@ -163,30 +163,30 @@ find_album_art(){
done done
fi fi
if [ "$STATUS" -ne 0 ];then if [ "$STATUS" -ne 0 ];then
[ ! "$SILENT" ] && echo "error: file does not have an album art" [ ! "$SILENT" ] && echo "error: file does not have an album art"
get_cover_online get_cover_online
fi fi
} }
update_cover() { update_cover() {
find_album_art find_album_art
if [ "$ARTLESS" == false ]; then if [ "$ARTLESS" == false ]; then
convert "$COVER" -resize "$SIZE" "$COVER" &> /dev/null convert "$COVER" -resize "$SIZE" "$COVER" &> /dev/null
[ ! "$SILENT" ] && echo "kunst: resized album art to $SIZE" [ ! "$SILENT" ] && echo "kunst: resized album art to $SIZE"
fi fi
} }
pre_exit() { pre_exit() {
# Get the proccess ID of kunst and kill it. # Get the proccess ID of kunst and kill it.
# We are dumping the output of kill to /dev/null # We are dumping the output of kill to /dev/null
# because if the user quits sxiv before they # because if the user quits sxiv before they
# exit kunst, an error will be shown # exit kunst, an error will be shown
# from kill and we dont want that # from kill and we dont want that
kill -9 "$(cat /tmp/kunst.pid)" &>/dev/null kill -9 "$(cat /tmp/kunst.pid)" &>/dev/null
} }
@ -204,45 +204,45 @@ main() {
[ "$KUNST_SIZE" != "" ] && SIZE="$KUNST_SIZE" [ "$KUNST_SIZE" != "" ] && SIZE="$KUNST_SIZE"
[ "$KUNST_POSITION" != "" ] && POSITION="$KUNST_POSITION" [ "$KUNST_POSITION" != "" ] && POSITION="$KUNST_POSITION"
# Flag to run some commands only once in the loop # Flag to run some commands only once in the loop
FIRST_RUN=true FIRST_RUN=true
while true; do while true; do
update_cover update_cover
if [ "$ARTLESS" == true ];then if [ "$ARTLESS" == true ];then
# Dhange the path to COVER because the music note # Dhange the path to COVER because the music note
# image is a png not jpg # image is a png not jpg
COVER=/tmp/kunst.png COVER=/tmp/kunst.png
# Decode the base64 encoded image and save it # Decode the base64 encoded image and save it
# to /tmp/kunst.png # to /tmp/kunst.png
echo "$MUSIC_NOTE" | base64 --decode > "$COVER" echo "$MUSIC_NOTE" | base64 --decode > "$COVER"
fi fi
if [ ! "$SILENT" ];then if [ ! "$SILENT" ];then
echo "kunst: swapped album art to $(mpc current)" echo "kunst: swapped album art to $(mpc current)"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
fi fi
if [ "$FIRST_RUN" == true ]; then if [ "$FIRST_RUN" == true ]; then
FIRST_RUN=false FIRST_RUN=false
# Display the album art using sxiv # Display the album art using sxiv
sxiv -g "$SIZE$POSITION" -b "$COVER" -N "Kunst" & sxiv -g "$SIZE$POSITION" -b "$COVER" -N "Kunst" &
# Save the process ID so that we can kill # Save the process ID so that we can kill
# sxiv when the user exits the script # sxiv when the user exits the script
echo $! >/tmp/kunst.pid echo $! >/tmp/kunst.pid
fi fi
# 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 :)
while true; do while true; do
mpc idle player &>/dev/null && (mpc status | grep "\[playing\]" &>/dev/null) && break mpc idle player &>/dev/null && (mpc status | grep "\[playing\]" &>/dev/null) && break
done done
[ ! "$SILENT" ] && echo "kunst: received event from mpd" [ ! "$SILENT" ] && echo "kunst: received event from mpd"
done done
} }
# Disable CTRL-Z because if we allowed this key press, # Disable CTRL-Z because if we allowed this key press,