From: Lazaros Koromilas Date: Sun, 12 Jun 2016 18:55:45 +0000 (+0200) Subject: lyrics: use open-uri to handle HTTP 301 redirection X-Git-Tag: v0.25~7 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=84fb647e21918f41216390c7c9d4d03a549f36e5;p=ncmpc.git lyrics: use open-uri to handle HTTP 301 redirection --- diff --git a/NEWS b/NEWS index 6db0158..2fb1860 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,5 @@ ncmpc 0.25 - not yet released +* lyricswiki: handle redirects ncmpc 0.24 - (2014-07-14) diff --git a/lyrics/20-lyricwiki.rb b/lyrics/20-lyricwiki.rb index 9ab72b8..3e284ff 100755 --- a/lyrics/20-lyricwiki.rb +++ b/lyrics/20-lyricwiki.rb @@ -22,7 +22,7 @@ # require 'uri' -require 'net/http' +require 'open-uri' require 'cgi' # We need this because URI.escape doesn't escape ampersands. @@ -33,7 +33,7 @@ end url = "http://lyrics.wikia.com/api.php?action=lyrics&fmt=xml&func=getSong" + \ "&artist=#{escape(ARGV[0])}&song=#{escape(ARGV[1])}" -response = Net::HTTP.get(URI.parse(url)) +response = open(URI.parse(url)).read if not response =~ /\s*(.*?)\s*<\/url>/im $stderr.puts "No URL in response!" @@ -43,7 +43,7 @@ end url = $1 exit(69) if url =~ /action=edit$/ -response = Net::HTTP.get(URI.parse(url)) +response = open(URI.parse(url)).read if not response =~ /
\s*(.*?)\s*