disable CTRL-Z
This commit is contained in:
parent
d30f0ffd78
commit
580704de6a
47
kunst
47
kunst
|
@ -29,7 +29,7 @@ show_help() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# parse the arguments
|
# Parse the arguments
|
||||||
options=$(getopt -o h --long size:,music_dir:,version,help -- "$@")
|
options=$(getopt -o h --long size:,music_dir:,version,help -- "$@")
|
||||||
eval set -- "$options"
|
eval set -- "$options"
|
||||||
|
|
||||||
|
@ -59,16 +59,16 @@ while true; do
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
# this is a base64 endcoded image which will be used if
|
# This is a base64 endcoded image which will be used if
|
||||||
# if the file does not have an emmbeded album art.
|
# the file does not have an emmbeded album art.
|
||||||
# the image is a image of a music note
|
# The image is an image of a music note
|
||||||
read -d '' MUSIC_NOTE << EOF
|
read -d '' MUSIC_NOTE << EOF
|
||||||
iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAJESURBVGhD7Zg/axRRFMVXAtpYphEVREKClnHfJI0MmReSfAC3tRejhaBgo70fwN7aD2BvEU0gfztbu5AqMxNjoVnvG87KZXy7z5m5dxLI/OCw8Pade+7M3n3Dbq+jo6OjY8RwMJhKk+hhlph3eRJ9w/LF5jCOr1PTj6jpD7mNjkjDkbDl4vFjpX87teZJlkSfSD9501zYfv5QJ1fyZHGexuJtZs12ZqMzX8NlwX4+nK3NXMutWaOm39Nd/u5rMCSUao80fjBNwY+p8Y+krNxQVaGsLsfWzFLYS2r4M30Rf5WbaCJE6OILlhIidPEFSwkRuviCpYQIXXzB1WX26bR6ky4v3OPriNCFB1YRHa079Pr6eKk/h1IFfA+WdOGBk+QeXtT0Ft3pV6e2fxf2f+AeLOnCA8tC0xv09H1xGi/cgWUi3I8lXXigEzX8u3gmWPP8JI5uYdt/w2thSRceSM0/zVfnb+CtW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mWEssR8ga0+0jNL9Z75fD7Rp7UOW32kZxb/1u37vFyUu+sODtjqozGzxaFADfprFM3vuD3Y3gytmf17LJPHXbgTNb5BWhe58yNan1lpWp9ZDVqdWS1am9mOjo7LRq/3B1ESKyYUVquzAAAAAElFTkSuQmCC
|
||||||
EOF
|
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
|
||||||
|
@ -81,7 +81,7 @@ is_connected() {
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -89,10 +89,10 @@ get_cover_online() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# try to get the album cover online from api.deezer.com
|
# Try to get the album cover online from api.deezer.com
|
||||||
API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && API_URL=${API_URL//' '/'%20'}
|
API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && API_URL=${API_URL//' '/'%20'}
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -108,14 +108,14 @@ get_cover_online() {
|
||||||
|
|
||||||
|
|
||||||
update_cover() {
|
update_cover() {
|
||||||
# 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
|
||||||
echo "kunst: extracted album art"
|
echo "kunst: extracted album art"
|
||||||
ARTLESS=false
|
ARTLESS=false
|
||||||
|
@ -123,8 +123,8 @@ update_cover() {
|
||||||
DIR="$MUSIC_DIR$(dirname "$(mpc current -f %file%)")"
|
DIR="$MUSIC_DIR$(dirname "$(mpc current -f %file%)")"
|
||||||
echo "kunst: inspecting $DIR"
|
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
|
||||||
|
@ -140,7 +140,7 @@ update_cover() {
|
||||||
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
|
||||||
convert $COVER -resize $SIZE $COVER
|
convert $COVER -resize $SIZE $COVER
|
||||||
echo "kunst: resized album art to $SIZE"
|
echo "kunst: resized album art to $SIZE"
|
||||||
|
@ -149,12 +149,13 @@ update_cover() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pre_exit() {
|
pre_exit() {
|
||||||
|
# Get the proccess ID of kunst and kill it
|
||||||
kill -9 $(cat /tmp/kunst.pid)
|
kill -9 $(cat /tmp/kunst.pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -162,11 +163,11 @@ main() {
|
||||||
update_cover
|
update_cover
|
||||||
|
|
||||||
if [ $ARTLESS == true ];then
|
if [ $ARTLESS == true ];then
|
||||||
# change 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
|
||||||
|
@ -177,17 +178,25 @@ main() {
|
||||||
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 -b $COVER -N "Kunst" &
|
sxiv -g $SIZE -b $COVER -N "Kunst" &
|
||||||
|
|
||||||
|
# Save the process ID so that we can kill
|
||||||
|
# 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 :)
|
||||||
mpc idle &> /dev/null
|
mpc idle &> /dev/null
|
||||||
echo "kunst: received event from mpd"
|
echo "kunst: received event from mpd"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Disable CTRL-Z because if we allowed this key press,
|
||||||
|
# then the script would exit but, sxiv would still be
|
||||||
|
# running
|
||||||
|
trap "" SIGTSTP
|
||||||
|
|
||||||
trap pre_exit EXIT
|
trap pre_exit EXIT
|
||||||
main
|
main
|
||||||
|
|
Loading…
Reference in New Issue