Skip to content

Instantly share code, notes, and snippets.

@tecknicaltom
Last active November 24, 2015 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tecknicaltom/5eeae6b6a89948251981 to your computer and use it in GitHub Desktop.
Save tecknicaltom/5eeae6b6a89948251981 to your computer and use it in GitHub Desktop.
script to download ogg song lyrics
#!/bin/bash
FILE=$1
echo $FILE
ARTIST=$(ogginfo "$FILE" | grep -i ARTIST= | sed 's# ARTIST=##i')
TITLE=$(ogginfo "$FILE" | grep -i TITLE= | sed 's# TITLE=##i')
echo Artist: $ARTIST
echo Title: $TITLE
LYRIC_FILE=~/.lyrics/"$ARTIST"/"$TITLE".lyric
if [[ -e "$LYRIC_FILE" ]]
then
echo "Aborting. Lyric file already exists:"
echo $LYRIC_FILE
exit
fi
TMPFILE="$(tempfile --prefix=lyric --suffix=.lyric)"
wget http://lyrics.wikia.com/wiki/"$ARTIST":"$TITLE"?action=edit -O "$TMPFILE"
( echo "# Artist: " $ARTIST
echo "# Title: " $TITLE
echo
perl -ne 'print if(/<lyrics>/ .. /<\/lyrics>/)' "$TMPFILE" | grep -v 'lyrics>' | grep -v 'PUT LYRICS HERE (and delete this entire line)' | sed 's# *$##'
) | sponge "$TMPFILE"
"$EDITOR" "$TMPFILE"
cat "$TMPFILE" | perl -ne 'chomp; print "$_\n" if(/^[^#]/ .. 1)' | sponge "$TMPFILE"
grep -q '\S' "$TMPFILE"
if [[ $? -eq 0 ]]
then
mkdir -p ~/.lyrics/"$ARTIST"/
cp "$TMPFILE" "$LYRIC_FILE"
else
echo "Empty file. Aborting."
fi
rm "$TMPFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment