Code

Implement a search-format configuration option (Mantis #4007)
[ncmpc.git] / lyrics / 15-leoslyrics.sh
1 #!/bin/bash
3 set -e
5 search="http://api.leoslyrics.com/api_search.php?auth=ncmpc"
6 lyrics="http://api.leoslyrics.com/api_lyrics.php?auth=ncmpc"
7 cache="$HOME/.lyrics/$1 - $2.txt"
9 hid=$(wget -q -O- "$search&artist=$1&songtitle=$2" |
10         sed -n 's/.*hid="\([^"]*\)".*exactMatch="true".*/\1/p' |
11         head -n 1)
13 test "$hid"
15 mkdir -p "$(dirname "$cache")"
17 wget -q -O- "$lyrics&hid=$hid" | awk '
18         /<text>/   { go=1; sub(".*<text>", "")  };
19         /<\/text>/ { go=0; sub("</text>.*", "") };
20         go         { sub("&#xD;", ""); print    };
21 ' | tee "$cache"