]> git.madduck.net Git - etc/awesome.git/blob - scripts/mpdcover

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

yawn: new icon
[etc/awesome.git] / scripts / mpdcover
1 #!/bin/bash
2 #
3 # A simple cover fetcher script for current playing song on mpd.
4 #
5 # Author : Wolfgang Mueller
6 #
7 # Adapted for Lain internal use.
8 # https://github.com/copycat-killer/lain
9 #
10 # You can use, edit and redistribute this script in any way you like.
11 #
12 # Dependencies: imagemagick.
13 #
14 # Usage: mpdcover <music_directory> <song_file> <cover_resize> <default_art>
15
16 # Configuration-------------------------------------------------------
17
18 # Music directory
19 MUSIC_DIR=$1
20
21 # Song file
22 file=$2
23
24 # Regex expression used for image search
25 IMG_REG="(Front|front|Cover|cover|Art|art|Folder|folder)\.(jpg|jpeg|png|gif)$"
26
27 # Path of temporary resized cover
28 TEMP_PATH="/tmp/mpdcover.png"
29
30 # Resize cover
31 COVER_RESIZE="$3x$3"
32
33 if [ $COVER_RESIZE == "x" ]; then
34     COVER_RESIZE="100x100"
35 fi
36
37 # The default cover to use (optional)
38 DEFAULT_ART=$4
39
40 # Thumbnail background (transparent)
41 COVER_BACKGROUND="none"
42
43 #--------------------------------------------------------------------
44
45 # check if anything is playing at all
46 [[ -z $file ]] && exit 1
47
48 # Art directory
49 art="$MUSIC_DIR/${file%/*}"
50
51 # find every file that matches IMG_REG set the first matching file to be the
52 # cover.
53 cover="$(find "$art/" -maxdepth 1 -type f | egrep -i -m1 "$IMG_REG")"
54
55 # when no cover is found, use DEFAULT_ART as cover
56 cover="${cover:=$DEFAULT_ART}"
57
58 # check if art is available
59 if [[ -n $cover ]]; then
60    if [[ -n $COVER_RESIZE ]]; then
61         convert "$cover" -thumbnail $COVER_RESIZE -gravity center -background "$COVER_BACKGROUND" -extent $COVER_RESIZE "$TEMP_PATH"
62         cover="$TEMP_PATH"
63    fi
64 else
65    rm $TEMP_PATH
66 fi
67
68 exit 0