Last active
November 24, 2015 21:53
-
-
Save tecknicaltom/5eeae6b6a89948251981 to your computer and use it in GitHub Desktop.
script to download ogg song lyrics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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