From 88ebd850003e88cc05982ead3c0d770c6edf9766 Mon Sep 17 00:00:00 2001 From: Cedric Fung Date: Thu, 11 Apr 2013 09:11:29 +0200 Subject: [PATCH] lyricswiki: fix Ruby 2.0 and UTF-8 --- NEWS | 1 + lyrics/20-lyricwiki.rb | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 59c0c84..a94f9bb 100644 --- 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) diff --git a/lyrics/20-lyricwiki.rb b/lyrics/20-lyricwiki.rb index 8702249..56f61aa 100755 --- a/lyrics/20-lyricwiki.rb +++ b/lyrics/20-lyricwiki.rb @@ -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(/
/, "\n")) -puts Iconv.conv('UTF-8//TRANSLIT//IGNORE', 'Latin1', lyrics_latin1) +lyrics = $1.gsub(/
/, "\n") + +if lyrics.respond_to?(:force_encoding) + puts CGI::unescapeHTML(lyrics.force_encoding(Encoding::UTF_8)) +else + $KCODE = 'U' + puts CGI::unescapeHTML(lyrics) +end -- 2.30.2