Skip to main content
Welcome guest. | Register | Login | Post

Lyrics download script

4 replies [Last post]
Offline
Joined: 2008-03-17

I love being able to download the lyrics for a song using rhythmbox, but I really want to be able to do this from the command line. The only thing I could find using google is this article: http://www.linux.com/feature/114259 The problem with this article is that the link to the actual script isn't functioning. I was wondering if anyone knows where the script is or knows of another terminal-based solution to my problem? Even using a graphical lyric programme with terminal based command options would be fine. But I am at a loss.

Thanks,
enterthepig

Offline
Joined: 2006-03-28
Well, either I'm blind or

Well, either I'm blind or there's no link to the complete script in the article.

But anyway, based on the descriptions given in the article it shouldn't be too hard to write a little shell-script that uses the tools named there and get it running.
Most of the necessary calls seem to be shown there, so if you know some basic Bash-scripting it shouldn't take too long to get this working.

Also, did you check out the comments? There seems to be some good info too.

a thing's picture
Offline
Joined: 2005-12-20
dirty hack with Amarok

I am thinking you might be able to use some dirty hack with Amarok and Dbus.

Offline
Joined: 2008-03-17
Thanks...

I tried coming up with a script using the information provided in the article, but it still doesn't work. This is what I have now:

#!/bin/bash
ARTIST=$(id3tool "$1" | sed -ne "s/.*Artist:\(.*\)/\1/p")
SONGTITLE=$(id3tool "$1" | sed -ne "s/.*Song Title:\(.*\)/\1/p")
AUTH="drwily"
ARTIST=$(echo $ARTIST | xmlstarlet unesc)
echo $ARTIST
SONGTITLE=$(echo $SONGTITLE | xmlstarlet unesc)
echo $SONGTITLE
if [[ ! -d "/home/drwily/.lyrics/$ARTIST" ]]; then
  mkdir "/home/drwily/.lyrics/$ARTIST"
fi
search_results=$(wget -q "http://api.leoslyrics.com/api_search.php?auth=$AUTH&artist=$ARTIST&songtitle=$SONGTITLE" -O -)
result=$(echo $search_results | xmlstarlet sel -t -v "/leoslyrics/response/text()")
if [[ ! -f "/home/drwily/.lyrics/$ARTIST/$SONGTITLE.lyrics" ]]; then
  echo $lyrics | xmlstarlet sel -t -v "/leoslyrics/lyric/text/text()" | xmlstarlet unesc > "/home/drwily/.lyrics/$ARTIST/$SONGTITLE.lyrics"
fi

and this is the output I get when trying to run it with ./lyricsfetcherintheworks "Music/Frosty/Flobots - Handlebars.mp3" :

Flobots
Handlebars
-:2: parser error : Start tag expected, '<' not found

^

...any ideas? I'm really at a loss here.
Thanks

Offline
Joined: 2008-03-17
Finally!

Good news. I finally figured it out. Here is a copy of my script for those who happenstance to stumble upon it in search of a similar script:

#!/bin/bash
red="\E[31m"
AUTH="drwily"

if [[ $1 == *.mp3 ]]; then
        ARTIST=$(id3tool "$1" | sed -ne "s/.*Artist:\(.*\)/\1/p")
        SONGTITLE=$(id3tool "$1" | sed -ne "s/.*Song Title:\(.*\)/\1/p")
else
        ARTIST=$(mutagen-inspect "$1" | sed -ne "s/.*artist=\(.*\)/\1/p")
        SONGTITLE=$(mutagen-inspect "$1" | sed -ne "s/.*title=\(.*\)/\1/p")
fi

ARTIST=$(echo $ARTIST | xmlstarlet unesc)
SONGTITLE=$(echo $SONGTITLE | xmlstarlet unesc)
echo "$ARTIST - $SONGTITLE"

if [[ ! -d "/home/drwily/.lyrics/$ARTIST" ]]; then
  mkdir "/home/drwily/.lyrics/$ARTIST"
fi

search_results=$(wget -q "http://api.leoslyrics.com/api_search.php?auth=$AUTH&artist=$ARTIST&songtitle=$SONGTITLE" -O -)
result=$(echo $search_results | xmlstarlet sel -t -v "/leoslyrics/response/text()")

if [[ $result == "SUCCESS" ]]; then
  HID=$(echo $search_results | xmlstarlet sel -t -v "/leoslyrics/searchResults/result/@hid")
wget -q "http://api.leoslyrics.com/api_lyrics.php?auth=$AUTH&hid=$HID" -O - | xmlstarlet sel -t -v "/leoslyrics/lyric/text/text()" | xmlstarlet unesc > "/home/drwily/.lyrics/$ARTIST/$SONGTITLE.lyrics"
else
echo -e $1 "${red}EPIC FAIL"; tput sgr0
fi

obviously some directories would need to be customized and dependencies installed, but it should be functionable.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.