From 2f5749e9ab77e568d7d9e19e6dc8aa4fe7e574c4 Mon Sep 17 00:00:00 2001 From: Siddharth Dushantha Date: Wed, 13 Feb 2019 10:33:48 +0100 Subject: [PATCH] Put the main code into a function --- cover.sh | 40 ---------------------------------------- kunst.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 40 deletions(-) delete mode 100644 cover.sh create mode 100755 kunst.sh diff --git a/cover.sh b/cover.sh deleted file mode 100644 index 34a9907..0000000 --- a/cover.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -COVER=/tmp/cover.jpg -MUSIC_DIR=~/Music/ -CURRENT=$(mpc current -f %file%) - -update_cover() { - - # extract the album art from the mp3 file - ffmpeg -i "$MUSIC_DIR$(mpc current -f %file%)" $COVER -y &> /dev/null - - echo "Extracted album art" - - # resize the image to 250x250 - convert $COVER -resize 250x250 $COVER - - echo "Resized album art to 250x250" -} - - -update_cover -echo "Swapped art to $(mpc current)" - - -#mpv --keep-open=yes --cursor-autohide=always --no-osd-bar --no-osc --title="cover" --force-window=immediate --geometry 250x250 $COVER & -sxiv -g 250x250 -b $COVER & - - -while true; do - NEW=$(mpc current -f %file%) - if [ "$NEW" != "$CURRENT" ];then - CURRENT=$NEW - echo "Song changed. Swapping album art" - - update_cover - -# mpv --keep-open=yes --no-osd-bar --no-osc --title="cover" --force-window --geometry 250x250 $COVER & - echo "Swapped art to $(mpc current)" - fi -done diff --git a/kunst.sh b/kunst.sh new file mode 100755 index 0000000..efa9284 --- /dev/null +++ b/kunst.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +COVER=/tmp/kunst.jpg +MUSIC_DIR=~/Music/ +CURRENT=$(mpc current -f %file%) + + +update_cover() { + # extract the album art from the mp3 file and dont show the messsy + # output of ffmpeg + ffmpeg -i "$MUSIC_DIR$(mpc current -f %file%)" $COVER -y &> /dev/null + + echo "Extracted album art" + + # resize the image to 250x250 + convert $COVER -resize 250x250 $COVER + + echo "Resized album art to 250x250" +} + + + +main() { + update_cover + echo "Swapped art to $(mpc current)" + + #mpv --keep-open=yes --cursor-autohide=always --no-osd-bar --no-osc --title="cover" --force-window=immediate --geometry 250x250 $COVER & + sxiv -g 250x250 -b $COVER & + + + while true; do + NEW=$(mpc current -f %file%) + if [ "$NEW" != "$CURRENT" ];then + CURRENT=$NEW + echo "Song changed. Swapping album art" + + update_cover + + # mpv --keep-open=yes --no-osd-bar --no-osc --title="cover" --force-window --geometry 250x250 $COVER & + echo "Swapped art to $(mpc current)" + fi + done +} + + +main