diff --git a/.editorconfig b/.editorconfig index a5c9586..a5b5bc4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,12 +3,14 @@ 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] indent_style = space -indent_size = 2 \ No newline at end of file +indent_size = 2 diff --git a/kunst b/kunst index 355d8ec..d6e1d67 100755 --- a/kunst +++ b/kunst @@ -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 ] [--music_dir "path/to/dir"] [--silent] [--version]" echo " " @@ -26,53 +24,52 @@ show_help() { echo "optional arguments:" echo " -h, --help show this help message and exit" echo " --size what size to display the album art in" - echo " --position the position where the album art should be displayed" + echo " --position the position where the album art should be displayed" echo " --viewer whether to use imv or sxiv" echo " --music_dir the music directory which MPD plays from" echo " --silent dont show the output" 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" while true; do - case "$1" in - --size) - shift; - SIZE=$1 - ;; - --position) - shift; - POSITION=$1 - ;; - --viewer) - shift; - VIEWER=$1 - ;; - --music_dir) - shift; - MUSIC_DIR=$1 - ;; - -h|--help) - show_help - exit - ;; - --version) - echo $VERSION + case "$1" in + --size) + shift + SIZE=$1 + ;; + --position) + shift + POSITION=$1 + ;; + --viewer) + shift + VIEWER=$1 + ;; + --music_dir) + shift + MUSIC_DIR=$1 + ;; + -h | --help) + show_help exit ;; - --silent) - SILENT=true - ;; - --) - shift - break - ;; - esac - shift + --version) + echo $VERSION + exit + ;; + --silent) + SILENT=true + ;; + --) + shift + break + ;; + esac + shift done # If available, use imv instead of sxiv on Wayland, @@ -85,31 +82,29 @@ 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 </dev/null; then connected=true else - if [ ! $SILENT ];then - echo "kunst: unable to check online for the album art" - fi + 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,22 +115,21 @@ 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 - echo "error: cover not found online" - fi + if [ "$IMG_URL" = '' ] || [ "$IMG_URL" = 'null' ]; then + if [ ! $SILENT ]; then + echo "error: cover not found online" + fi ARTLESS=true else - if [ ! $SILENT ];then - echo "kunst: cover found online" - fi + if [ ! $SILENT ]; then + echo "kunst: cover found online" + fi curl -o $COVER -s --ssl $IMG_URL ARTLESS=false fi } - update_cover() { # Extract the album art from the mp3 file and dont show the messsy # output of ffmpeg @@ -145,16 +139,16 @@ update_cover() { STATUS=$? # Check if the file has a embbeded album art - if [ $STATUS -eq 0 ];then - if [ ! $SILENT ];then - echo "kunst: extracted album art" - fi + 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 - echo "kunst: inspecting $DIR" - fi + DIR="$MUSIC_DIR/$(dirname "$(mpc current -f %file%)")" + if [ ! $SILENT ]; then + echo "kunst: inspecting $DIR" + fi # Check if there is an album cover/art in the folder. # Look at issue #9 for more details @@ -163,51 +157,51 @@ update_cover() { find "$DIR" -type f \ | grep -iE '/(([0-9| |-]*)?)(album|cover|\.?folder|front).*\.(gif|jpeg|jpg|png)$' ) - while read -r CANDIDATE; do - if [ -f "$CANDIDATE" ]; then - STATUS=0 - ARTLESS=false - ffmpeg -loglevel error -i "$CANDIDATE" -vframes 1 $COVER -y - if [ ! $SILENT ];then - echo "kunst: found cover $CANDIDATE" - fi - break - fi - done <<< "$candidates" # use here string so loop changes vars in main process - fi + while read -r CANDIDATE; do + if [ -f "$CANDIDATE" ]; then + STATUS=0 + ARTLESS=false + ffmpeg -loglevel error -i "$CANDIDATE" -vframes 1 $COVER -y + if [ ! $SILENT ]; then + echo "kunst: found cover $CANDIDATE" + fi + break + fi + done <<<"$candidates" # use here string so loop changes vars in main process + fi - if [ $STATUS -ne 0 ];then - if [ ! $SILENT ];then - echo "error: file does not have an album art" - fi + if [ $STATUS -ne 0 ]; then + if [ ! $SILENT ]; then + echo "error: file does not have an album art" + fi get_cover_online fi # 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 - echo "kunst: resized album art to $SIZE" - fi + if [ ! $SILENT ]; then + echo "kunst: resized album art to $SIZE" + fi fi } pre_exit() { # Get the proccess ID of kunst and kill it. - # We are dumping the output of kill to /dev/null - # 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 - + # We are dumping the output of kill to /dev/null + # 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 + } main() { - - [[ $KUNST_MUSIC_DIR != "" ]] && MUSIC_DIR=$KUNST_MUSIC_DIR - [[ $KUNST_SIZE != "" ]] && SIZE=$KUNST_SIZE - [[ $KUNST_POSITION != "" ]] && POSITION=$KUNST_POSITION + + [[ $KUNST_MUSIC_DIR != "" ]] && MUSIC_DIR=$KUNST_MUSIC_DIR + [[ $KUNST_SIZE != "" ]] && SIZE=$KUNST_SIZE + [[ $KUNST_POSITION != "" ]] && POSITION=$KUNST_POSITION # Flag to run some commands only once in the loop FIRST_RUN=true @@ -216,20 +210,20 @@ 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 + echo "kunst: swapped album art to $(mpc current)" + printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - fi - - if [ ! $SILENT ];then - echo "kunst: swapped album art to $(mpc current)" - printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - - fi if [ $FIRST_RUN == true ]; then FIRST_RUN=false @@ -251,11 +245,11 @@ main() { # Waiting for an event from mpd; play/pause/next/previous # this is lets kunst use less CPU :) 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 - if [ ! $SILENT ];then - echo "kunst: received event from mpd" - fi + if [ ! $SILENT ]; then + echo "kunst: received event from mpd" + fi if [ "$VIEWER" = 'imv' ]; then imv-msg "$(cat /tmp/kunst.pid)" close all imv-msg "$(cat /tmp/kunst.pid)" open "$COVER"