Code

leoslyrics.sh plugin: Add bash leoslyrics plugin
authorAndy Spencer <andy753421@gmail.com>
Tue, 24 Nov 2009 15:51:06 +0000 (15:51 +0000)
committerMax Kellermann <max@duempel.org>
Tue, 24 Nov 2009 16:07:04 +0000 (17:07 +0100)
Simple version of the Leo's Lyrics plugin that uses bash and wget.

This also caches the lyrics in ~/.lyrics so that they are later retrieved by
the hd.sh plugin.

Makefile.am
lyrics/15-leoslyrics.sh [new file with mode: 0755]

index 1fdb6167d9bffb251551efcc8d4ac9c5a2511275..50003aa5fd852573e67cbc05856b32238cd4346d 100644 (file)
@@ -186,7 +186,7 @@ sparse-check:
 # lyrics plugins
 #
 
-lyrics_plugins = lyrics/10-hd.sh lyrics/20-lyricwiki.rb lyrics/30-leoslyrics.py
+lyrics_plugins = lyrics/10-hd.sh lyrics/15-leoslyrics.sh lyrics/20-lyricwiki.rb lyrics/30-leoslyrics.py
 
 if ENABLE_LYRICS_SCREEN
 
diff --git a/lyrics/15-leoslyrics.sh b/lyrics/15-leoslyrics.sh
new file mode 100755 (executable)
index 0000000..7a119bb
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+set -e
+
+search="http://api.leoslyrics.com/api_search.php?auth=ncmpc"
+lyrics="http://api.leoslyrics.com/api_lyrics.php?auth=ncmpc"
+cache="$HOME/.lyrics/$1 - $2.txt"
+
+hid=$(wget -q -O- "$search&artist=$1&songtitle=$2" |
+       sed -n 's/.*hid="\([^"]*\)".*exactMatch="true".*/\1/p' |
+       head -n 1)
+
+test "$hid"
+
+mkdir -p "$(dirname "$cache")"
+
+wget -q -O- "$lyrics&hid=$hid" | awk '
+       /<text>/   { go=1; sub(".*<text>", "")  };
+       /<\/text>/ { go=0; sub("</text>.*", "") };
+       go         { sub("&#xD;", ""); print    };
+' | tee "$cache"