Code

lyricswiki: fix Ruby 2.0 and UTF-8
authorCedric Fung <cedric@vec.io>
Thu, 11 Apr 2013 07:11:29 +0000 (09:11 +0200)
committerMax Kellermann <max@duempel.org>
Thu, 11 Apr 2013 07:11:29 +0000 (09:11 +0200)
NEWS
lyrics/20-lyricwiki.rb

diff --git a/NEWS b/NEWS
index 59c0c84cf8b01366c0614defd5d46b45b751660f..a94f9bb82c77f432ae04297dc761a69c2186a1c5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ ncmpc 0.21 - not yet released
 * song format: evaluate literal strings as true
 * fix crash on search screen when disconnected
 * screen_queue: fix crash on CMD_SCREEN_SWAP when the queue is empty
+* lyricswiki: fix Ruby 2.0 and UTF-8
 
 
 ncmpc 0.20 - (02/05/2012)
index 87022492b95497a4659beb7f610190a02eba6610..56f61aa7943cd4487f9d996090ec6a222747f20f 100755 (executable)
@@ -24,7 +24,6 @@
 require 'uri'
 require 'net/http'
 require 'cgi'
-require 'iconv'
 
 # We need this because URI.escape doesn't escape ampersands.
 def escape(string)
@@ -55,6 +54,11 @@ if not $1 =~ /^.*<\/div>(.*?)$/im
        exit(1)
 end
 
-# 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)
+lyrics = $1.gsub(/<br \/>/, "\n")
+
+if lyrics.respond_to?(:force_encoding)
+  puts CGI::unescapeHTML(lyrics.force_encoding(Encoding::UTF_8))
+else
+  $KCODE = 'U'
+  puts CGI::unescapeHTML(lyrics)
+end