From: Thomas Jansen Date: Sat, 3 Oct 2009 13:32:06 +0000 (+0200) Subject: plugin: handle stderr messages of lyrics plugins X-Git-Tag: release-0.16~205 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=905266256e0a564d8b5421fa9cd897901e583314;p=ncmpc.git plugin: handle stderr messages of lyrics plugins Use a second pipe to capture error messages generated by lyrics plugins. If one plugin succeeds to retrieve some lyrics, we display them and discard the error messages. If no plugin succeeds, we show the error messages of all plugins that failed with an exit code other than 69 (EX_UNAVAILABLE, sysexits.h). All plugins use exit code 0 to indicate success (i.e. they are able to provide lyrics on stdout). Exit code 69 indicates failure to retrieve lyrics, but otherwise normal operation of the plugin. A plugin returning exit code 69 is not listed as a failed plugin. Other exit codes indicate an internal error in the plugin. Those plugins are listed as failed along with the output they provide on stderr. --- diff --git a/NEWS b/NEWS index 571f7bf..bbbe18f 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ ncmpc 0.16 - not yet released * allow multiple queued database updates * reactivate incremental playlist changes * optimize "add+play song" with addid/playid +* handle stderr messages from lyrics plugins ncmpc 0.15 - 2009-09-24 diff --git a/lyrics/01-hd.sh b/lyrics/01-hd.sh index 2480e5a..a0d7020 100755 --- a/lyrics/01-hd.sh +++ b/lyrics/01-hd.sh @@ -21,4 +21,10 @@ # Load lyrics from the user's home directory # -cat ~/.lyrics/"$1 - $2".txt 2>/dev/null +FILENAME=~/.lyrics/"$1 - $2".txt + +if [ -e "$FILENAME" ] ; then + cat "$FILENAME" 2>/dev/null +else + exit 69 +fi diff --git a/lyrics/02-lyricwiki.rb b/lyrics/02-lyricwiki.rb index 74c13b2..2e1aed7 100755 --- a/lyrics/02-lyricwiki.rb +++ b/lyrics/02-lyricwiki.rb @@ -28,11 +28,18 @@ url = "http://lyrics.wikia.com/api.php?action=lyrics&fmt=xml&func=getSong" + \ "&artist=#{URI.escape(ARGV[0])}&song=#{URI.escape(ARGV[1])}" response = Net::HTTP.get(URI.parse(url)) -exit(2) unless response =~ /\s*(.*?)\s*<\/url>/im +if not response =~ /\s*(.*?)\s*<\/url>/im + $stderr.puts "No URL in response!" + exit(1) +end + url = $1.gsub(/wikia.com/, "wikia.com/lyrics"); -exit(2) if $1 =~ /action=edit$/ +exit(69) if $1 =~ /action=edit$/ response = Net::HTTP.get(URI.parse(url)) -exit(2) unless response =~ /
\s*(.*?)\s*