Skip to content

Instantly share code, notes, and snippets.

@nicnocquee
Last active January 18, 2016 15:59
Show Gist options
  • Select an option

  • Save nicnocquee/114369673c60c83c8c6a to your computer and use it in GitHub Desktop.

Select an option

Save nicnocquee/114369673c60c83c8c6a to your computer and use it in GitHub Desktop.
Script to find lyric of songs in a given folder. Requires mediainfo.
#!/bin/sh
# Require mediainfo: brew install mediainfo
function readSong () {
if [ "$1" != "." ] ; then
TITLE=`mediainfo "$1" | grep "^\Track name\ *:" | sed 's/.*Track name\ *:\ //g'`
ARTIST=`mediainfo "$1" | grep "^\Performer\ *:" | sed 's/.*Performer\ *:\ //g'`
FILENAME=`mediainfo "$1" | grep "^\Complete name\ *:" | sed 's/.*Complete name\ *:\ //g' | sed 's/\.mp3$/\.txt/g' | sed 's/\.m4a$/\.txt/g'`
echo "Fetching lyric "$ARTIST" "$TITLE" ... "
LYRIC=`curl --data-urlencode "artist=$ARTIST" --data-urlencode "title=$TITLE" -G -s "http://makeitpersonal.co/lyrics"`
echo "$LYRIC" > "$FILENAME"
fi
}
export -f readSong
if [[ "$#" -eq 0 ]]; then
echo "Usage: "
echo "Search for lyric for given title and artist"
echo " lyrics.sh -a \"<Artist>\" -t \"<Title>\""
echo "Or to search for lyrics of the songs in a directory"
echo " lyrics.sh <directory>"
elif [ "$#" -eq 1 ]; then
find "$1" -maxdepth 1 -iregex ".*\.[mp3|m4a]*" -execdir bash -c 'readSong "$0"' {} \;
else
while [[ $# > 1 ]]
do
key="$1"
case $key in
-a|--artist)
ARTIST="$2"
shift # past argument
;;
-t|--title)
TITLE="$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
echo "Searching lyric for: "$TITLE" by "$ARTIST""
FILENAME="/tmp/"$ARTIST" - "$TITLE".txt"
LYRIC=`curl --data-urlencode "artist=$ARTIST" --data-urlencode "title=$TITLE" -G -s "http://makeitpersonal.co/lyrics"`
echo "$LYRIC" > "$FILENAME"
open "$FILENAME"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment