This commit is contained in:
mrsu 2023-08-31 16:59:39 +01:00
parent e9f14b5d79
commit c34707fa24
1 changed files with 1 additions and 56 deletions

57
kunst
View File

@ -94,62 +94,7 @@ iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
EOF
is_connected() {
# 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
# the internet is not connected this script will work as expected
if ping -q -c 1 -W 1 api.deezer.com >/dev/null; then
connected=true
else
log "unable to check online for the album art"
connected=false
fi
}
get_cover_online() {
# Check if connected to internet
is_connected
if [ "$connected" == false ];then
ARTLESS=true
return
fi
# If the current playing song ends with .mp3 or something similar, remove
# it before searching for the album art because including the file extension
# reduces the chance of good results in the search query
QUERY=$(mpc current | sed 's/\.[^.]*$//' | iconv -t ascii//TRANSLIT -f utf8)
# 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'}
log "fetching $API_URL"
# Extract the albumcover from the json returned
JSON=$(curl -s "$API_URL")
ALBUM=$(echo "$JSON" | jq -r '.tracks.data[0].album.picture_big' | sed 's/null//');
ARTIST=$(echo "$JSON" | jq -r '.tracks.data[0].artist.picture_big' | sed 's/null//');
IMG_URL="${ALBUM:-$ARTIST}"
if [ "$IMG_URL" = '' ] || [ "$IMG_URL" = 'null' ];then
log "cover not found online"
ARTLESS=true
else
log "cover found online"
curl -o "$COVER" -s "$IMG_URL"
ARTLESS=false
fi
}
find_album_art(){
# Check if the user wants to get the album art from the internet,
# regardless if the current song has an embedded album art or not
if [ ! -z "$ONLINE_ALBUM_ART" ]; then
log "getting cover from internet"
get_cover_online
return
fi
# 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
@ -179,7 +124,7 @@ find_album_art(){
if [ "$STATUS" -ne 0 ];then
log "file does not have an album art"
get_cover_online
ARTLESS=true
fi
}