diff --git a/lyrics/20-lyricwiki.rb b/lyrics/20-lyricwiki.rb
index 87022492b95497a4659beb7f610190a02eba6610..fde22e44a835144efddc0fd7dfa55fe039a2497c 100755 (executable)
--- a/lyrics/20-lyricwiki.rb
+++ b/lyrics/20-lyricwiki.rb
#!/usr/bin/env ruby
#
-# (c) 2004-2008 The Music Player Daemon Project
+# (c) 2004-2017 The Music Player Daemon Project
# http://www.musicpd.org/
#
# This program is free software; you can redistribute it and/or modify
#
require 'uri'
-require 'net/http'
+require 'open-uri'
require 'cgi'
-require 'iconv'
# We need this because URI.escape doesn't escape ampersands.
def escape(string)
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!"
url = $1
exit(69) if url =~ /action=edit$/
-response = Net::HTTP.get(URI.parse(url))
-if not response =~ /<div class='lyricbox'>\s*(.*?)\s*<!--/im
+response = open(URI.parse(url)).read
+if not response =~ /<div class='lyricbox'>\s*(.*?)\s*<div class='lyricsbreak'>/im
$stderr.puts "No <div class='lyricbox'> in lyrics page!\n"
exit(1)
end
-if not $1 =~ /^.*<\/div>(.*?)$/im
- $stderr.puts "Couldn't remove leading XML tags in lyricbox!\n"
- exit(1)
-end
+lyrics = $1.gsub(/<br \/>/, "\n")
-# lyrics come in Latin1, but we need UTF-8
-lyrics_latin1 = CGI::unescapeHTML($1.gsub(/<br \/>/, "\n"))
-puts Iconv.conv('UTF-8//TRANSLIT//IGNORE', 'Latin1', lyrics_latin1)
+if lyrics.respond_to?(:force_encoding)
+ puts CGI::unescapeHTML(lyrics.force_encoding(Encoding::UTF_8))
+else
+ $KCODE = 'U'
+ puts CGI::unescapeHTML(lyrics)
+end