lain/scripts/mpdcover

69 lines
1.6 KiB
Plaintext
Raw Normal View History

2013-11-02 21:05:25 +01:00
#!/bin/bash
2013-09-07 12:06:42 +02:00
#
# A simple cover fetcher script for current playing song on mpd.
#
2014-10-20 18:05:47 +02:00
# Original author: Wolfgang Mueller
2013-09-07 12:06:42 +02:00
#
# Adapted for Lain internal use.
# https://github.com/copycat-killer/lain
#
# You can use, edit and redistribute this script in any way you like.
#
# Dependencies: imagemagick.
#
2013-09-18 00:27:46 +02:00
# Usage: mpdcover <music_directory> <song_file> <cover_resize> <default_art>
2013-09-07 12:06:42 +02:00
# Configuration-------------------------------------------------------
# Music directory
MUSIC_DIR=$1
# Song file
file=$2
# Regex expression used for image search
2013-09-18 00:27:46 +02:00
IMG_REG="(Front|front|Cover|cover|Art|art|Folder|folder)\.(jpg|jpeg|png|gif)$"
2013-09-07 12:06:42 +02:00
# Path of temporary resized cover
TEMP_PATH="/tmp/mpdcover.png"
# Resize cover
2013-09-14 00:01:00 +02:00
COVER_RESIZE="$3x$3"
if [ $COVER_RESIZE == "x" ]; then
COVER_RESIZE="100x100"
fi
2013-09-07 12:06:42 +02:00
2013-09-18 00:27:46 +02:00
# The default cover to use (optional)
DEFAULT_ART=$4
2013-09-07 12:06:42 +02:00
# Thumbnail background (transparent)
COVER_BACKGROUND="none"
#--------------------------------------------------------------------
# check if anything is playing at all
[[ -z $file ]] && exit 1
# Art directory
art="$MUSIC_DIR/${file%/*}"
# find every file that matches IMG_REG set the first matching file to be the
# cover.
cover="$(find "$art/" -maxdepth 1 -type f | egrep -i -m1 "$IMG_REG")"
2013-09-18 00:27:46 +02:00
# when no cover is found, use DEFAULT_ART as cover
cover="${cover:=$DEFAULT_ART}"
2013-09-07 12:06:42 +02:00
# check if art is available
if [[ -n $cover ]]; then
if [[ -n $COVER_RESIZE ]]; then
2014-10-20 18:05:47 +02:00
convert "$cover" -scale $COVER_RESIZE -gravity "center" -background "$COVER_BACKGROUND" "$TEMP_PATH"
2013-09-07 12:06:42 +02:00
cover="$TEMP_PATH"
fi
else
rm $TEMP_PATH
fi
exit 0