Code

lyricwiki: allow ampersands in artist/song names
authorJonathan Neuschäfer <j.neuschaefer@gmx.net>
Mon, 8 Aug 2011 22:47:36 +0000 (00:47 +0200)
committerJonathan Neuschäfer <j.neuschaefer@gmx.net>
Mon, 8 Aug 2011 22:47:36 +0000 (00:47 +0200)
lyrics/20-lyricwiki.rb

index 3873e7a8120cec248817391c8cf8d8f0c8189623..87022492b95497a4659beb7f610190a02eba6610 100755 (executable)
@@ -26,8 +26,14 @@ require 'net/http'
 require 'cgi'
 require 'iconv'
 
+# We need this because URI.escape doesn't escape ampersands.
+def escape(string)
+       new = URI.escape(string)
+       new.gsub(/&/, "%26")
+end
+
 url = "http://lyrics.wikia.com/api.php?action=lyrics&fmt=xml&func=getSong" + \
-    "&artist=#{URI.escape(ARGV[0])}&song=#{URI.escape(ARGV[1])}"
+    "&artist=#{escape(ARGV[0])}&song=#{escape(ARGV[1])}"
 response = Net::HTTP.get(URI.parse(url))
 
 if not response =~ /<url>\s*(.*?)\s*<\/url>/im