Code

update lyricwiki plugin to lyric.wikia.com
authorThomas Jansen <mithi@mithi.net>
Sat, 12 Sep 2009 22:29:28 +0000 (00:29 +0200)
committerThomas Jansen <mithi@mithi.net>
Sat, 12 Sep 2009 22:29:28 +0000 (00:29 +0200)
Lyricwiki was integrated into wikia.com. This changed the URL and once
again the API.

lyrics/02-lyricwiki.rb

index 08938b82d0ead08db95a637748c859533c5bdbd4..74c13b2144190f3207085d118dd504b79bf5dc46 100755 (executable)
 #
 
 #
-# Load lyrics from lyricwiki.org
+# Load lyrics from lyrics.wikia.com, formerly lyricwiki.org
 #
 
 require 'uri'
 require 'net/http'
 
-url = "http://lyricwiki.org/api.php" + \
-    "?artist=#{URI.escape(ARGV[0])}&song=#{URI.escape(ARGV[1])}"
+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 =~ /<pre>\s*(.*?)\s*<\/pre>/im
-exit(2) if $1 == "Not found"
-
-url = $1
-url =~ /<a href='\s*(.*?)\s*'>/im
+exit(2) unless response =~ /<url>\s*(.*?)\s*<\/url>/im
+url = $1.gsub(/wikia.com/, "wikia.com/lyrics");
+exit(2) if $1 =~ /action=edit$/
 
 response = Net::HTTP.get(URI.parse(url))
-exit(2) unless response =~ /<div class='lyricbox' >\s*(.*?)\s*<p>/im
+exit(2) unless response =~ /<div class='lyricbox' >\s*(.*?)\s*<!--/im
 
 puts $1.gsub(/<br \/>/, "\n")