Skip to content

Instantly share code, notes, and snippets.

@vlevit
Created January 21, 2013 21:52
Show Gist options
  • Save vlevit/4589821 to your computer and use it in GitHub Desktop.
Save vlevit/4589821 to your computer and use it in GitHub Desktop.
Dirty script to download covers for the album of currently playing song by mpd with glyrc
#!/bin/bash
# Dirty script to download covers for the album of currently playing song by mpd
# with glyrc
# Copyright (c) 2013 Vyacheslav Levit
# Licensed under The MIT License: http://opensource.org/licenses/MIT
MUSIC_DIR="$HOME/Music"
TEMPDIR=/var/tmp
MAX_DOWNLOADS=20
VIEWER=(qiv -tB)
GLYRC_ARGS=(--plugmax 2 --minsize 490)
COVER='cover.$ext' # might be '$artist - $album.$ext'
COVERTXT="/tmp/cover.txt"
if ! type mpc &>/dev/null || ! type glyrc &>/dev/null ; then
echo "mpc and glyrc are required"
exit 1
fi
artist="$(mpc --format %artist% current)"
[[ $? != 0 ]] && { echo "mpd not running?" ; exit 1; }
album="$(mpc --format %album% current)"
file="$MUSIC_DIR/$(mpc --format %file% current)"
echo "artist:$artist"
echo "album:$album"
if [[ -z "$artist" ]] || [[ -z "$album" ]] ; then
echo "artist or/and album field is empty"
exit 1
fi
if [[ ! -e "$file" ]] ; then
echo "File doesn't exist. Wrong MUSIC_DIR?"
exit 1
fi
album_dir="${file%/*}"
glyrcdir="$TEMPDIR/glyrc"
coverdir="$glyrcdir/$artist - $album"
mkdir -p "$coverdir"
cd "$coverdir"
glyrc cover -n "$MAX_DOWNLOADS" --artist "$artist" --album "$album" "${GLYRC_ARGS[@]}"
"${VIEWER}" "$coverdir"
if [[ ! -e "$COVERTXT" ]] ; then
echo "No images selected ($COVERTXT does not exist)"
exit 1
fi
coverfile="$(cat "$COVERTXT")"
rm -f "$COVERTXT"
if [[ ! -e "$coverfile" ]] ; then
echo "$coverfile doesn't exist"
exit 1
fi
ext="${coverfile##*.}"
[[ "$ext" == "jpeg" ]] && ext=jpg
eval dest=\"$COVER\"
dest="$album_dir/$dest"
cp "$coverfile" "$dest"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment