From 84fb647e21918f41216390c7c9d4d03a549f36e5 Mon Sep 17 00:00:00 2001 From: Lazaros Koromilas Date: Sun, 12 Jun 2016 20:55:45 +0200 Subject: [PATCH] lyrics: use open-uri to handle HTTP 301 redirection --- NEWS | 1 + lyrics/20-lyricwiki.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) 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*