From f5980a987f1294704bfa911b0de5d018cf78d02d Mon Sep 17 00:00:00 2001 From: deepjyoti30 Date: Tue, 19 Feb 2019 01:27:53 +0530 Subject: [PATCH 1/8] Added function to get albumcover online --- kunst | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/kunst b/kunst index c1556c7..25ce1fa 100755 --- a/kunst +++ b/kunst @@ -17,6 +17,25 @@ iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 EOF +get_cover_online() { + # Try to get the album cover online from api.deezer.com + API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && ur=${ur//' '/'%20'} + + # extract the albumcover from the json returned + IMG_URL=$(curl -s "$API_URL" | jq -r '.playlists.data[0] | .picture_big') + + if [ $IMG_URL = '' ] || [ $IMG_URL = 'null' ];then + echo "error: Cover not found online" + ARTLESS=true + else + echo "kunst: Cover found online" + wget -o $COVER $IMG_URL + ARTLESS=false + fi + +} + + update_cover() { # extract the album art from the mp3 file and dont show the messsy # output of ffmpeg @@ -31,7 +50,8 @@ update_cover() { ARTLESS=false else echo "error: file does not have an album art" - ARTLESS=true + get_cover_online + # ARTLESS=true return fi From 769110971f03a2a14c865c7b0cdafc7bf6d4b75e Mon Sep 17 00:00:00 2001 From: deepjyoti30 Date: Tue, 19 Feb 2019 01:41:11 +0530 Subject: [PATCH 2/8] Bugs --- kunst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kunst b/kunst index 25ce1fa..93f2e9f 100755 --- a/kunst +++ b/kunst @@ -24,12 +24,12 @@ get_cover_online() { # extract the albumcover from the json returned 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 echo "error: Cover not found online" ARTLESS=true else echo "kunst: Cover found online" - wget -o $COVER $IMG_URL + wget -O "$COVER" "$IMG_URL" ARTLESS=false fi From b508d8a4302ff54c49db73228e5569ee7ce4ee50 Mon Sep 17 00:00:00 2001 From: deepjyoti30 Date: Tue, 19 Feb 2019 01:50:24 +0530 Subject: [PATCH 3/8] Bugs --- kunst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kunst b/kunst index 93f2e9f..b6ef47b 100755 --- a/kunst +++ b/kunst @@ -51,14 +51,14 @@ update_cover() { else echo "error: file does not have an album art" get_cover_online - # ARTLESS=true - return fi # resize the image to 250x250 - convert $COVER -resize 250x250 $COVER + if [ $ARTLESS == false ]; then + convert $COVER -resize 250x250 $COVER + echo "kunst: resized album art to 250x250" + fi - echo "kunst: resized album art to 250x250" } From 03cee90069a3c1f2f722c2d49569f36e4edffbc2 Mon Sep 17 00:00:00 2001 From: deepjyoti30 Date: Tue, 19 Feb 2019 11:11:28 +0530 Subject: [PATCH 4/8] Moved to curl from wget --- kunst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kunst b/kunst index b6ef47b..6b49688 100755 --- a/kunst +++ b/kunst @@ -19,7 +19,8 @@ EOF get_cover_online() { # Try to get the album cover online from api.deezer.com - API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && ur=${ur//' '/'%20'} + # API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && ur=${ur//' '/'%20'} + API_URL="http://api.deezer.com/search/autocomplete?q=Brian%20Crain%20-%20Song%20for%20Sienna" # extract the albumcover from the json returned IMG_URL=$(curl -s "$API_URL" | jq -r '.playlists.data[0] | .picture_big') @@ -29,7 +30,7 @@ get_cover_online() { ARTLESS=true else echo "kunst: Cover found online" - wget -O "$COVER" "$IMG_URL" + curl -o $COVER -s $IMG_URL ARTLESS=false fi From 1ec31fc3b1c6ce5d07002760b2fe79a5725c94d7 Mon Sep 17 00:00:00 2001 From: deepjyoti30 Date: Tue, 19 Feb 2019 11:21:14 +0530 Subject: [PATCH 5/8] Improvements to code. --- kunst | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/kunst b/kunst index 6b49688..461792b 100755 --- a/kunst +++ b/kunst @@ -17,10 +17,28 @@ iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 EOF +is_connected() { + # Check if internet is connected + if ping -q -c 1 -W 1 8.8.8.8 >/dev/null; then + connected=true + else + echo "kunst: Can't check online for the cover" + connected=false + fi +} + + get_cover_online() { + # Check if connected to internet + is_connected + + if [ $connected == false ];then + ARTLESS=true + return + fi + # Try to get the album cover online from api.deezer.com - # API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && ur=${ur//' '/'%20'} - API_URL="http://api.deezer.com/search/autocomplete?q=Brian%20Crain%20-%20Song%20for%20Sienna" + API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && ur=${ur//' '/'%20'} # extract the albumcover from the json returned IMG_URL=$(curl -s "$API_URL" | jq -r '.playlists.data[0] | .picture_big') From 09dfdfc8a069e0ca8f69692dce6eee1f0c8aac3e Mon Sep 17 00:00:00 2001 From: deepjyoti30 Date: Tue, 19 Feb 2019 14:03:47 +0530 Subject: [PATCH 6/8] Bug fixes. --- kunst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kunst b/kunst index 461792b..a6cafb5 100755 --- a/kunst +++ b/kunst @@ -38,7 +38,7 @@ get_cover_online() { fi # Try to get the album cover online from api.deezer.com - API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && ur=${ur//' '/'%20'} + API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && API_URL=${API_URL//' '/'%20'} # extract the albumcover from the json returned IMG_URL=$(curl -s "$API_URL" | jq -r '.playlists.data[0] | .picture_big') From 8dd8dbbda3b6d31868702f198af8879be7ce9937 Mon Sep 17 00:00:00 2001 From: deepjyoti30 Date: Tue, 19 Feb 2019 15:26:11 +0530 Subject: [PATCH 7/8] Added support to pass Music dir and dimension. --- kunst | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/kunst b/kunst index a6cafb5..05e11e7 100755 --- a/kunst +++ b/kunst @@ -8,6 +8,36 @@ COVER=/tmp/kunst.jpg MUSIC_DIR=~/Music/ +DIMENSION=250x250 + +# Parse the arguments +options=$(getopt -o d:D:h --long dimension:,DIR:,help -- "$@") +eval set -- "$options" + +while true; do + case "$1" in + -d|--dimension) + shift; + DIMENSION=$1 + ;; + -D|--DIR) + shift; + MUSIC_DIR=$1 + ;; + -h|--help) + echo "kunst" + echo " -d, --dimension: Pass the dimension for the image.(Default: $DIMENSION)" + echo " -D, --DIR: Pass the Music directory that MPD plays from. (Default: $MUSIC_DIR)" + echo " -h, --help: Show this message and exit." + exit + ;; + --) + shift + break + ;; + esac + shift +done # this is a base64 endcoded image which will be used if # if the file does not have an emmbeded album art. @@ -74,8 +104,8 @@ update_cover() { # resize the image to 250x250 if [ $ARTLESS == false ]; then - convert $COVER -resize 250x250 $COVER - echo "kunst: resized album art to 250x250" + convert $COVER -resize $DIMENSION $COVER + echo "kunst: resized album art to $DIMENSION" fi } @@ -98,7 +128,7 @@ main() { echo "------------------------------------------" # display the album art using sxiv - sxiv -g 250x250 -b $COVER -N "Kunst" & + sxiv -g $DIMENSION -b $COVER -N "Kunst" & while true; do # waiting for an event from mpd; play/pause/next/previous From 8489545fbd73964b8115a4ff78d8f5f1443a35a5 Mon Sep 17 00:00:00 2001 From: deepjyoti30 Date: Tue, 19 Feb 2019 18:28:32 +0530 Subject: [PATCH 8/8] Bug fixes. --- kunst | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/kunst b/kunst index 05e11e7..c312c41 100755 --- a/kunst +++ b/kunst @@ -112,29 +112,11 @@ update_cover() { main() { - update_cover - if [ $ARTLESS == true ];then - # change 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 - fi - - echo "kunst: swapped album art to $(mpc current)" - echo "------------------------------------------" - - # display the album art using sxiv - sxiv -g $DIMENSION -b $COVER -N "Kunst" & + # Flag to run some commands only once in the loop + FIRST_RUN=true while true; do - # waiting for an event from mpd; play/pause/next/previous - # this is lets kunst use less CPU :) - mpc idle &> /dev/null - echo "kunst: received event from mpd" update_cover @@ -150,6 +132,18 @@ main() { echo "kunst: swapped album art to $(mpc current)" echo "------------------------------------------" + + if [ $FIRST_RUN == true ]; then + FIRST_RUN=false + + # display the album art using sxiv + sxiv -g $DIMENSION -b $COVER -N "Kunst" & + fi + + # waiting for an event from mpd; play/pause/next/previous + # this is lets kunst use less CPU :) + mpc idle &> /dev/null + echo "kunst: received event from mpd" done }