Code

20-lyricwiki.rb: recode recieved lyrics
authorJonathan Neuschäfer <j.neuschaefer@gmx.net>
Wed, 26 May 2010 21:13:12 +0000 (23:13 +0200)
committerMax Kellermann <max@duempel.org>
Sat, 19 Jun 2010 15:03:13 +0000 (17:03 +0200)
The lyrics are recieved in Latin1, but UTF-8 is needed.

lyrics/20-lyricwiki.rb

index db7b970307dd03d944eb76e971cedaf8698c72ce..3873e7a8120cec248817391c8cf8d8f0c8189623 100755 (executable)
@@ -24,6 +24,7 @@
 require 'uri'
 require 'net/http'
 require 'cgi'
+require 'iconv'
 
 url = "http://lyrics.wikia.com/api.php?action=lyrics&fmt=xml&func=getSong" + \
     "&artist=#{URI.escape(ARGV[0])}&song=#{URI.escape(ARGV[1])}"
@@ -48,4 +49,6 @@ if not $1 =~ /^.*<\/div>(.*?)$/im
        exit(1)
 end
 
-puts CGI::unescapeHTML($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)