Code

lyrics: use open-uri to handle HTTP 301 redirection
authorLazaros Koromilas <lostd@2f30.org>
Sun, 12 Jun 2016 18:55:45 +0000 (20:55 +0200)
committerMax Kellermann <max@duempel.org>
Mon, 13 Jun 2016 13:46:25 +0000 (15:46 +0200)
NEWS
lyrics/20-lyricwiki.rb

diff --git a/NEWS b/NEWS
index 6db0158fe4b1cb14d9a4562bb7854fbd73049c58..2fb18600b4bb876a2e5ea6bb56615293ec447dd7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,5 @@
 ncmpc 0.25 - not yet released
+* lyricswiki: handle redirects
 
 
 ncmpc 0.24 - (2014-07-14)
index 9ab72b826722fe74d023ef361ffc11a580ae43ee..3e284ff9e532e48552f306e3e0bfdfcc036f9cb1 100755 (executable)
@@ -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 =~ /<url>\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 =~ /<div class='lyricbox'>\s*(.*?)\s*<!--/im
        $stderr.puts "No <div class='lyricbox'> in lyrics page!\n"
        exit(1)